//conkers game: graphical version - uses ascii graphics.
//-------------------------------------------
//extensions on previous: removed the text based interface, and replaced it with an ascii graphics interface. you control the blue
//face, which can be moved with the w,a,s,d keys. run your character into the red faces to chalenge them to a game of conkers
//to extend the players ( player[10] ) living time, king_of starts at 10, and HL is set to 30 and the enemies(player[0-9])
//king_of is random between 1-10, but the HL is still 4.
//green enemies have a king_of of 5 or more lower than the players king_of. 5 or more higher and they are red, anything inbetween
//is yellow. 
//--------------------
//Ian Copland 06/03/07

//header files...
#include <iostream>
using namespace std;
#include <ctime>
#include <stack>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>

//declare functions...
void add_to_history(int,int,int);
void display_history(int);
void set_screen_pos(int,int);
void player_battle(int,int &,int);
int get_enemy_colour(int,int);

//define constants...
#define GRID_WIDTH  35
#define GRID_HEIGHT 20
#define POS_X       0
#define POS_Y       0

//setup stacks...
stack<int> history;
stack<int> history_storage;
//********************************************************************************
//-----------------------------Class Conker---------------------------------------
//********************************************************************************
class conker{
	
public:
	float HL;					//the 1/2 life of the conker
	int king_of;				//the conkers power
	int nbattles;				//the number of battles its fought
	int conker_number;			//the conkers number

	conker(){HL=4;king_of=1+rand()%10;nbattles=0;}
	int fight_conkers(int,int,int);
	void raise_power(int);
	void reset(int &no_conkers);
};

//********************************************************************************
//-----------------------------Conker reset function------------------------------
//********************************************************************************
void conker::reset(int &no_conkers){
	add_to_history(king_of,nbattles,conker_number);
	king_of=1;
	nbattles=0;
	no_conkers++;
	conker_number=no_conkers;
}

//********************************************************************************
//-----------------------------Conker raise power function------------------------
//********************************************************************************
void conker::raise_power(int loser_king_of){
	king_of+=loser_king_of;
	nbattles+=1;
}

//********************************************************************************
//-----------------------------Conker fight conker function-----------------------
//********************************************************************************
int conker::fight_conkers(int king2,int HL2,int battles2){				
	float first_strength;		//the first conkers strength value
	float second_strength;		//the second conkers strength value
	float strength_ratio;		//ratio of the strengths
	int random;					//random num ber between 0 and 100
	srand(time(NULL));
	//strength of this conker
	first_strength = king_of *((float)HL /(HL + nbattles));
	//strength of opponent
	second_strength = king2 *((float)HL2 /(HL2 + battles2));
	//ratio of the strengths
	strength_ratio = 100*(first_strength / (first_strength + second_strength));
	//return the winner
	random = rand()%100;
	if (random<strength_ratio)
		return 0;// conker 1 is winner
	else
		return 1;// conker 2 is winner
}

