Below you will find a game I written in my spare time from college. Any and all critique welcome. I plan to expand this to a console RPG later, and eventually GUI. All in C++.
BTW, nice forums.
//============================================================================
// Name : Monster Shot.cpp
// Author : Dave T
// Description : Monster Shot is an array based game in which the user
// makes guesses in the form of inputing numbers in order to hit monsters hiding
// in the array.
// Additional Notes: I wrote this with a friend to help understand C++ basics
//============================================================================
/** PREPROCESSOR DIRECTIVES **/
#include <iostream>
/** CONSTANTS **/
// WORLD SIZE Determines the playable space of the game
#define EASY_WORLD_SIZE 6
#define NORMAL_WORLD_SIZE 10
#define HARD_WORLD_SIZE 25
// The number of shots the user has
#define EASY_AMMO 3
#define NORMAL_AMMO 7
#define HARD_AMMO 12
// Gives + to ammo
#define POWERUP_AMMO -1
#define POWERUP_X2 -2
using namespace std;
/** GLOBAL VARIABLES **/
int easyBoard[EASY_WORLD_SIZE] = {-1,1,0,1,1,0}; // Easy Game Board
int normalBoard[NORMAL_WORLD_SIZE] = {1,1,0,0,10,1,0,1,-1,10}; // Normal(Default) Game Board
int hardBoard[HARD_WORLD_SIZE] = {0,-2,1,10,0,1,0,1,1,10,1,1,0,-2,0,1,0,0,1,1,10,1,1,0,-1}; // Hard Game Board
int * pBoard; // Points at board that the user selects
int worldSize; // holds worldSize value
int gameAmmo; // holds ammo
/** MESSAGE HANDLER **/
char msgHowtoPlay[] = "HOW TO PLAY : \n"
"Enter a number\n"
"and it will either result in a hit or \n"
"miss for a monster.\n\n";
char msgChooseDifficulty[] = "CHOOSE DIFFICULTY SETTING\n"
"Enter: 'e'\t'n'\t'h'\n"
"\nEasy: 5 space board\n"
"Normal: 10 space board\n"
"Hard: 25 space board\n\n";
char msgGameOver[] = "\nOut of ammo!\n\n"
"A shadow of fear washes over you\n"
"as the monsters approach...\n\n"
"GAME OVER\n\n";
char msgYouWin[] = "All monsters slain.\n"
"YOU WIN!\n\n";
char msgMonsterHit[] = "You hit a monster \n";
char msgWheretoAim[] = "\nWhere will you aim? (Enter # between 1 - ";
char msgInvalid[] = "invalid input, try again\n";
char msgMissed[] = "Hey man, you missed \n";
/** FUNCTION DEFINITIONS **/
void intro()
{
cout << msgHowtoPlay;
}
// Difficulty Setting Handler
void chooseDifficulty()
{
char diffChoice;
cout << msgChooseDifficulty;
cin >> diffChoice;
if(diffChoice == 'e')
{
pBoard = easyBoard;
gameAmmo = EASY_AMMO;
worldSize = EASY_WORLD_SIZE;
cout << "You have selected [easy].\n";
}
else if(diffChoice == 'n')
{
pBoard = normalBoard;
gameAmmo = NORMAL_AMMO;
worldSize = NORMAL_WORLD_SIZE;
cout << "You have selected [normal].\n";
}
else if(diffChoice == 'h')
{
pBoard = hardBoard;
gameAmmo = HARD_AMMO;
worldSize = HARD_WORLD_SIZE;
cout << "You have selected [hard].\n";
}
else
{
pBoard = normalBoard;
gameAmmo = NORMAL_AMMO;
worldSize = NORMAL_WORLD_SIZE;
cout << "Default selection: [normal].\n";
}
cout << "You have "<< gameAmmo << " Shots\n";
}
// CHecks for 0 Ammo
bool gameOver()
{
if(gameAmmo == 0)
{
cout << msgGameOver;
return true;
}else
return false;
}
// Checks for clear board
bool checkWin()
{
for(int i=0;i<worldSize; i++)
{
if(pBoard[i] > 0)
{
return false;
}
}
return true;
}
/****************************************************************/
int main()
{
int shot; // the user's shot
int i; // holds decremented shot as index for board
int score = 0;
// GAME RULES & DIFFICULTY HANDLING
intro();
chooseDifficulty();
// GAME
while(true)
{
cout << msgWheretoAim << worldSize << ") ";
cin >> shot;
if(shot < 1 || shot > worldSize)
{
cout << msgInvalid;
continue;
}
// converts user's shot to index
i = shot-1;
gameAmmo--;
// Check for monster Hit
if(pBoard[i] > 0)
{
// You got one!
cout << msgMonsterHit;
score+=pBoard[i];
if(pBoard[i] == 10)
{
cout << "+ 10 points!\n";
}
// Clear the space and check for a win
pBoard[i] = 0;
// Checks for
}else if(pBoard[i] == POWERUP_AMMO)
{
gameAmmo+=2;
cout << "BONUS! + 2 to ammo!\n";
cout << gameAmmo << " shots remaining \n\n";
}else if(pBoard[i] == POWERUP_X2)
{
gameAmmo+=3;
cout << "BONUS! + 3 to ammo!\n";
cout << gameAmmo << " shots remaining \n\n";
}else
{
cout << msgMissed;
cout << gameAmmo << " shots remaining \n";
if(gameOver() == true)
{
break;
}
}
if(checkWin() == true)
{
cout << msgYouWin;
break;
}
}
cout << "Final Score: " << score << endl;
return 0;
}