Newbie Game Programmers!

This is a discussion on Newbie Game Programmers! within the Game Programming forums, part of the General Programming Boards category; I just finished a tic-tac-toe game in ascii. I know it isnt very appealing or great but its my first ...

  1. #1
    Ryce
    Guest

    Lightbulb Newbie Game Programmers!

    I just finished a tic-tac-toe game in ascii. I know it isnt very appealing or great but its my first real game i made my self. I hope that this will give you helpfull hints and stuff for your challanges!

    NOTE: THIS IS SOME LONG CODE!(Or its longest i've ever written)

    //BEGIN CODE!!!
    //------------------------------------------------------
    #include <iostream.h>
    #include <string.h>
    #include <conio.h>

    //Globals
    int player=1;
    int winner=0;
    int tie=0;

    char board[3][3] = { // An Array to hold board data
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'}
    };

    // Functions
    void draw_map(); // Draw map and take input
    void clrscr(); // Clear the screen
    void check_4_winner(); // Checks for a winner

    // Loaly little main()!
    int main()
    {
    draw_map();



    return 0;
    }

    // Actully Functions now========================
    // Draw Map--------------
    void draw_map()
    {
    int choice;
    int r,c;
    clrscr();
    winner=0;
    while(!winner)// Loop 9 times(amount of spaces on board) or untill a winnner!
    {

    retry:
    clrscr();

    cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;
    cout << "\n";
    cout << "Player "<<player<<": ";
    cin >> choice;
    if((board[0][0] != '1') && (board[0][1] != '2') && (board[0][2] != '3') &&
    (board[1][0] != '4') && (board[1][1] != '5') && (board[1][2] != '6') &&
    (board[2][0] != '7') && (board[2][1] != '8') && (board[2][2] != '9'))
    {
    goto tie;
    }
    switch(choice)
    {
    case 1:
    if((board[0][0] == 'X') || (board[0][0] == 'O')){goto retry;}
    board[0][0] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 2:
    if((board[0][1] == 'X') || (board[0][1] == 'O')){goto retry;}
    board[0][1] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 3:
    if((board[0][2] == 'X') || (board[0][2] == 'O')){goto retry;}
    board[0][2] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 4:
    if((board[1][0] == 'X') || (board[1][0] == 'O')){goto retry;}
    board[1][0] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 5:
    if((board[1][1] == 'X') || (board[1][1] == 'O')){goto retry;}
    board[1][1] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 6:
    if((board[1][2] == 'X') || (board[1][2] == 'O')){goto retry;}
    board[1][2] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 7:
    if((board[2][0] == 'X') || (board[2][0] == 'O')){goto retry;}
    board[2][0] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 8:
    if((board[2][1] == 'X') || (board[2][1] == 'O')){goto retry;}
    board[2][1] = (player==1) ? 'X':'O';
    check_4_winner();
    break;
    case 9:
    if((board[2][2] == 'X') || (board[2][2] == 'O')){goto retry;}
    board[2][2] = (player==1) ? 'X':'O';
    check_4_winner();
    break;

    default:
    cout << "Not a valid selection!";
    goto retry;
    break;
    }
    player = (player%2) +1;
    clrscr();
    check_4_winner();

    }

    if(tie==1)
    {
    cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;
    cout << "\n";
    cout << "A Tie!\n\n\n";
    goto end;


    }
    if(player == 1)
    {
    cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;
    cout << "\n";
    cout << "Player 2 Wins!!\n\n\n";
    goto end;


    }
    if(player == 2)
    {
    cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;
    cout << "-----+-----+-----" << endl;
    cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;
    cout << "\n";
    cout << "Player 1 Wins!!\n\n\n";
    goto end;


    }
    check_4_winner();
    tie:;
    cout << endl << "TIE GAME!"<<endl;

    end:;
    }


    //Clear Screen -----------------------
    void clrscr()
    {
    for(register i=0;i<=30;i++)
    {
    cout << endl;
    }
    }

    //Check for a winner ---------------------------
    void check_4_winner()
    {
    clrscr();
    if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
    (board[0][2]==board[1][1] && board[0][2]==board[2][0]))
    {
    winner=1;
    }
    else
    {
    for(int i=0; i <=2;i++)
    {
    if((board[i][0] == board[i][1] &&
    board[i][0] == board[i][2]) ||
    (board[0][i] == board[1][i] &&
    board[0][i] == board[2][i]))
    winner = 1;
    }


    }

    }
    // END CODE!!
    //---------------------------------------

    well i know its rarely commented but it shoudnt be to hard to figure the logic.
    But feel free to post as many questions as you like! I'll try my best to help anyone that might need it!

    My next step is to input a computer difficulty!!
    and work out the bug(s)

    -------------------------------
    BUGS
    -------------------------------
    1.) We'll the only one that really counts is when you get a tie, you have to type one more number befor it recognizes it. It's not to big but it is bothersom and i have yet to fix it!

    ------------------------------
    GENERAL INFO.
    ------------------------------
    This was Programmend by me of course, and i used
    Visual C++ 6.0
    I don't know if that helps some but it might.

    --
    ok i think thats about it! All the advanced programmers didn't need it i aimd at newbies like my self. Eventully i want...

    AI
    Actully Graphics(IE: mode 13h and lines)
    No Bugs
    And mouse support

    --
    We'll i can get all those eventully except mode 13h and real graphics caue i cant use mem.h since i dont have it. So untill i find a way around it or a tutorial to teach me how to gointo 13h without it you'll be stuck with this

  2. #2
    .
    Join Date
    Aug 2001
    Posts
    598
    First, you can upload you cpp file so you don't have to post the code.

    Second goto's are a no no.

    Third visual C++ is a windows only compiler, mode 13h is for dos. Graphics need to be helf off until you have a good understanding of the lanuge. Then you could use directx, opengl, or even the windos gdi.

    Forth keep up the good work.
    To Err Is To Be Human. To Game Is Divine!"

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you cant do int13h graphics with your current compiler......

    Get a copy of DJGPP if you want to do that.

    read some of the recent threads on the c++ board for the link to DJGPP.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well first off, goto's aren't a "nono" its just they usually mean that in your mind you are saying "I don't know how to do this with an if, for, while, or do statement so I'll use a goto." And yes 13h does require a new compiler (i use turbo c) but you could just use a different means of creating graphics. Your options are work with windows, opengl, directX,or MFC. Or use a dos compiler.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    16

    Arrow hey...

    I agree, somewhat. Goto is not a bad statement, at least not for some things. If you dont want people to steal your code as often, gotos will stop some of them. The computer could care less how you tell it to get where it is going. It has a bad name because if anyone else wants to look at your code then he might have trouble. I don't use gotos, but would have no trouble looking through code with them. You people have messy rooms, you don't have problems finding stuff in them do you?
    "Practice means good, Perfect Practice means Perfect"

  6. #6
    Ryce
    Guest

    Cool

    heh i've herd gotos are not the best thing. But it works! I'll look for a more efficiant way to write the program, i know that my code wasnt as efficiant as others.

    i will upload code for now on.

    and thx i really had no clue why i couldnt do graphics with vc++.
    Ill get DJCPP. well i guess ill post later when an acomplisment is made...

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    www.delorie.com/djgpp

    also, if you want to really get into game programming, i suggest you take a look at the Allegro library, but i think it's a long ways understanding (and coding practice) until then... good luck!
    hasafraggin shizigishin oppashigger...

  8. #8
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    theres nothing wrong with gotos. i believe that they were called "evil" because of spagetty codes, were you have to keep finding were gotos go. but a start: and end: couldn't hurt, could they. it lets you easaly go to the end or the start of a program.

    but here i would of used a function

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well I'd say using goto's to prevent source theft will work maybe 50% of the time and that is only because us programmers can get rather lazy. I'm not so lazy that I can't do a search for the goto(like CTRL+F on my ide). I think goto's are just the same as if's, do's, while's, and for's but only more complicated (most times). For exampe:
    Code:
    for(i = 0; i < 100; i++){
    //whatever
    }
    could be done with goto statements and be a mess:
    Code:
    i = 0;
    forloop:
        if(i >= 100){
           goto end_of_loop;
        } else {
           //whatever
           i++;
           goto forloop;
        }
    end_of_loop:
    Nothin' different between the two. The first is just easier on the eyes. If you don't like goto's at all then by all means avoid assembly langauge.

  10. #10
    Registered User
    Join Date
    Aug 2001
    Posts
    16
    Are you trying to say that C language automatically uses the assembly equiv. of gotos without us knowing? I know it has to find out where to go next, but I don't mess with that sort of stuff.
    "Practice means good, Perfect Practice means Perfect"

  11. #11
    MBee
    Guest
    Hmmm, I am learning C++ right now, and am using Bloodshed Dev-C++, but I plan to program games later so I have downloaded DJGPP and the Allegro Lib., with RHIDE. I feel comfortable with Dev-C++ right now because of its interface, but, can I use Allegro with Dev-C++. I am a complete NooB to C++, but it looks familiar to Perl, with the if else statements, and braces, and all, but....

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Lol! Hey kingruss, I'm not saying that c changes everything to an assembly equivilent. But maybe it does, I don't know. I'm just pointing out that c may have spoilled all of us just a little bit. In asm you don't have luxuries such as for loops and need to use goto's. Maybe the only reason for goto's in c is so that it resembles other langauges more.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,670
    I feel comfortable with Dev-C++ right now because of its interface, but, can I use Allegro with Dev-C++.
    I don't think you can...



    ITSA
    Socket Library!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ game programmers wanted
    By Mark Smulders in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 06-11-2007, 08:26 AM
  2. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  4. Programmers Wanted: Game Development
    By Loknar Gor in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-17-2006, 06:00 AM
  5. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21