//********************************************************************************
//-------------------------------MAIN---------------------------------------------
//********************************************************************************
int main(){
	int conker1=0;				//random number between 0 and 9
	int conker2=0;				//random number between 0 and 9	
	int winner=0;				//0=conker1 is winner; 1=conker2 is winner
	int i,j;						//for loops
	char keep_playing=0;        //if 0 the program keeps looping, if 1 the program ends
	//int kingout[10];            //the output array for the king_of values
	//int battlesout[10];         //the output array for the nbattles values
	//int numberout[10];          //the output array for the conker_number values
	int number_of_conkers=0;	//number of conkers
	int conker1number=0;		//holds the value of conker1s conker_number so it doesnt get lost if conker1 loses
	int conker2number=0;		//holds the value of conker2s conker_number so it doesnt get lost if conker2 loses
	int line_number=0;			//current position of the cursor.

	CHAR_INFO screenBuffer[GRID_WIDTH * GRID_HEIGHT];	
	SMALL_RECT drawRect = {POS_X, POS_Y, POS_X + (GRID_WIDTH - 1), POS_Y + (GRID_HEIGHT - 1)}; 
	COORD gridSize = {GRID_WIDTH , GRID_HEIGHT};		
	COORD zeroZero = {0, 0};							
	HANDLE OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
	int x=3,y=10,enemyx[10],enemyy[10];//x and y positions of the player, and the 10 enemies onscreen at once
	int will_move; //evaluated whether the enemies will move or stay in the same place
	int moved; //evaluates whether the enemy has moved(can also mean its chosen not to move)
	char key;//hold the value of the key being pressed
	int level_map[GRID_WIDTH * GRID_HEIGHT]= {//gives the basic map of ascii characters of the level
		35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,35,35,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,35,35,00,00,00,00,35,
		35,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,35,
		35,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,35,
		35,00,00,00,00,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,00,00,00,00,35,
		35,00,00,00,00,35,35,35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,35,35,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35};
	
	//initiate random sequence unpredictably
	srand(time(NULL));
	//setup the conkers
	conker player[11];//conker 10 is the player
	for (i=0;i<10;i++){
		number_of_conkers++;player[i].conker_number=number_of_conkers;
	}
	//set the players innitial stats
	player[10].king_of = 10;
	player[10].HL = 30;
	//set player pos so enemies are not placed on top
	screenBuffer[x + y * GRID_WIDTH].Char.AsciiChar = 1; 
	screenBuffer[x + y * GRID_WIDTH].Attributes = FOREGROUND_BLUE;
	//get enemy positions
	for (i=0;i<10;i++){
		do{
			enemyx[i]=1+rand()%33;
			enemyy[i]=1+rand()%18;
		}while(screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Char.AsciiChar == 00);
		//set the enemy positions, so other enemies cannot be placed on top.
		screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Char.AsciiChar = 2;
		screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Attributes = get_enemy_colour(player[10].king_of,player[i].king_of);
	}
	while(1){
	for (i=0; i < GRID_WIDTH * GRID_HEIGHT;i++){
		screenBuffer[i].Char.AsciiChar = level_map[i]; 
		screenBuffer[i].Attributes = FOREGROUND_GREEN;
	}
	if (kbhit()){
		key = toupper(getch());
		switch (key){
		case ('W')://up
			if (screenBuffer[x + (y-1) * GRID_WIDTH].Char.AsciiChar != 35)
				y-=1;
			break;
		case ('S')://down
			if (screenBuffer[x + (y+1) * GRID_WIDTH].Char.AsciiChar != 35)
				y+=1;
			break;
		case ('A')://left
			if (screenBuffer[(x-1) + y * GRID_WIDTH].Char.AsciiChar != 35)
				x-=1;
			break;
		case ('D')://right
			if (screenBuffer[(x+1) + y * GRID_WIDTH].Char.AsciiChar != 35)
				x+=1;
			break;
		case ('H')://right
			if (number_of_conkers>10){
				display_history(number_of_conkers-10);
				line_number=0;
			}
		}
	}

	screenBuffer[x + y * GRID_WIDTH].Char.AsciiChar = 1; 
	screenBuffer[x + y * GRID_WIDTH].Attributes = 1;

	for (i=0;i<10;i++){
		moved=0;
		do{
			will_move=rand()%5;
			switch(will_move){
			case 0://up
				if (screenBuffer[(enemyx[i]-1) + enemyy[i] * GRID_WIDTH].Char.AsciiChar != 35){
					enemyx[i]-=1;moved=1;break;}
			case 1://down
				if (screenBuffer[(enemyx[i]+1) + enemyy[i] * GRID_WIDTH].Char.AsciiChar != 35){
					enemyx[i]+=1;moved=1;break;}
			case 2://left
				if (screenBuffer[enemyx[i] + (enemyy[i]-1) * GRID_WIDTH].Char.AsciiChar != 35){
					enemyy[i]-=1;moved=1;break;}
			case 3://right
				if (screenBuffer[enemyx[i] + (enemyy[i]+1) * GRID_WIDTH].Char.AsciiChar != 35){
					enemyy[i]+=1;moved=1;break;}
			case 4://none
				moved=1;break;
			default:
				moved=1;break;
			}
		}while(moved==0);
		//set the enemy positions, so other enemies cannot be placed on top.
		screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Char.AsciiChar = 2;
		screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Attributes = get_enemy_colour(player[10].king_of,player[i].king_of);
		for (j=0;j<10;j++){
			//check if enemies are touching each other
			if (enemyx[i] == enemyx[j] && enemyy[i] == enemyy[j] && i!=j){
				conker1number=player[i].conker_number;
				conker2number=player[j].conker_number;
				winner = player[i].fight_conkers(player[j].king_of,player[j].HL,player[j].nbattles);
				if (winner == 0){//player i = winner
					player[i].raise_power(player[j].king_of);
					player[j].reset(number_of_conkers);
					do{//reposition player j
						enemyx[j]=1+rand()%33;
						enemyy[j]=1+rand()%18;
					}while(screenBuffer[enemyx[j] + enemyy[j] * GRID_WIDTH].Char.AsciiChar != 0);
				}else{//player j = winner
					player[j].raise_power(player[i].king_of);
					player[i].reset(number_of_conkers);
					do{//reposition player i
						enemyx[i]=1+rand()%33;
						enemyy[i]=1+rand()%18;
					}while(screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Char.AsciiChar != 0);
				}
				//display the winner
				if (line_number > 19){line_number=0;system("CLS");}
				set_screen_pos(40,line_number);line_number+=1;
				cout << "Enemy " << conker1number << " fought enemy " << conker2number << " and " << (winner==1 ? "lost." : "won.");
				set_screen_pos(40,line_number);line_number+=1;
				cout << "Enemy " << player[(winner == 1 ? i : j)].conker_number << " has joined the battle!";
			}
			//if player is touching an enemy...
			if (enemyx[i]==x && enemyy[i]==y){
				winner = player[i].fight_conkers(player[10].king_of,player[10].HL,player[10].nbattles);
				if (line_number > 19){line_number=0;system("CLS");}
				set_screen_pos(40,line_number);line_number+=1;
				cout << "You fight enemy " << player[i].conker_number << "...";
				player_battle(winner,line_number, get_enemy_colour(player[10].king_of,player[i].king_of));
				if (winner == 1){
					if (line_number > 19){line_number=0;system("CLS");}
					set_screen_pos(40,line_number);line_number+=1;
					cout << "...and win!";
					player[10].raise_power(player[i].king_of);
					player[i].reset(number_of_conkers);
					do{//reposition player j
						enemyx[i]=1+rand()%33;
						enemyy[i]=1+rand()%18;
					}while(screenBuffer[enemyx[i] + enemyy[i] * GRID_WIDTH].Char.AsciiChar == 0);
					set_screen_pos(40,line_number);line_number+=1;
					cout << "Enemy " << player[(winner == 1 ? i : j)].conker_number << " has joined the battle!";
				}
			}
		}
	}
	//output the players stats, and display history text
	set_screen_pos(1,21);
	cout << "King Of: " << player[10].king_of << "  " << "Number of battles: " << player[10].nbattles;
	set_screen_pos(1,22);
	cout << "Strength: " << player[10].king_of *((float)player[10].HL /(player[10].HL + player[10].nbattles));
	set_screen_pos(1,23);
	if (number_of_conkers>10)
		cout << "Press H for the History";
	WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
	Sleep(100);
	}
	return 0;
}
//********************************************************************************
//-----------------------------player_fight function------------------------------
//********************************************************************************

