Thread: Game Starter?

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Unhappy Game Starter? (Now with Tic-Tac-Toe!)

    I have been at C++ for quite some time now, but how would I make a game?!

    I use Dev-C++ and everytime I even run the sample New Project -> WINDOWS APP it CANT RUN THE PROGRAM!

    The tutorials I have found just explain arrays text excetera... How would I draw a image? A line?

    Sorry Im a n00b but I am lost how people make there C++ progs.
    Last edited by CammoDude91; 07-26-2003 at 07:29 PM.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Its not a simple matter as youve probably guessed by now nothing is simple in C++ lol. If you don't know how to create windows then I recommend the book Tricks of the Windows Game Programming Gurus. This book assumes you know C++ and starts off nice and gentley with creating windwos and moves onto to cover all about direct x and at the end of it you should know enough to create your games.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Before worrying about your game, you'll need to find out why you can't compile/run a sample program. What errors are you getting?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I would suggest starting with console games before you move on to windows. A good first game to program is simple tic tac toe. From there, you can add some AI to your ttt game, or you can move on to something like pong or tetris or maybe checkers. Look into the SDL and Allegro libraries for an easy way to do graphics in console mode.
    Away.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Smile ok, thanks.

    please keep the comments comming! I will go make a tic-tac-toe soon enough with AI!
    However I have downloaded Allegro expecting different from what I got. It was a bunch of .dat and .txt files in folders. There was nothing I knew how to do.
    I do know that Icy Tower used Allegro however and I love that game...

  6. #6
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    you sound an intelligent person, just researc the following winapi calls (well the basic structure and windows based variables would help you also (inparticularly Window Procedures and Window Classes)

    CreateWindow(*);
    BitBlt(*);
    CreateCompatibleDC(*);
    CreateCompatibleBitmap(*);
    SelectObject(*);
    LoadImage(*);
    DeleteDC(*);
    DeleteObject(*);

    Most of these are GDI calls.. and a few User32's, i would totaly research the winapi its so simple and well these days im beginning to think that windows will be the only os avaliable soon (altho mac and linux could pull together and create computers with a nice open source os with really cool mac hardware lol)
    if u want il gladly write a demonstration app (would be in m$ c++ syntax tho) hope it helps

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Smile Thank you all!

    Wow, thanks a lot guys. And I will look into those calls after my tic-tac-toe game. However, I ran into a bug.


    #include <iostream>
    #include <stdlib.h>

    using namespace std; // Whatever the hell that means.

    int main(int argc, char *argv[]) // It was like this when I started. Dont touch!
    {
    // INT the position variables :-p
    int L1_R1 = 0;
    int L1_R2 = 0;
    int L1_R3 = 0;
    int L2_R1 = 0;
    int L2_R2 = 0;
    int L2_R3 = 0;
    int L3_R1 = 0;
    int L3_R2 = 0;
    int L3_R3 = 0;
    int US_ER = 0;
    int CO_NM = 0; /* max = 5 */

    // Intro the user... till they fall asleep... *yahn*
    cout<<"-=[ TIC-TAC-TOE ]=-"<<endl;
    cout<<"-By Cameron Garvie-"<<endl<<endl;
    cout<<"I assume you know how to play Tic-Tac-Toe, and this is no different."<<endl;
    cout<<"I show you the board, and ask for your position. Then I update it."<<endl;
    cout<<"The first player to get three in a row wins. Although I am unbeatable."<<endl;
    cout<<endl<<"The main format for your position is the width then the height.";
    cout<<endl<<"Here is an example, 22. This will put a 8 in the center.";
    cout<<endl<<"You can be 8's. I will be 4's. There is no difference. Don't complain.";
    cout<<endl<<"Zero's mean that the space is empty and you may go there.";
    cout<<endl<<endl;

    // You mean we actually "play" the game? lol.
    cout<<"Let's begin! Here is the board:"<<endl;
    while (CO_NM<5)
    {
    // What a ghetto looking board.
    cout<<" "<<L1_R1<<"|"<<L2_R1<<"|"<<L3_R1<<endl;
    cout<<" "<<"- - -"<<endl;
    cout<<" "<<L1_R2<<"|"<<L2_R2<<"|"<<L3_R2<<endl;
    cout<<" "<<"- - -"<<endl;
    cout<<" "<<L1_R3<<"|"<<L2_R3<<"|"<<L3_R3<<endl;
    cout<<"So what is your choice? ";
    cin>>US_ER;

    // What the hell did they say? And what does it mean?
    if (US_ER = 11) { L1_R1 = 8; } else { L1_R1 = 4; }
    if (US_ER = 12) { L1_R2 = 8; } else { L1_R2 = 4; }
    if (US_ER = 13) { L1_R3 = 8; } else { L1_R3 = 4; }
    if (US_ER = 21) { L2_R1 = 8; } else { L2_R1 = 4; }
    if (US_ER = 22) { L2_R2 = 8; } else { L2_R2 = 4; }
    if (US_ER = 23) { L2_R3 = 8; } else { L2_R3 = 4; }
    if (US_ER = 31) { L3_R1 = 8; } else { L3_R1 = 4; }
    if (US_ER = 32) { L3_R2 = 8; } else { L3_R2 = 4; }
    if (US_ER = 33) { L3_R3 = 8; } else { L3_R3 = 4; }

    CO_NM++;
    }
    return 0;
    }


    The problem is all input fills the chart with 8's. Which is not what I want. When I tried case statements it did not work either. I tried to do this without any tutorials and this was what I got. About me being intelligent - I'll have to work on that, I'm only 10. lol.

    Again, thank you... Now to the debugging! lol.

    PS: About your OS prediction. I agree, but Mac looks soooo much cooler these days. And I just saw some Add about a new G5 Proccessor, the fastest ever! Windows is ahead simply because they have more software, although people illegaly port most to Linux.
    Last edited by CammoDude91; 07-26-2003 at 03:49 PM.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    if (US_ER = 11) { L1_R1 = 8; } else { L1_R1 = 4; }
    that checks whether US_ER gets set to 11
    Code:
    if (US_ER == 11) { L1_R1 = 8; } else { L1_R1 = 4; }
    use the equality, not assignment operator
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Talking thx dude!

    ah... GML is really hard to quit, still using the = as a equality checker! thx though!

  10. #10
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Thumbs up I finished!

    So its defintly not the greatest, and the AI is terrible! But hey, Im still proud.

    include <iostream>
    #include <stdlib.h>

    using namespace std; // Whatever the hell that means.
    int main(int argc, char *argv[]) // It was like this when I started. Dont touch!
    {
    // INT the position variables :-p
    int L1_R1 = 0;
    int L1_R2 = 0;
    int L1_R3 = 0;
    int L2_R1 = 0;
    int L2_R2 = 0;
    int L2_R3 = 0;
    int L3_R1 = 0;
    int L3_R2 = 0;
    int L3_R3 = 0;
    int US_ER = 0;
    int CO_NM = 0;
    int CA_NO = 0;

    // Intro the user, untill they fall asleep... *yahn*
    cout<<"-=[ TIC-TAC-TOE ]=-"<<endl;
    cout<<"-By Cameron Garvie-"<<endl<<endl;
    cout<<"I assume you know how to play Tic-Tac-Toe, and this is no different."<<endl;
    cout<<"I show you the board, and ask for your position. Then I update it."<<endl;
    cout<<"The first player to get three in a row wins. Although I am unbeatable."<<endl;
    cout<<endl<<"The main format for your position is the width then the height.";
    cout<<endl<<"Here is an example, 22. This will put a 8 in the center.";
    cout<<endl<<"You can be 8's. I will be 4's. There is no difference. Don't complain.";
    cout<<endl<<"Zero's mean that the space is empty and you may go there.";
    cout<<endl<<endl;

    // You mean we actually "play" the game? lol.
    cout<<"Let's begin! Here is the board:"<<endl;
    while (CO_NM<5)
    {
    // What a ghetto looking board.
    cout<<" "<<L1_R1<<"|"<<L2_R1<<"|"<<L3_R1<<endl;
    cout<<" "<<"- - -"<<endl;
    cout<<" "<<L1_R2<<"|"<<L2_R2<<"|"<<L3_R2<<endl;
    cout<<" "<<"- - -"<<endl;
    cout<<" "<<L1_R3<<"|"<<L2_R3<<"|"<<L3_R3<<endl;
    cout<<"So what is your choice? ";
    cin>>US_ER;

    // What the hell did they say?
    if (US_ER == 11) { L1_R1 = 8; }
    if (US_ER == 12) { L1_R2 = 8; }
    if (US_ER == 13) { L1_R3 = 8; }
    if (US_ER == 21) { L2_R1 = 8; }
    if (US_ER == 22) { L2_R2 = 8; }
    if (US_ER == 23) { L2_R3 = 8; }
    if (US_ER == 31) { L3_R1 = 8; }
    if (US_ER == 32) { L3_R2 = 8; }
    if (US_ER == 33) { L3_R3 = 8; }

    // Backing up that "Unbeatable" comment!
    CA_NO = 0;
    if (CA_NO == 0) { if (L1_R1 == 8) { if (L1_R2 == 8) { if (L1_R3 == 0) {
    L1_R3 = 4; CA_NO = 1; } } } }
    if (CA_NO == 0) { if (L1_R1 == 8) { if (L2_R1 == 8) { if (L3_R1 == 0) {
    L3_R1 = 4; CA_NO = 1; } } } }
    if (CA_NO == 0) { if (L1_R1 == 8) { if (L2_R2 == 8) { if (L3_R3 == 0) {
    L3_R3 = 4; CA_NO = 1; } } } }
    if (CA_NO == 0) { if (L1_R1 == 0) { L1_R1 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L2_R2 == 0) { L2_R2 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L3_R3 == 0) { L3_R3 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L1_R2 == 0) { L1_R2 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L1_R3 == 0) { L1_R3 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L2_R1 == 0) { L2_R1 = 4; CA_NO = 1; } }
    if (CA_NO == 0) { if (L2_R3 == 0) { L2_R3 = 4; CA_NO = 1; } }

    // Add to the move count...
    CO_NM = CO_NM + 1;
    }

    // Lets wrap this up!
    cout<<endl<<endl;
    cout<<"Well thats it... this was just a little game i made to learn C++!"<<endl;
    cout<<"I hope you enjoyed it! Please help me with the AI. I should have "<<endl;
    cout<<"used arrays. Then I could program better opponents. Well, goodbye."<<endl;
    cout<<endl;
    system("pause");
    return 0;
    }
    Thats it! Thanks for all your support! I will now move on to a Text RPG! Then windows is comming up...
    Last edited by CammoDude91; 07-26-2003 at 06:41 PM.

  11. #11
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    By the way, judging by your comments you're confused about a couple of things.

    You should have a look around for some info on the C++ feature "namespaces", don't concern yourself too much with this at the moment as it's a more advanced feature. You just need to know that things like iostream are in the std namespace. So when you say "using namespace std;" you're telling the compiler that you will be saying things like "cout" in your code, and you will be referring to the "cout" in iostream.

    Also, the arguments in the main() function are for command line arguments, which your program can use for various things, like decide how to execute.
    Last edited by HybridM; 07-26-2003 at 07:09 PM.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  12. #12
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    More specifically, argc is the number of arguments and argv is an array of strings, so you could run your program from a command prompt or something like:
    Code:
    c:\myprog.exe argument
    and you could find that the user entered "argument" when he ran the program
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Talking I get it...

    I get it now... Thank you!
    Could you comment on my Tic-Tac-Toe creation?

  14. #14
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    The way it is you can select slot "11" and put an 8 there and then select it your next turn and you put an 8 there again...you could put the values in an array or something and then check each element in the array to see if it is a 4 or an 8 or if they are actually allowed to select that slot
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  15. #15
    Registered User
    Join Date
    Jul 2003
    Posts
    27

    Unhappy good point...

    Well. I really dont want to continue such a simple game - so I will move on to RPG. But thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  3. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  4. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM