Jump to content
  • Advertisement
Sign in to follow this  
sinrtb

Hello World

This topic is 4778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What would be the hello world of a game? Can anyone show me where to fine an example of a well commented source for a fairly basic game. something so i can get an idea of the different libraries and how they work?

Share this post


Link to post
Share on other sites
Advertisement
Im not really sure what you want. I dont know what part of a game that is reffered to as "hello world". Could you explain it a little more?

There are plenty of games in open source with very nice code. Ill see if I can dig up anything.

Share this post


Link to post
Share on other sites
Tic tac toe is the hello world of games. I'm not sure which programming language you're using but here's my version of ttt in C++


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
char grid[9]={'0','1','2','3','4','5','6','7','8'};
int i, ch;
char player='X',winner='.';

while (winner=='.') { // '.' means no one has won
// swap players
if (player=='X') player='O'; else player='X';
// draw board
for (i=0;i<9;i=i+3) cout << grid << grid[i+1] << grid[i+2] << endl;
// get user input
cout << "Player "<<player<<" turn:";
cin >> ch;
// put the player's go into grid[] array
grid[ch]=player;
// check for winner
for (i=0;i<3;i++) {
// check for vertical win
if (grid==grid[i+3] && grid[i+3]==grid[i+6]) winner=grid;
// check for horizontal win
if (grid[i*3]==grid[(i*3)+1] && grid[(i*3)+1]==grid[(i*3)+2]) winner=grid[i*3];
}
// check for diagonal wins
if (grid[0]==grid[4] && grid[4]==grid[8]) winner=grid[0];
if (grid[2]==grid[4] && grid[4]==grid[6]) winner=grid[2];
system("cls"); // clear screen
}
// draw board again
for (i=0;i<9;i=i+3) cout << grid << grid[i+1] << grid[i+2] << endl;
cout << "Winner is " << player <<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

Share this post


Link to post
Share on other sites
Ah I see :P. Hello world is the first you do when you do the basic programs, you want the basic game. :P

Well Ive just finished my snake clone (you know the one from the nokia phones?) as a ascii game in console c++. If you want the source just ask, but that tic tac toe looks a liiittle bit simplier. :P

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Paper/Scissors/Rock is an easy game to make.

Share this post


Link to post
Share on other sites
for console: number guessing game is pretty easy:

computer picks random number (1 to 1000)
you guess
comp -> too high / low
you try again
comp -> too high to low
...

you have to get the number whithin 10 guesses


for graphical: pong / connect 4 / noughts and crosses / checkers ...
(only 2 player ie. no AI)

Share this post


Link to post
Share on other sites
I'd say tic tac toe or pong are good. Tetris is more complex as is breakout etc... PacMan, tetris, breakout, are good for second games in my opinion.

Share this post


Link to post
Share on other sites
Im thinking guess the number is probably the simplest game to implement. Memory type games are pretty easy and cool too becuase you can expand upon them as you learn gfx.

Share this post


Link to post
Share on other sites
Ive done a rock/paper/sciccors:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
cout<<"welcome to the rock paper sciccors game!"<<endl;
int times;
cout<<"how many times would you like to play?"<<endl;
cin>>times;
int choice;
int computer;
int score = 0;
int compscore = 0;
cout<<"enter a 1 to three.1:rock,2:paper,3:sciccors"<<endl;

for(int i=0;i<times;i++)
{
choice=0;
cin>>choice;
switch(choice)
{
case 1:
cout<<"you did rock."<<endl;
break;

case 2:
cout<<"you did paper."<<endl;
break;

case 3:
cout<<"you did sciccors."<<endl;
break;

default:
cout<<"not a valid choice. ener a valid choice."<<endl;
i=i-1;
cin>>choice;
continue;
break;

}
computer=0;
srand(time(0));


computer=(rand() % 3) + 1;
switch(computer)
{
case 1:
cout<<"computer did rock."<<endl;
break;

case 2:
cout<<"computer did paper."<<endl;
break;

case 3:
cout<<"computer did sciccors."<<endl;
break;
}
switch(computer)
{
case 1:
if(choice==3)
{
cout<<"computer won round!"<<endl;
compscore=compscore+1;
}
else if(choice==2)
{
cout<<"player won round!"<<endl;
score=score+1;
}
else if(choice==1)
{
cout<<"you got the same move as the computer. Do this round again."<<endl;
i=i-1;
continue;
}
break;

case 2:
if(choice==1)
{
cout<<"player won round!"<<endl;
score=score+1;
}
else if(choice==3)
{
cout<<"computer won round!"<<endl;
compscore=compscore+1;
}
else if(choice==2)
{
cout<<"you got the same move as the computer. Do this round again."<<endl;
i=i-1;
continue;
}
break;

case 3:
if(choice==2)
{
cout<<"computer won round!"<<endl;
compscore=compscore+1;
}
else if(choice==1)
{
cout<<"player won round!"<<endl;
score=score+1;
}
else if(choice==3)
{
cout<<"you got the same move as the computer. Do this round again."<<endl;
i=i-1;
continue;
}
break;
}
}
if(score>compscore)
{
cout<<"player won game!!!"<<endl;
}
else if(score<compscore)
{
cout<<"computer won game!!!"<<endl;
}
else if(score==compscore)
{
cout<<"it was a tie!!!"<<endl;
}
system("pause");
}



its not commented, sorry.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!