• Advertisement
Sign in to follow this  

Hello World

This topic is 4684 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
supercoder, just btw by siccors i think u mean scissors (or was it a pun of somesort)

btw a good game to make is any classic board game - do the logic then take pictures of the board/paste it

Share this post


Link to post
Share on other sites
the real hello world of game programing is ofcourse random number guessing.
in ofcourse, the real hello world languge, python, not to say that it's a noob languge, just saying that it's easy to pick up and does what you want it to without any tricks :D


import random
rand = random.randint(1,10)
guess = input('guess a number between 1 and 10: ')
if guess == rand:
print 'congratulations, you guess right!'
else:
print 'sorry, try again'



Share this post


Link to post
Share on other sites
Thanks for all the replies, im a second year in CS so i am familiar with standard C and C++ and am interested in the display of graphics and using the more non standard libraries in the wintel enviroment. I can do rand guessing and have made some small games such as that as well as some text based games (very small but they compile and work :) ) .

again thanks for the replies.

Share this post


Link to post
Share on other sites
thats the problem with formal education, you don't have a chance to explore and form conclusions on your own.

if your actuly in second year uni and asking a question like this, you need some major work on programing. spend about a year programing on your own.

if your not, the first logicaly step would be learning a graphics API.

Share this post


Link to post
Share on other sites
Quote:
Original post by kburkhart84
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.


I think pong is the direction i want to go anyone know where i can find the source for pong or something similar to it.

as for the state of my education it is mostly focused on algorithms and analysis, i can for instance make a tree stucture that loads a DB file into memory and assigns the entries to a tree structure. but putting a background image in the console window is outside my education.

im not a huge fan of python but i am familiar with it. my intro to programming class was done in python my data structures was done in C and my current programming class is C++.

Share this post


Link to post
Share on other sites
I have some simple console games you can download. http://fire.prohosting.com/ride9736/

Please note these are very humble offerings. Hope they help.

Share this post


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

  • Advertisement