Well, it's a text game, a console application. And does not have images, or animations.
But this is my first game that I develop ( my other programs were applications that solved math problems ) .
Executable:
game.exeNote: I used visual studio, though you need the .NET framework.
Source code:
game.hCODE
//game.h : header file = 23 lines of codes ( 373 including the .cpp file )
#ifndef GAME_H
#define GAME_H
#include <iostream>
class juego
{
int score, over;
public:
int setsScore(){return score++;};
int gameOver() {return over++;};
void winner();
void lose();
void bonus();
void randomize();
juego();
};
#endif
game.cppCODE
// game.cpp : main project file = 350 lines of codes ( 373 including header file )
#include "game.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int caja1, caja2, caja3;
int x, y;
int suma;
int SCORE, GAMEOVER;
char type[10];
int health = 5;
#include <ctime>
#include <cstdlib>
void juego::randomize()
{
//randomize the numbers generator
srand(time (0) );
//obtains random numbers
x = 1 + rand() % 6;
y = 1 + rand() % 6;
suma = x + y;
//Sets to true one of the three boxes
if ( suma >= 1 && suma <= 4 )
{
caja1 = true;
}
if ( suma >= 5 && suma <= 8 )
{
caja2 = true;
}
if ( suma >= 9 && suma <= 12 ){
caja3 = true;
}
}
//Initializes members of the class juego
void juego::winner()
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n YOU GOT $1,000. Thanks for playing.\n\n\n\n\n\n\n\n\n";
}
void juego::lose()
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n GAME OVER!!!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
void juego::bonus()
{
GAMEOVER -= 2;
health += 2;
cout << "\n\n[YOU GOT TWO EXTRA LIVES] You currently have " << health << " lives.\n\n";
}
//Constructor, sets the boxes to 0 and sets the score and lives.
juego::juego()
{
score = 1;
SCORE = 0;
over = 1;
GAMEOVER = 0;
bool caja1 = false;
bool caja2 = false;
bool caja3 = false;
}
int main()
{
//objects of the class juego
juego iniciar; //Starts the game by randomizing the seed, (puts the money in one of the boxes)
juego set; //Sets the new score
juego lives; //lives
juego win; //Object that shows the winner message
juego game_over; //Object that shows the message of Game Over
juego extra; //Gives two extra lives
do{
cout << "--------------------------------------------\n|One of these boxes has $100.00.| " << endl << endl;
cout << "[*] [*] [*]";
cout << "\n 1 2 3";
cout << endl << endl;
//randomize
iniciar.randomize();
cout << "Type the number of the box you think is the right one: ";
cin >> type;
atoi(type);
switch ( type[0] ){
case '1':
//If the user selected the correct box adds one to score
if ( caja1 == 1 )
{
cout << "\n** New score: " << set.setsScore() << " **\n\n";
SCORE++;
caja1 = 0;
caja2 = 0;
caja3 = 0;
if ( SCORE == 5)
{
extra.bonus(); //gives extra lives
}
//If the user have 10 points, win.
if ( SCORE == 10 ){
win.winner(); //shows congrats message
caja1 = 1;
system("PAUSE");
}
}
else
{
lives.gameOver();
GAMEOVER++;
health--;
if ( GAMEOVER == 5 ){
game_over.lose(); //shows game over message
caja1 = 1;
system("PAUSE");
}
else{
caja1 = 0;
caja2 = 0;
caja3 = 0;
cout << "\nTRY AGAIN\n";
//shows where the money was located
if ( suma >= 1 && suma <= 4 )
{
cout << "\n\nThe money was in box #1\n\n";
}
if ( suma >= 5 && suma <= 8 )
{
cout << "\n\nThe money was in box #2\n\n";
}
if ( suma >= 9 && suma <= 12 ){
cout << "\n\nThe money was in box #3\n\n";
}
cout << "- Lives left = " << health << " -\n\n";
system("PAUSE");
cout << "\n";}
}
break;
case '2':
//If the user selected the correct box adds one to score
if ( caja2 == 1 )
{
cout << "\n** New score: " << set.setsScore() << " **\n\n";
SCORE++;
caja1 = 0;
caja2 = 0;
caja3 = 0;
if ( SCORE == 5)
{
extra.bonus(); //gives extra lives
}
//If the user have 10 points, win.
if ( SCORE == 10 ){
win.winner(); //shows congrats message
caja2 = 1;
system("PAUSE");
}
}
//Losing points
else
{
lives.gameOver();
GAMEOVER++;
health--;
if ( GAMEOVER == 5 ){
game_over.lose(); //shows game over message
caja2 = 1;
system("PAUSE");
}
else{
caja1 = 0;
caja2 = 0;
caja3 = 0;
cout << "\nTRY AGAIN\n";
//shows where the money was located
if ( suma >= 1 && suma <= 4 )
{
cout << "\n\nThe money was in box #1\n\n";
}
if ( suma >= 5 && suma <= 8 )
{
cout << "\n\nThe money was in box #2\n\n";
}
if ( suma >= 9 && suma <= 12 ){
cout << "\n\nThe money was in box #3\n\n";
}
cout << "- Lives left = " << health << " -\n\n";
system("PAUSE");
cout << "\n";
}
}
break;
case '3':
//If the user selected the correct box adds one to score
if ( caja3 == 1 )
{
cout << "\n** New score: " << set.setsScore() << " **\n\n";
SCORE++;
caja1 = 0;
caja2 = 0;
caja3 = 0;
if ( SCORE == 5)
{
extra.bonus(); //gives extra lives
}
//If the user have 10 points, win.
if ( SCORE == 10 ){
win.winner(); //shows congrats message
caja3 = 1;
system("PAUSE");
}
}
//Lose points
else
{
lives.gameOver();
GAMEOVER++;
health--;
if ( GAMEOVER == 5 ){
game_over.lose(); //shows game over message
caja3 = 1;
system("PAUSE");
}
else{
//sets the boxes to 0.
caja1 = 0;
caja2 = 0;
caja3 = 0;
cout << "\nTRY AGAIN\n";
//Shows where the money was located
if ( suma >= 1 && suma <= 4 )
{
cout << "\n\nThe money was in box #1\n\n";
}
if ( suma >= 5 && suma <= 8 )
{
cout << "\n\nThe money was in box #2\n\n";
}
if ( suma >= 9 && suma <= 12 ){
cout << "\n\nThe money was in box #3\n\n";
}
cout << "- Life left = " << health << " -\n\n";
system("PAUSE");
cout << "\n";}
}
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout << "\aYou typed an invalid number.\n" << endl;
caja1 = 0;
caja2 = 0;
caja3 = 0;
break;
}
cin.get();
} while ( caja1 == 0 && caja2 == 0 && caja3 == 0 );
return 0;
}
The program shows three boxes.
The point is to get $1000, by guessing where's the money.
what do you think?
This post has been edited by c--: 3 Feb, 2008 - 10:26 AM