int get_enemy_colour(int playerk,int enemyk){
	if (enemyk>playerk+5)
		return 4;
	else if (enemyk<playerk-5)
		return 2;
	else 
		return 6;
}

//********************************************************************************
//-----------------------------player_fight function------------------------------
//********************************************************************************

void player_battle(int winner,int &line_number,int enemy_colour){
	CHAR_INFO screenBuffer[GRID_WIDTH * GRID_HEIGHT];	
	SMALL_RECT drawRect = {POS_X, POS_Y, POS_X + (GRID_WIDTH - 1), POS_Y + (GRID_HEIGHT - 1)}; 
	COORD gridSize = {GRID_WIDTH , GRID_HEIGHT};		
	COORD zeroZero = {0, 0};							
	HANDLE OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
	char key=0;		//checks if the end key has been pressed
	int y=14; //players y coord
	int ey=7;//enemies y coord
	int i,j,k;//for loops
	int level_map[GRID_WIDTH * GRID_HEIGHT]= {//gives the basic map of ascii characters of the level
		35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,35,
		35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35};
		//animate the faces attacking each other.
		for (i=0;i<3;i++){
			for (j=0;j<3;j++){
				for (k=0; k < GRID_WIDTH * GRID_HEIGHT;k++){
					screenBuffer[k].Char.AsciiChar = level_map[k]; 
					screenBuffer[k].Attributes = FOREGROUND_GREEN;
				}
				y-=1;ey+=1;
				screenBuffer[18 + y * GRID_WIDTH].Char.AsciiChar = 1;
				screenBuffer[18 + y * GRID_WIDTH].Attributes = FOREGROUND_BLUE;
				screenBuffer[18 + ey * GRID_WIDTH].Char.AsciiChar = 2;
				screenBuffer[18 + ey * GRID_WIDTH].Attributes = enemy_colour;
				WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
				Sleep(100);
			}
			Sleep(100);
			for (j=0;j<3;j++){
				for (k=0; k < GRID_WIDTH * GRID_HEIGHT;k++){
					screenBuffer[k].Char.AsciiChar = level_map[k]; 
					screenBuffer[k].Attributes = FOREGROUND_GREEN;
				}
				y+=1;ey-=1;
				screenBuffer[18 + y * GRID_WIDTH].Char.AsciiChar = 1;
				screenBuffer[18 + y * GRID_WIDTH].Attributes = FOREGROUND_BLUE;
				screenBuffer[18 + ey * GRID_WIDTH].Char.AsciiChar = 2;
				screenBuffer[18 + ey * GRID_WIDTH].Attributes = enemy_colour;
				WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
				Sleep(100);
			}
		}
		for (j=0;j<3;j++){
				for (k=0; k < GRID_WIDTH * GRID_HEIGHT;k++){
					screenBuffer[k].Char.AsciiChar = level_map[k]; 
					screenBuffer[k].Attributes = FOREGROUND_GREEN;
				}
				y-=1;ey+=1;
				screenBuffer[18 + y * GRID_WIDTH].Char.AsciiChar = 1;
				screenBuffer[18 + y * GRID_WIDTH].Attributes = FOREGROUND_BLUE;
				screenBuffer[18 + ey * GRID_WIDTH].Char.AsciiChar = 2;
				screenBuffer[18 + ey * GRID_WIDTH].Attributes = enemy_colour;
				WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
				Sleep(100);
			}
		if (winner==1){//if the player wins then this happens...
			screenBuffer[18 + ey * GRID_WIDTH].Char.AsciiChar = 'x';
			screenBuffer[18 + ey * GRID_WIDTH].Attributes = enemy_colour;
			WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);	
			Sleep(400);
			screenBuffer[18 + ey * GRID_WIDTH].Char.AsciiChar = 00;
			WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
			Sleep(400);
			return;
		}else{//if the player loses this happens and the game ends...
			screenBuffer[18 + y * GRID_WIDTH].Char.AsciiChar = 'x';
			screenBuffer[18 + y * GRID_WIDTH].Attributes = FOREGROUND_BLUE;
			WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);	
			Sleep(400);
			screenBuffer[18 + y * GRID_WIDTH].Char.AsciiChar = 00;
			WriteConsoleOutput(OutputH, screenBuffer, gridSize, zeroZero, &drawRect);
			Sleep(400);
			if (line_number > 19){line_number=0;system("CLS");}
			set_screen_pos(40,line_number);line_number+=1;
			cout << "...and lose.";
			Sleep(500);
			set_screen_pos(14,7);
			cout << "GAME OVER";
			Sleep(1000);
			set_screen_pos(12,8);
			cout << "Press X to end.";
			while(1){
				if (kbhit()){
					key=toupper(getch());
					if (key=='X'){
						set_screen_pos(5,8);
						exit(0);
					}
				}
			}
			
		}


}

