Feb 3, 2008 at 8:16am UTC
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 ) . :P
-game.h-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//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.cpp-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
// 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? :)
Last edited on Feb 3, 2008 at 8:17am UTC
Feb 3, 2008 at 9:29am UTC
Well the odds are slim to win and instead of printing $100 per round you just have new score. Maybe prompting the user with the goal is $1000 at the begin might help clear up what is the goal. Overall a good game with nice layout. Good Job!
Last edited on Feb 3, 2008 at 9:43am UTC
Feb 3, 2008 at 9:32am UTC
...
Last edited on Feb 3, 2008 at 9:42am UTC