/*Date:06hb.10.2010
**Time:3.04pm
**GAME TITLE: Space Adventure
**A Game For Windows [by using Dev C++]
**Copyright 2010 [@zrI & ZomBiedy]
*/
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
using namespace std;
struct GAME
{ //struct definition
char menu[15];
};
struct P_DATA
{
string P1name;
string P2name;
};
//global variables
const int row=9,col=8;
int i,j,current_i,current_j,step;
GAME advGame[4];
P_DATA user[1];
int no_menu;
int hp=20, mp=20, ehp=30, move, emove;
const int size_question=70;//to make it really random, try to get around 70 questions
int LimitBattle=35; //limiting battle to only 35
int LimitRest = 20; //limiting resting to only 20
struct WORLD //world of the game
{
char* board[row][col]; //the board, or the playing field
int game_element[row][col]; //1 resting,2 question,3 portal/jump,4 battle
}world; //note: make game_element at [0][0],[row-1][col-1] = 0
struct QUESTIONS
{
string q;
char ans;
int status; //keep status of being answer or not. if already use, value 1
}questions[size_question];
//function prototypes
int dice(void);
void intBoard(void);
void intgame_element(void);
void displayBoard(void);
void initialMenu(GAME advGame[4]);
void GameStart(int player);
void S_player(void);
void M_player(void);
void newGame(void);
void guideline(void);
void credit(void);
void selectMenu(int no_menu);
void displayMenu(GAME advGame[]);
void wait(float seconds);
void win(int turn);
int question(void);
void picture(void);
void initializeQuestion (void);
void initializeStatus (void);
void slowstepsBoard2(int step);
int hp2=20, mp2=20;
void rest(int turn);
void portal(int turn);
int battle (int turn);
int player;
void lose(int turn);
void slowstepsBoard(int step);
int current_i2,current_j2;
//======================================================================================================
//PRIMARY MAIN FUNCTION
int main(void)
{
srand(time(NULL)) ; //set rand to use time as seed
initialMenu(advGame);
displayMenu(advGame); //display game menu
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);
getch();
}
//======================================================================================================
//create game menu function (initialize)
void initialMenu(GAME advGame[4])
{
strcpy(advGame[0].menu,". NEW GAME");
strcpy(advGame[1].menu,". GUIDELINE");
strcpy(advGame[2].menu,". ABOUT");
strcpy(advGame[3].menu,". EXIT");
}
//======================================================================================================
//display game menu
void displayMenu(GAME advGame[4])
{
cout<<endl<<"================================================================================"<<endl<<" PROGRAM\\t: DIPLOMA IN COMPUTER SCIENCE(CS110)"<<endl;
cout<<" GROUP\\t\\t: CSD2K"<<endl<<" SESSIONS\\t: JULY-NOVEMBER 2010"<<endl<<endl<<endl<<"================================================================================"<<endl;
cout<<" GAME TITLE\\t: SPACE ADVENTURE"<<endl<<" TEAM NAME\\t: Mytho (Legend) " <<endl<<" DESIGNER\\t: @zrI & ZomBiedy "<<endl;
cout<<endl<<endl<<endl<<" GAME MENU:"<<endl;
for(int i=0;i<4;i++)
cout<<endl<<"\\t"<<(i+1)<<advGame[i].menu<<endl;
cout<<endl<<"================================================================================"<<endl;
}
//======================================================================================================
void selectMenu(int no_menu)
{
if(no_menu==1)
newGame();
else if(no_menu==2)
guideline();
else if(no_menu==3)
credit();
else if(no_menu==4)
{ cout<<endl<<" GAME EXIT"<<endl<<endl;
picture();
}
else
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, \'\\n\'); // clear out the bad input from the stream
cerr<<" -> Wrong number entered"<<endl;
system("PAUSE");
displayMenu(advGame); //display game menu
cout<<"\\n Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu); //recursive function
}
}
//======================================================================================================
void newGame()
{
int mode;
system("cls");
cout<<endl<<endl<<endl<<" SELECT M0DE:"<<endl<<endl<<endl<<"\\t1) Single Player\\t[P1]"<<endl<<endl<<"\\t2) Multi Player\\t\\t[P1 VS P2]"<<endl;
cout<<endl<<endl<<" Enter Mode: ";
cin>>mode;
if(mode==1)
{ cout<<endl<<endl<<" SINGLE PLAYER MODE"<<endl;
cout<<" -------------------"<<endl;
cout<<"\\n\\t ENTER NAME (without space): ";
cin>>user[0].P1name;
cout << endl;
system("PAUSE");
S_player();
}
else if(mode==2)
{ cout<<endl<<endl<<" MULTI PLAYER MODE"<<endl;
cout<<endl<<"\\t ENTER NAME (without space): "<<endl;
cout<<endl<<"\\t P1\\t: ";
cin>>user[0].P1name;
cout<<endl<<"\\t P2\\t: ";
cin>>user[0].P2name;
cout << endl<<endl;
system("PAUSE");
M_player();
}
else
{
cout<<" -> Wrong mode entered"<<endl;
system("PAUSE");
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, \'\\n\'); // clear out the bad input from the stream
newGame();
}
}
//======================================================================================================
void guideline()
{
cout << "\\n GAME GUIDELINE:"<<endl;
cout << " ---------------"<<endl;
wait(0.5);
cout << endl<<" SPACE ADVENTURE:"<<endl<<endl<<" 1) Best played when the window are maximised (full screen)." << endl << endl; wait(0.2);
cout << " 2) There are two modes available: Single Player and Multiplayer. Multiplayer"<<endl<<" allows two players to play in the same round of the game, by taking turns." <<endl;wait(0.2);
cout << endl<<" 3) Involves moving around the space grids from START until END using a dice to"<<endl<<" randomise the steps."<<endl<<endl<<" 4) There will be 4 elements: Questions, Portal, Resting Place and Battle."<<endl << endl; wait(0.2);
cout << endl<<" 5) GAME ELEMENT:" <<endl;wait(0.5);
cout << endl<<" i) Questions:"<<endl;wait(0.2);
cout << endl<<" => Various questions will be asked and player(s) must correctly answer the"<<endl<<" questions before continue with the journey."<<endl;wait(0.2);
cout << endl<<" => Questions are accompanied by 4 choices of answer, and player only need"<<endl<<" to enter A, B, C or D." << endl;wait(0.2);
cout << endl<<" => When player answer the question correctly, the game will continue. Else,"<<endl<<" player will ask with different question until player answer correctly."<< endl;wait(0.2);
cout << endl<<" => Player may get same question if player didn\'t answer correctly."<<endl<<" Questions that was answered correctly will not appear again." << endl;wait(0.2);
cout << endl; wait(0.2);
cout << endl<<" ii) Portal:" <<endl;wait(0.2);
cout << endl<<" => Player(s) may encounter portal that will send player(s) back or forth"<<endl<<" randomly using dice number."<<endl;wait(0.2);
cout << endl; wait(0.2);
cout << endl<<" iii) Resting Place:" <<endl;wait(0.2);
cout << endl<<" => This is a place where you can rest a bit and heal some HP." <<endl;wait(0.2);
cout << endl; wait(0.2);
cout << endl<<" iv) Battle:" << endl;wait(0.2);
cout << endl<<" => Player(s) may encounter enemy that trying to stops the player from"<<endl<<" continuing with the journey."<<endl<<endl<<" => You start with 20HP, 20MP. You can attack, use force or heal.Using"<<endl<<" force and heal require MP, so keep your MP in check before using it."<<endl<<endl<<" => Death from battle [HP=0] will result in GAME OVER."<<endl<<endl<<" => Player(s) WIN if enemy [HP=0] and can continue the game."<<endl;wait(0.2);
cout << endl<<endl;
system("PAUSE");
system("cls");
displayMenu(advGame);
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);
}
//======================================================================================================
void credit()
{ cout <<endl<<endl<<" CREDITS:" << endl; wait(0.2);
cout << " --------"<<endl;
cout <<endl<<" Thanks for teachings, supports and suggestions from everyone: Our parents,"; wait(0.1);
cout <<endl<<endl<<" families, Puan Azlina Narawi(Lecturer of CSC 138, our current lecturer),"; wait(0.1);
cout << endl<<endl<<" Miss Adeline Engkamat(Lecturer of CSC 128), Puan Zubaidah Bohari"; wait(0.1);
cout << endl<<endl<<" (Lecturer of CSC118), fellow classmates, and everyone that contributes. " << endl; wait(0.5);
cout << endl<<endl<<endl<<" Credits to:"<<endl<<endl<<" => www.usefultrivia.com"; wait(0.1);
cout << endl<<endl<<" => www.cplusplus.happycodings.com"; wait(0.1);
cout << endl<<endl<<" => http://www.daniweb.com/forums/"; wait(0.1);
cout << endl<<endl<<" => http://www.dreamincode.net/"; wait(0.1);
cout << endl<<endl<<" => http://www.learncpp.com/"; wait(0.1);
cout << endl<<endl<<" => Other resources as references in completing this mini-project." << endl;wait(0.5);
cout << endl<<endl<<endl<<" ABOUT GAME:" << endl; wait(0.2);
cout << " -----------"<<endl;
cout << endl<<" This two (2) dimensional game has been created by 2 UiTM student (Diploma in"; wait(0.1);
cout << endl<<endl<<" Computer Science) named; Muhammad Azri bin Jasni (@zrI) and his friend,"; wait(0.1);
cout << endl<<endl<<" Mohd Zabiedy bin Mohd Sulaiman (ZomBiedy)."; wait(0.1);
cout << endl<<endl<<endl<<" The game has been done as an mini-project for CSC 138 - Structured Programming"; wait(0.1);
cout << endl<<endl<<" during Semester July - September 2010. One of the objective of this"; wait(0.1);
cout << endl<<endl<<" assignment is to determine whether computer science (part 2) understand the"; wait(0.1);
cout << endl<<endl<<" concept of Structured Programming,its component and also know how is applying"; wait(0.1);
cout << endl<<endl<<" them focused on multiple dimension array in C++." << endl; wait(0.2);
cout << endl<<endl;
system("PAUSE");
system("cls");
displayMenu(advGame);
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);
}
//======================================================================================================
void S_player()
{
system("cls");
GameStart(1);
displayMenu(advGame);
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);
}
//======================================================================================================
void M_player()
{
system("cls");
GameStart(2);
system("cls");
displayMenu(advGame);
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);
}
//======================================================================================================
//starting of game
void GameStart(int player)
{
int no_menu,turn;
intBoard();
intgame_element();
initializeQuestion ();
system("cls");
cout<<endl<<" GAME START !!!...GOOD LUCK"<<endl; //initialize board
displayBoard();
if (player==2)
{
turn=1;
current_i2=0,current_j2=0;
while (strcmp(world.board[row-1][col-1]," P 1 ")!=0||strcmp(world.board[row-1][col-1]," P 2 ")!=0)
{
if (turn==1)
{
goto labelsingle;
}
else if (turn ==2)
{
cout<<endl<<" PLAYER 2: "<<user[0].P2name<<endl;
cout<<endl<<" Press any key to roll the dice...";
getch(); //display board
step=dice(); //get dice value and save as step
system("cls");
slowstepsBoard2(step);
cout<<endl<<" Your dice value: "<<step<<endl;
switch (world.game_element[current_i2][current_j2])
{
case 1:
cout<<endl<<" RESTING PLACE:"<<endl;
rest(turn);
break;
case 2:
cout<<endl<<" QUESTION:"<<endl;
question();
break;
case 3:
cout<<endl<<" PORTAL:"<<endl;
portal(turn);
break;
case 4:
cout<<endl<<" BATTLE:"<<endl;
battle(turn);
world.board[(current_i2)][(current_j2)]=" P 2 ";
cout << endl;
break;
}
world.board[current_i][current_j]=" P 1 ";
world.board[current_i2][current_j2]=" P 2 ";
}
labelreturn:
if (strcmp(world.board[row-1][col-1]," P 1 ")==0)
{ break;}
else if (strcmp(world.board[row-1][col-1]," P 2 ")==0)
{ break;}
//turn change
if (turn==1)
turn =2;
else if (turn==2)
turn=1;
}
}
else
{
turn = 0;
while(strcmp(world.board[8][7]," P 1 ")!=0)
{
labelsingle:
cout<<endl<<" PLAYER 1: "<<user[0].P1name<<endl;
cout<<endl<<" Press any key to roll the dice...";
getch(); //display board
step=dice(); //get dice value and save as step
system("cls");
slowstepsBoard(step); //move P1 on board according to the step
//display dice value
cout<<endl<<" Your dice value: "<<step<<endl;
switch (world.game_element[current_i][current_j])
{
case 1:
cout<<endl<<" RESTING PLACE:"<<endl;
rest(turn);
break;
case 2:
cout<<endl<<" QUESTION:"<<endl;
question();
break;
case 3:
cout<<endl<<" PORTAL:"<<endl;
portal(turn);
break;
case 4:
cout<<endl<<" BATTLE:"<<endl;
battle(turn);
world.board[(current_i)][(current_j)]=" P 1 ";
if((player==2))
world.board[current_i2][current_j2]=" P 2 ";
cout << endl;
displayBoard();
break;
}//switch
if(turn == 1) {goto labelreturn;}
}//while
}//else
win(turn);
if(turn==2)
cout<<endl<<endl<<" CONGRATULATION !!!.."<<user[0].P2name<<" Finish The Game...\\n See You Again..Thank You."<<endl<<"\\n <= Back to Game Menu "<<endl;
else if(turn==1)
cout<<endl<<endl<<" CONGRATULATION !!!.."<<user[0].P1name<<" Finish The Game...\\n See You Again..Thank You."<<endl<<"\\n <= Back to Game Menu "<<endl;
cout<<endl;
system("PAUSE");
system("cls");
main();
/*
displayMenu(advGame);
cout<<" Enter Number: "; //choose menu
cin>>no_menu;
system("cls");
selectMenu(no_menu);*/
}
//======================================================================================================
//dice function
int dice(void)
{
return rand() % 6 + 1;
}
//======================================================================================================
//initialize board
void intBoard(void)
{
for(i=0;i<row;i++)
for(j=0;j<col;j++)
world.board[i][j]=" ";
world.board[0][0]=" START ";
world.board[row-1][col-1]=" END ";
current_i=0; current_j=0;
if (player==2)
current_i2=0; current_j2=0;
}
//======================================================================================================
//initialize game_element
void intgame_element(void)
{
for (i=0;i<row;i++)
for (j=0;j<col;j++)
{
int countLimitBattle=0;
int countLimitRest=0;
world.game_element[i][j]=rand() % 4 + 1;
label4:
if (world.game_element[i][j]==1)
{
if (countLimitRest==LimitRest)
{
world.game_element[i][j]=rand() % 4 + 1;
goto label4;
}
else
countLimitRest++;
}
label3:
if (world.game_element[i][j]==4)
{
if (countLimitBattle==LimitBattle)
{
world.game_element[i][j]=rand() % 4 + 1;
goto label3;
}
else
countLimitBattle++;
}
}
world.game_element[row-1][col-1]=0; world.game_element[0][0]=0;
}
//======================================================================================================
//show game board
void displayBoard(void)
{
world.board[0][0]=" START ";
wait(0.2);
for(i=0;i<row;i++)
{ cout<<endl;
for(j=0;j<(col);j++)
cout<<"========";
cout<<endl<<\'|\';
if (i%2==1)
for(j=(col-1);j>=0;j--)
cout<<world.board[i][j]<<\'|\';
else
for(j=0;j<col;j++)
cout<<world.board[i][j]<<\'|\';
}
cout<<endl;
for(j=0;j<(col);j++)
cout<<"========";
cout<<endl;
}
//======================================================================================================
//stepping around board-slow motion
void slowstepsBoard(int step)
{
//new code
for (int count=0;count<=step;count++,current_j++)
{
if(player==2)
{world.board[current_i2][current_j2]=" P 2 ";}
system("cls");
if (current_i==row||(current_i==row&¤t_j==col))//when reach destination or over it, assign to
{
world.board[current_i][current_j]=" ";
world.board[8][7]=" P 1 "; //last destination and break out of loop
displayBoard();
break;
}
if (current_j>=col)
{
current_j=current_j-col;
current_i++;
}
world.board[current_i][current_j]=" P 1 ";
displayBoard();
wait(0.15);
world.board[current_i][current_j]=" ";
}//for
current_j--;
}
//======================================================================================================
//to slow down the display of the board
void wait(float seconds)
{
//error converting clock_t from float
//error didn\'t seems to affect gameplay
clock_t endwait;
endwait=clock()+seconds*CLOCKS_PER_SEC;
while(clock()<endwait){} // jarak antara nombor yang akan dipaparkan
}
//======================================================================================================
//resting function
void rest(int turn)
{
//random comments in resting place element
int randRest = (rand() % 4 + 1);
switch (randRest)
{
case 1:
cout << " => You found a space cafe and decided to have a popular\\n Universe Water before proceed with your adventure."<<endl;
break;
case 2:
cout << " => You gazes at the beautiful starry scene in front of you\\n before continuing your journey." <<endl;
break;
case 3:
cout << " => You land on space rock to repair your space ship." <<endl;
break;
case 4:
cout << " => You stop for a while to take space picture." <<endl;
break;
}
if (turn==2)
{
hp2+=10; //resting increase hp
if (hp2>100)
hp2=100;
cout << "\\n --------------------------"<< endl;
cout << " Increase HP by 10.\\n Current HP2 : " << hp2 << endl;
cout << " --------------------------"<< endl;
}//if
else if (turn==1||turn==0)
{
hp+=10; //resting increase hp
if (hp>100)
hp=100;
cout << "\\n --------------------------"<< endl;
cout << " Increase HP by 10.\\n Current HP : " << hp << endl;
cout << " --------------------------"<< endl;
}//else
}
//======================================================================================================
//portal function
void portal(int turn)
{
cout << " => You get sucked in into a WORMHOLE.\\n It sends you somewhere around the universe." << endl;
int polarity=(rand() % 2 + 1);
if (polarity==2)
step=dice();
else
step=(-1)*dice();
cout <<endl<<endl;
system("PAUSE");
system("cls");
if (turn==2)
{
world.board[(current_i2)][(current_j2)]=" ";
current_j2=current_j2+step;
if (current_j2>=col)
{
current_j2=current_j2-col;
current_i2++;
}
world.board[(current_i2)][(current_j2)]=" P 2 ";
}
else
{
world.board[(current_i)][(current_j)]=" ";
current_j=current_j+step;
if (current_j>=col)
{
current_j=current_j-col;
current_i++;
}
world.board[(current_i)][(current_j)]=" P 1 ";
}
cout<<" After sucked: "<<endl;
displayBoard();
}
//======================================================================================================
//battle mode = battle()+win()+lose()
int battle(int turn)
{
if (turn==2)
{hp2+=1; //for first battle, hp will be 20. every next battle, hp increase by 1 simulating hp regeneration
ehp=30;
labelbattle2:
mp2++; //mp regeneration
cout << "\\n -----------------------------------------------------" << endl;
cout << " ENEMY HP\\t: "<<setw(5)<<setiosflags(ios::right)<< ehp << "\\t\\t(1) Attack"<<endl<< " "<<user[0].P2name<<" HP\\t: "
<<setw(5)<<setiosflags(ios::right)<< hp2 << "\\t\\t(2) Use Force[10MP2]" << endl<< " "<<user[0].P2name<<" MP\\t: " <<setw(5)<<setiosflags(ios::right)<< mp2 << "\\t\\t(3) Heal[2MP2]"<< endl;
cout << " -----------------------------------------------------\\n Enter Number: ";
cin >> move;
system("cls");
if (move>=1&&move<=3)
{ cout << "\\n STATUS: " << endl; wait(0.2);
switch (move)
{
case 1:
if ((rand() % 3 + 1)==1)
{cout<<"\\n -> You PUNCHED your enemy on his face . [ehp-1]"<<endl; ehp-=1;}
else if ((rand() % 3 + 1)==2)
{cout<<"\\n -> You shot him from distance using RIFLE. [ehp-2]"<<endl; ehp-=2;}
else
{cout<<"\\n -> You sliced him with your DRAGON SWORD. [ehp-3]"<<endl; ehp-=3;}
break;
case 2:
if (mp2>=10)
{
int a=(rand() % 5 + 1);
cout<<"\\n -> You used your force and pushed him back, hurting\\n him in the process. [ehp-"<<a<<",mp2-10]"<<endl;
ehp-=a;
mp2-=10;
}
else
{
cout<<"\\n -> You don\'t have enough MP to use your force ability."<<endl;
}
break;
case 3:
if (mp2>=2)
{
cout<<"\\n -> You patched yourself quickly in the midst of battle.[hp2+4,mp2-2]"<<endl;
hp2+=4;
mp2-=2;
if (hp2>100)
hp2=100;
}
else
{
cout<<"\\n -> You don\'t have enough MP to heal yourself."<<endl;
}
}//switch(move)
wait(0.2);
if (ehp<=0)
{
win(turn);
return 1;
}
else
{
emove=(rand() % 3 + 1);
wait(0.2);
if (emove==1)
{ cout << "\\n -> The enemy shot you using his LASER RIFLE. [hp2-1]" << endl; hp2-=1;}
else if (emove==2)
{ cout << "\\n -> The enemy charged at you and pushed you onto the space rock.[hp2-2]" <<endl; hp2-=2;}
else if (emove==3)
{ cout << "\\n -> The enemy HEALED himself. [ehp+2]"<<endl; ehp+=2;}
wait(0.2);
}
if (hp2<=0)
{ lose(turn);
return 0;}
}//if (1<move<3)
else
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, \'\\n\'); // clear out the bad input from the stream
move=0;
cerr<<" -> Wrong input. Enter 1,2 or 3 only"<<endl;
wait(0.2);
system("PAUSE");cout<<endl;
system("cls");}
goto labelbattle2;
}//if
else
{
hp+=1; //for first battle, hp will be 20. every next battle, hp increase by 1 simulating hp regeneration
ehp=30;
label:
mp++; //mp regeneration
cout << "\\n -----------------------------------------------------" << endl;
cout << " ENEMY HP\\t: "<<setw(5)<<setiosflags(ios::right)<< ehp << "\\t\\t(1) Attack"<<endl<< " "<<user[0].P1name<<" HP\\t: "
<<setw(5)<<setiosflags(ios::right)<< hp << "\\t\\t(2) Use Force[10MP1]" << endl<< " "<<user[0].P1name<<" MP\\t: " <<setw(5)<<setiosflags(ios::right)<< mp << "\\t\\t(3) Heal[2MP1]"<< endl;
cout << " -----------------------------------------------------\\n Enter Number: ";
cin >> move;
system("cls");
if (move>=1&&move<=3)
{ cout << "\\n STATUS: "<< endl; wait(0.2);
switch (move)
{
case 1:
if ((rand() % 3 + 1)==1)
{cout<<"\\n -> You PUNCHED your enemy on his face . [ehp-1]"<<endl; ehp-=1;}
else if ((rand() % 3 + 1)==2)
{cout<<"\\n -> You shot him from distance using RIFLE. [ehp-2]"<<endl; ehp-=2;}
else
{cout<<"\\n -> You sliced him with your DRAGON SWORD. [ehp-3]"<<endl; ehp-=3;}
break;
case 2:
if (mp>=10)
{
int a=(rand() % 5 + 1);
cout<<"\\n -> You used your force and pushed him back,hurting\\n him in the process.[ehp-"<<a<<",mp-10]"<<endl;
ehp-=a;
mp-=10;
}
else
{
cout<<"\\n -> You don\'t have enough MP to use your force ability."<<endl;
}
break;
case 3:
if (mp>=2)
{
cout<<"\\n -> You patched yourself quickly in the midst of battle.[hp+4,mp-2]"<<endl;
hp+=4;
mp-=2;
if (hp>100)
hp=100;
}
else
cout<<"\\n -> You don\'t have enough MP to heal yourself."<<endl;
}//switch(move)
wait(0.2);
if (ehp<=0)
{ win(turn); return 1;}
else
{
emove=(rand() % 3 + 1);
wait(0.2);
if (emove==1)
{ cout << "\\n -> The enemy shot you using his LASER RIFLE.[hp-1]" << endl; hp-=1;}
else if (emove==2)
{ cout << "\\n -> The enemy charged at you and pushed you onto the space rock.[hp-2]" <<endl; hp-=2;}
else if (emove==3)
{ cout << "\\n -> The enemy HEALED himself. [ehp+2]"<<endl; ehp+=2;}
wait(0.2);
}
if (hp<=0)
{ lose(turn);
return 0;}
}//if (1<move<3
else
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, \'\\n\'); // clear out the bad input from the stream
move=0;
cerr<<" -> Wrong input. Enter 1,2 or 3."<<endl;
wait(0.2);
system("PAUSE");cout<<endl;
system("cls");}
goto label;
}//else
}
//======================================================================================================
//win()
void win(int turn)
{
if (player==2)
{
switch (turn)
{
case 1:
cout<<endl<<"\\n "<<user[0].P1name<<" WIN!" << endl; break;
case 2:
cout<<endl<<"\\n "<<user[0].P2name<<" WIN!" << endl; break;
}
}
else
cout<<endl<<"\\n "<<user[0].P1name<<" WIN!" << endl; //winner by name displayed
cout << endl;
system("PAUSE");
system("cls");
}
//======================================================================================================
//lose()
void lose(int turn)
{
cout<<endl<<"\\n GAME OVER" << endl;
if (player==2)
{
switch(turn)
{ case 2:
cout<<"\\n "<<user[0].P1name<<" Win, "<<user[0].P2name<<" Lose";break; //cout<<"PLAYER 1 Win, PLAYER 2 Lose"; break;
case 1:
cout<<"\\n "<<user[0].P2name<<" Win, "<<user[0].P1name<<" Lose";break; //cout<<"PLAYER 2 Win, PLAYER 1 Lose"; break;
}
}
cout << endl;
system("PAUSE");
system("cls");
main();
}
//======================================================================================================
//question functions-question(),initializeQuestion(),initializeStatus()
int question (void)
{
while(1)
{
//label2:
int randomQuestion=( (rand()) % size_question); //randomize the questions
if (questions[randomQuestion].status==1)
continue;//goto label2;
char answer;
cout<<questions[randomQuestion].q<<endl;
cout<<"\\n Your answer: ";
cin>>answer;
answer=toupper(answer);
if (answer == questions[randomQuestion].ans)//...
{ cout<<endl<<" -> That\'s correct!"<<endl; questions[randomQuestion].status=1;
return 1;
}
else
cout<<endl<<" -> That\'s wrong..."<<endl;
system("Pause");
system("cls");}
//goto label2;
}
//=================================================
//list of questions
void initializeQuestion (void)
{
questions[0].q="\\n There are many theories about the birth of our solar system. Which theory\\n involves a passing star pulling dust and debris from the forming sun?\\n\\tA: Nebular Hypothesis\\n\\tB: Tidal Theory\\n\\tC: Collision Theory\\n\\tD: Protoplanet Hypothesis";
questions[0].ans=\'B\';
questions[1].q="\\n The planets make up what percentage of the mass in our solar system?\\n\\tA: 0.0135 %\\n\\tB: 0.135 %\\n\\tC: 1.35 %\\n\\tD: 13.5 %";
questions[1].ans=\'B\';
questions[2].q="\\n What are the only two planets in our solar system without moons?\\n\\tA: Mercury & Venus\\n\\tB: Venus & Mars\\n\\tC: Uranus & Neptune\\n\\tD: Neptune & Pluto";
questions[2].ans=\'A\';
questions[3].q="\\n What is the name of Pluto\'s moon?\\n\\tA: Charon\\n\\tB: Phobus\\n\\tC: Pandora\\n\\tD: Nereid";
questions[3].ans=\'A\';
questions[4].q="\\n The three main parts of a comet are the nucleus, the tail, and the _____?\\n\\tA: Zenith\\n\\tB: Umbra\\n\\tC: Radiant\\n\\tD: Coma";
questions[4].ans=\'D\';
questions[5].q="\\n What year boasted the first woman in space?\\n\\tA: 1963\\n\\tB: 1968\\n\\tC: 1973\\n\\tD: 1983";
questions[5].ans=\'A\';
questions[6].q="\\n What is the term for the condition when three celestial bodies are arranged\\n in a straight line?\\n\\tA: Occultation\\n\\tB: Parallax\\n\\tC: Syzygy\\n\\tD: Triple Transit";
questions[6].ans=\'C\';
questions[7].q="\\n Which of the following was discovered in 2002?\\n\\tA: Nereid\\n\\tB: Varuna\\n\\tC: Titan\\n\\tD: Quaoar";
questions[7].ans=\'D\';
questions[8].q="\\n What manned U.S. space program eventually put 12 men on the Moon?\\n\\tA: Apollo\\n\\tB: Gemini\\n\\tC: Mercury\\n\\tD: Voyager";
questions[8].ans=\'A\';
questions[9].q="\\n From 1978 to 1999, which planet was farthest from the Sun?\\n\\tA: Pluto\\n\\tB: Neptune\\n\\tC: Uranus\\n\\tD: Saturn";
questions[9].ans=\'B\';
questions[10].q="\\n What was the very first personal computer?\\n\\tA: TRS-80\\n\\tB: Commodore PET\\n\\tC: Kenbak-1\\n\\tD: Apple I";
questions[10].ans=\'C\';
questions[11].q="\\n What year was the word \\"computer\\" first used to describe\\n a mechanical calculating device?\\n\\tA: 1897\\n\\tB: 1912\\n\\tC: 1926\\n\\tD: 1942";
questions[11].ans=\'A\';
questions[12].q="\\n What was the first portable computer?\\n\\tA: Epson HX-20\\n\\tB: Cray I\\n\\tC: Osborne I\\n\\tD: IBM 5155";
questions[12].ans=\'C\';
questions[13].q="\\n During the 1970s computer engineers at various research institutions\\n began to utilize telecommunications technologies to link their computers\\n together. This effort, the forefather of the modern Internet, was known as the ...\\n\\tA: INSTANET\\n\\tB: ARPANET\\n\\tC: ORDONET\\n\\tD: BAYONET";
questions[13].ans=\'B\';
questions[14].q="\\n What was the first computer to defeat a world champion chess player?\\n\\tA: Chinook\\n\\tB: X3D Fritz\\n\\tC: Deep Blue\\n\\tD: A.L.I.C.E.";
questions[14].ans=\'C\';
questions[15].q="\\n What computer device did Douglas Engelbart invent in 1963?\\n\\tA: Modem\\n\\tB: Mouse\\n\\tC: Floppy disk\\n\\tD: Microchip";
questions[15].ans=\'B\';
questions[16].q="\\n What \\"law\\" describes the fact that, on average, computers\\n doubled in capacity every 18 to 24 months since 1900?\\n\\tA: Anderson\'s Law\\n\\tB: Moore\'s Law\\n\\tC: Jefferson\'s Law\\n\\tD: Bohr\'s Law";
questions[16].ans=\'B\';
questions[17].q="\\n How many lines of code did the Windows 98 operating system contain?\\n\\tA: 4 million\\n\\tB: 9 million\\n\\tC: 18 million\\n\\tD: 40 million";
questions[17].ans=\'C\';
questions[18].q="\\n What was the first commercially successful vector processor?\\n\\tA: Cray I\\n\\tB: HP-2115\\n\\tC: Altair 8800\\n\\tD: Apple I";
questions[18].ans=\'A\';
questions[19].q="\\n What new product did Apple Computer launch with a $1.5 million\\n commercial during the 1984 Super Bowl?\\n\\tA: Apple I\\n\\tB: Apple IIe\\n\\tC: Apple IIc\\n\\tD: Macintosh";
questions[19].ans=\'D\';
questions[20].q="\\n Mt. Fuji is the highest point in what Asian country?\\n\\tA: Bangladesh\\n\\tB: Burma\\n\\tC: China\\n\\tD: Japan";
questions[20].ans=\'D\';
questions[21].q="\\n What is western Asia\'s longest river?\\n\\tA: Tigris\\n\\tB: Euphrates\\n\\tC: Xi Jiang\\n\\tD: Kurobe";
questions[21].ans=\'B\';
questions[22].q="\\n What tiny country, known to its inhabitants as Druk Yul(Land of\\n the Thunder Dragon), is sandwiched between China and India?\\n\\tA: Bhutan\\n\\tB: Bangladesh\\n\\tC: Mongolia\\n\\tD: Burma";
questions[22].ans=\'A\';
questions[23].q="\\n What mountain range runs along the northern border of India?\\n\\tA: Urul Mountains\\n\\tB: Tatra Mountains\\n\\tC: Xiao Hinggan Ling Mountains\\n\\tD: Himalayan Mountains";
questions[23].ans=\'D\';
questions[24].q="\\n Korea is separated from Japan by what strait?\\n\\tA: Cheju\\n\\tB: Tsushima\\n\\tC: Gibraltar\\n\\tD: Bungo";
questions[24].ans=\'B\';
questions[25].q="\\n What Chinese city is situated at the mouth of the Chang Jiang (Yangtze) River?\\n\\tA: Shanghai\\n\\tB: Beijing\\n\\tC: Taipei\\n\\tD: Changchun";
questions[25].ans=\'A\';
questions[26].q="\\n What is the tallest mountain in Asia?\\n\\tA: Qogir\\n\\tB: Kangchenjunga\\n\\tC: Cho Oyu\\n\\tD: Mount Everest";
questions[26].ans=\'D\';
questions[27].q="\\n Iran is slightly larger than what U.S. state?\\n\\tA: Rhode Island\\n\\tB: Montana\\n\\tC: Texas\\n\\tD: Alaska";
questions[27].ans=\'D\';
questions[28].q="\\n What Japanese city is the site of the Peace Memorial Park\\n and the eternal Peace Flame which is never to be extinguished\\n until all nuclear weapons are dismantled?\\n\\tA: Hiroshima\\n\\tB: Nagasaki\\n\\tC: Tokyo\\n\\tD: Kyoto";
questions[28].ans=\'A\';
questions[29].q="\\n What is the capital of Afghanistan?\\n\\tA: Teheran\\n\\tB: Kandahar\\n\\tC: Baghdad\\n\\tD: Kabul";
questions[29].ans=\'D\';
questions[30].q="\\n When was the idea of the atom first introduced?\\n\\tA: 450 B.C.\\n\\tB: 1050\\n\\tC: 1791\\n\\tD: 1942";
questions[30].ans=\'A\';
questions[31].q="\\n In 2004, what was discovered on the island of Flores\\n in Indonesia?\\n\\tA: A living dinosaur\\n\\tB: Remains of a hobbit-sized human species\\n\\tC: A tribe whose members commonly live over 150 years\\n\\tD: A plant with a mammal-like brain";
questions[31].ans=\'B\';
questions[32].q="\\n An earthquake that measures 8 on the Richter Scale would\\n be how many times stronger than an earthquake that\\n measures 4 on the same scale?\\n\\tA: 2 times stronger\\n\\tB: 4 times stronger\\n\\tC: 1000 times stronger\\n\\tD: 10,000 times stronger";
questions[32].ans=\'D\';
questions[33].q="\\n What is the gestation period of an Hippopotamus?\\n\\tA: 4 months\\n\\tB: 8 months\\n\\tC: 12 months\\n\\tD: 16 months";
questions[33].ans=\'B\';
questions[34].q="\\n What physicist discovered that a wave\'s frequency changes\\n when the source and the observer are in motion relative\\n to one another?\\n\\tA: Max Planck\\n\\tB: Christian Doppler\\n\\tC: Enrico Fermi\\n\\tD: Albert Einstein";
questions[34].ans=\'B\';
questions[35].q="\\n In what type of matter are atoms most tightly packed?\\n\\tA: Solids\\n\\tB: Liquids\\n\\tC: Gases\\n\\tD: All are the same";
questions[35].ans=\'A\';
questions[36].q="\\n Which of the following means \\"rain\\" when added to\\n a cloud\'s name?\\n\\tA: Alto\\n\\tB: Nimbus\\n\\tC: Strato\\n\\tD: Cirrus";
questions[36].ans=\'B\';
questions[37].q="\\n What is the longest river in the world?\\n\\tA: Amazon\\n\\tB: Nile\\n\\tC: Congo\\n\\tD: Chang Jiang";
questions[37].ans=\'B\';
questions[38].q="\\n How many brains did a Stegosaurus have?\\n\\tA: One\\n\\tB: Two\\n\\tC: Three\\n\\tD: None";
questions[38].ans=\'A\';
questions[39].q="\\n What instrument is used to measure wind speed?\\n\\tA: Anemometer\\n\\tB: Barometer\\n\\tC: Altimeter\\n\\tD: Fanometer";
questions[39].ans=\'A\';
questions[40].q="\\n What is Earth\'s largest continent?\\n\\tA: Asia\\n\\tB: Africa\\n\\tC: Europe\\n\\tD: Antarctica";
questions[40].ans=\'A\';
questions[41].q="\\n What razor-thin country accounts for more than half of the western coastline of South America?\\n\\tA: Ecuador\\n\\tB: Chile\\n\\tC: Peru\\n\\tD: Bolivia";
questions[41].ans=\'B\';
questions[42].q="\\n What river runs through Baghdad?\\n\\tA: Tigris\\n\\tB: Euphrates\\n\\tC: Karun\\n\\tD: Jordan";
questions[42].ans=\'C\';
questions[43].q="\\n What country is home to Kangaroo Island?\\n\\tA: Australia\\n\\tB: France\\n\\tC: Japan\\n\\tD: Great Britain";
questions[43].ans=\'A\';
questions[44].q="\\n What continent is located at Latitude 90° S Longitude 0.00° E?\\n\\tA: South America\\n\\tB: Asia\\n\\tC: Australia\\n\\tD: Antarctica";
questions[44].ans=\'A\';
questions[45].q="\\n What is the largest country in South America?\\n\\tA: Columbia\\n\\tB: Argentina\\n\\tC: Brazil\\n\\tD: Peru";
questions[45].ans=\'C\';
questions[46].q="\\n What is the tallest mountain in the world?\\n\\tA: Aconcagua\\n\\tB: Qogir\\n\\tC: Mount Kilimanjaro\\n\\tD: Mount Everest";
questions[46].ans=\'D\';
questions[47].q="\\n What city is the capital of Australia?\\n\\tA: Perth\\n\\tB: Melbourne\\n\\tC: Sydney\\n\\tD: Canberra";
questions[47].ans=\'D\';
questions[48].q="\\n Riyadh is the capital of what Middle-Eastern country?\\n\\tA: Iraq\\n\\tB: Syria\\n\\tC: Saudi Arabia\\n\\tD: Yemen";
questions[48].ans=\'C\';
questions[49].q="\\n Which of these African nations is NOT landlocked?\\n\\tA: Niger\\n\\tB: Congo\\n\\tC: Chad\\n\\tD: Burkina Faso";
questions[49].ans=\'B\';
questions[50].q="\\n What is the earliest surviving system of laws?\\n\\tA: Rosetta Stone\\n\\tB: Code of Hammurabi\\n\\tC: Hebrew Torah\\n\\tD: Shabaka Stone";
questions[50].ans=\'B\';
questions[51].q="\\n What type of gun did John Wilkes Booth use to assassinate U.S. President Abraham Lincoln?\\n\\tA: Derringer Pistol\\n\\tB: Colt Peacemaker\\n\\tC: Smith & Wesson Revolver\\n\\tD: Winchester Rifle";
questions[51].ans=\'A\';
questions[52].q="\\n What was the last battle of the Napoleonic Wars?\\n\\tA: Battle of Trafalgar\\n\\tB: Battle of the Nile\\n\\tC: Battle of Wavre\\n\\tD: Battle of Waterloo";
questions[52].ans=\'C\';
questions[53].q="\\n The world\'s first postage stamp was introduced in what year?\\n\\tA: 1690\\n\\tB: 1760\\n\\tC: 1840\\n\\tD: 1910";
questions[53].ans=\'C\';
questions[54].q="\\n Who was the first democratically elected President of Russia?\\n\\tA: Mikhail Gorbachev\\n\\tB: Boris Yeltsin\\n\\tC: Vladimir Putin\\n\\tD: Nikita Khrushchev";
questions[54].ans=\'B\';
questions[55].q="\\n Which of the following inventions was the first to be patented?\\n\\tA: Chewing Gum\\n\\tB: Dishwasher\\n\\tC: Cash Register\\n\\tD: Rubber Band";
questions[55].ans=\'A\';
questions[56].q="\\n When the first Burger King Restaurant opened in 1954, how much did a hamburger cost?\\n\\tA: 9 cents\\n\\tB: 18 cents\\n\\tC: 37 cents\\n\\tD: 50 cents";
questions[56].ans=\'B\';
questions[57].q="\\n What was the first city to reach a population of one million?\\n\\tA: Rome\\n\\tB: London\\n\\tC: New York\\n\\tD: Beijing";
questions[57].ans=\'A\';
questions[58].q="\\n How long did the Hundred Years\' War last?\\n\\tA: 86 years\\n\\tB: 99 years\\n\\tC: 100 years\\n\\tD: 116 years";
questions[58].ans=\'D\';
questions[59].q="\\n Who was the first Prime Minister of the United Kingdom?\\n\\tA: Henry Pelham\\n\\tB: Robert Walpole\\n\\tC: George Grenville\\n\\tD: Winston Churchill";
questions[59].ans=\'B\';
questions[60].q="\\n What European country consists of a boot-shaped peninsula surrounded by four seas?\\n\\tA: Norway\\n\\tB: Sweden\\n\\tC: Italy\\n\\tD: Greece";
questions[60].ans=\'C\';
questions[61].q="\\n What country is geographically separated from continental Europe by the Pyrenees mountains?\\n\\tA: Spain\\n\\tB: France\\n\\tC: Italy\\n\\tD: Croatia";
questions[61].ans=\'A\';
questions[62].q="\\n What is Europe\'s longest river?\\n\\tA: Rhine\\n\\tB: Loire\\n\\tC: Volga\\n\\tD: Thames";
questions[62].ans=\'C\';
questions[63].q="\\n What European country is bordered by Slovakia, Ukraine, Romania, Serbia, Croatia, Slovenia, and Austria?\\n\\tA: Bulgaria\\n\\tB: Hungary\\n\\tC: Russia\\n\\tD: France";
questions[63].ans=\'B\';
questions[64].q="\\n Germany is divided into how many states?\\n\\tA: 8\\n\\tB: 16\\n\\tC: 24\\n\\tD: 32";
questions[64].ans=\'B\';
questions[65].q="\\n Poland is situated on the southern end of what sea?\\n\\tA: Aegean Sea\\n\\tB: Black Sea\\n\\tC: Baltic Sea\\n\\tD: Norwegian Sea";
questions[65].ans=\'C\';
questions[66].q="\\n What river begins in the Black Forest region of Germany, flows across central Europe and the countries of Austria, Hungary, Croatia, and Yugoslavia, and empties into the Black Sea?\\n\\tA: Seine\\n\\tB: Danube\\n\\tC: Oder\\n\\tD: Elbe";
questions[66].ans=\'B\';
questions[67].q="\\n What is the capital of Lithuania?\\n\\tA: Valmiera\\n\\tB: Taurage\\n\\tC: Vilnius\\n\\tD: Riga";
questions[67].ans=\'C\';
questions[68].q="\\n What is the tallest mountain in Europe?\\n\\tA: Mount Corno\\n\\tB: Mount Elbrus\\n\\tC: Mount Olympus\\n\\tD: Mount Blanc";
questions[68].ans=\'B\';
questions[69].q="\\n What is the highest inhabited country in Europe?\\n\\tA: Andorra\\n\\tB: Liechtenstein\\n\\tC: Croatia, D: Switzerland";
questions[69].ans=\'A\';
initializeStatus ();
}
void initializeStatus (void)
{
for ( i=0; i<size_question; i++)
questions[i].status=0;
}
//======================================================================================================
//stepping around board player 2
void slowstepsBoard2(int step)
{
//new code
world.board[current_i2][current_j2]=" ";
for (int count=0;count<=step;count++,current_j2++)
{
system("cls");
if (current_i2==row||(current_i2==row&¤t_j2==col))//when reach destination or over it, assign to
{
world.board[current_i2][current_j2]=" ";
world.board[8][7]=" P 2 "; //last destination and break out of loop
world.board[current_i][current_j]=" P 1 ";
displayBoard();
break;
}
if (current_j2>=col)
{
current_j2=current_j2-col;
current_i2++;
}
world.board[current_i2][current_j2]=" P 2 ";
world.board[current_i][current_j]=" P 1 ";
displayBoard();
world.board[current_i2][current_j2]=" ";
wait(0.2);
}//for
current_j2--;
}
//======================================================================================================
void picture()
{
cout<<"\\t ________ _______"<<endl<<"\\t| | / |"<<endl<<"\\t| ###### | / ###### /"<<endl;
cout<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | / ###### /"<<endl;
cout<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | / ###### /"<<endl;
cout<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | / ###### /"<<endl<<"\\t| ###### | ##### ----- ----"<<endl;
cout<<"\\t| ###### | ####### / #####| | ####|"<<endl<<"\\t| ###### | ###### / #####| | #####|"<<endl;
cout<<"\\t| ###### | ###### / ######| | #####|"<<endl<<"\\t| ###### | #### / ###### // ##### /"<<endl;
cout<<"\\t| ###### | #### | ###### // ##### /"<<endl<<"\\t| ###### | ## \\\\ ##### // ##### /"<<endl;
cout<<"\\t| ____________________ #### /"<<endl<<"\\t|/ ,,,,,,,,,,,,,,,, \\\\;...; /"<<endl;
cout<<"\\t| ##############:\'\'\':| ----"<<endl<<"\\t| ##############: :| !!!!!!!!!!!!!!!! !!!!!!!!"<<endl;
cout<<"\\t| ##############:...:| !!!!!!!!!!!!!!!! !!!!!!!!!!"<<endl<<"\\t ;====================/ !!! !; !!! !!!"<<endl;
cout<<"\\t|| +++++++++++++++++++++++ || !!! !; !!! !!!"<<endl<<"\\t|| ##################### ||| !!! !; !!! !!!"<<endl;
cout<<"\\t|| ******************* /// !!! !; !!! !!!"<<endl<<"\\t|| || !!! !; !!! !!!"<<endl;
cout<<"\\t|| ||; !!! !; !!! ;;.!!!"<<endl<<"\\t\\t\\t\\t\\t !!! !; !!!!!!!!!!"<<endl;
cout<<"\\t\\t\\t\\t\\t \\"\\"\\"\\"\\"\\" !!!!!!\\"!!!"<<endl<<"\\t\\t\\t\\t\\t\\t\\t !!\'"<<endl;
}