//********************************************************************************
//-----------------------------set_screen_pos function----------------------------
//********************************************************************************

void set_screen_pos(int coordx,int coordy){
	COORD cursor_pos; // used to pass coords
	HANDLE hconsole=CreateFile("CONOUT$",GENERIC_WRITE | GENERIC_READ,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

	// set printing position
	cursor_pos.X = coordx;
	cursor_pos.Y = coordy;
	SetConsoleCursorPosition(hconsole,cursor_pos);
}


//********************************************************************************
//-----------------------------Add to history function----------------------------
//********************************************************************************
void add_to_history(int king_of,int nbattles,int conker_number){
	history.push(king_of);
	history.push(nbattles);
	history.push(conker_number);
}

//********************************************************************************
//-----------------------------display history function---------------------------
//********************************************************************************
void display_history(int no_in_history){
	int number;				//number of the conker
	int king;				//the conkers king_of
	int battles;			//number of battles the conkers fought
	int i;					//used in loops
	int return_value;		//used when returning values to the history
	char key;				//used for getting key presses.

	system("CLS");
	//output the values in the stack "history" and move all the values to "history_storage"
	for (i=0;i<no_in_history;i++){
		number = history.top();history_storage.push(number);history.pop();
		battles = history.top();history_storage.push(battles);history.pop();
		king = history.top();history_storage.push(king);history.pop();
		cout << "Enemy " << number <<" was King Of: " << king << " and survived: " << battles << " battles.\n";
	}
	//switch all the values back from "history_storage" to "history"
	for (i=0;i<no_in_history*3;i++){
		return_value=history_storage.top();
		history.push(return_value);
		history_storage.pop();
	}
	cout << "\nOptions:\n";
	cout << "          B - Back to game.\n";
	cout << "          X - Exit program.\n"; 
	while(1){
		if (kbhit()){
			key = toupper(getch());
			switch (key){
			case ('B')://up
				system("CLS");
				return;
				break;
			case ('X')://down
				exit(0);
				break;
			}
		}
	}
}




