0% found this document useful (0 votes)
6 views42 pages

game docsupload

The document outlines the game 'Tank Wars', which is a single-player tank combat game inspired by World War I. It details the game's characters, rules, objectives, and includes wireframes and function prototypes for the game's code. The player must navigate through levels, defeat enemies, and manage health while avoiding enemy fire to win the game.

Uploaded by

anasfaizsahi6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views42 pages

game docsupload

The document outlines the game 'Tank Wars', which is a single-player tank combat game inspired by World War I. It details the game's characters, rules, objectives, and includes wireframes and function prototypes for the game's code. The player must navigate through levels, defeat enemies, and manage health while avoiding enemy fire to win the game.

Uploaded by

anasfaizsahi6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Tank Wars

Session 2023 – 2027

Submitted by:
Anas Faiz 2023-CS-26

Supervised by:
Dr. Muhammad Awais Hassan

Course:
CSC-102 Programming Fundamentals

Department of Computer Science

University of Engineering and Technology


Lahore Pakistan
Grow

Table of Content
s
 Tank Wars...................................................................................................................................................3
 Tank wars Characters..................................................................................................................................3
 Game Objects..............................................................................................................................................3
 Rules & Interactions...................................................................................................................................3
 Goal of The Game.......................................................................................................................................4
 Wireframes of the Game.............................................................................................................................4
 Function Prototypes....................................................................................................................................7
 Complete Code...........................................................................................................................................9

Anas Faiz 2023-CS-26


Grow

 Tank Wars
The game is based on the a war tank which is going to fight to with his enemies and fight to
death
I have used the concept of world war 1 in which my player plays the role of one side of the
waring
nation but in my game there is only one player and three enemy in the first level and one player
and one enemy in 2nd level so the competition is tough for the player but he has do it for his
country.

 Tank wars Characters


This following are the characters of the game:
o Player : The player can move in the maze from left to right in first level and top to bottom in
level 2nd.
o Enemy 1: The enemy is present on the top of the maze and moves right and left whilst also
shooting bullets. The movement of this enemy and all the enemies are random so the player
cannot know where the enemy may move.
o Enemy 2: This is one moves right to left in the top middle corner of the maze while also fires
bullets. Its movement is also random.
o Enemy 3: This enemy is present near the spawn point of the player and shoots bullets at him.
o Final Boss 1: It is small in size than other enemies and shoots bullets whilst moving up and
down randomly and quickly making it a very hard target to hit. It appears in the final level.
o Final player: Final level player is big and slow because of being tired after first war. This
makes it a very easy target.

 Game Objects
The object in the game is:
o A health of 200 is given to the player in level one and 100 in final level. Its objective is to
shoot and kill all the enemies before they kill him. Every time it takes a bullet it loses the
health of 50 so it has play very carefully in order to survive.
o Survival is one of the main objective.

 Rules & Interactions


The rules of the game are:
o The player must kill all the enemies in the first level and the final level.
o The player has a health of 200 in level one and 100 in level final.
o The enemies shoot continuously to prevent the player from killing them.
o Press right arrow key to move player right. Left for left up for up and down arrow key for
down movement.

Anas Faiz 2023-CS-26


Grow

o Press up space key to shoot bullet from the tank of player.


o Enemies will spawn randomly on screen and you need to kill them by shooting at them with
your bullet.
o The hero and enemies health are given at the bottom of the maze.
o Avoid player's contact with enemy bullet and kill them before they do.
o Press escape key to exit the game.

 Goal of The Game


The goal of the game is that the hero must kill all enemies while keeping himself alive to reach
the final level. Where the hero will face enemy while having restricted motion. The hero will
eliminate them and win the game.

 Wireframes of the Game

Figure 1: Main Menu

Anas Faiz 2023-CS-26


Grow

Figure 2: first level maze

Anas Faiz 2023-CS-26


Grow

Figure 3: Final Level of the Game

Figure 4: Game lost

Anas Faiz 2023-CS-26


Grow

Figure 5: Game won

Figure 6: final level screen

 Function Prototypes
 void gotoxy(int x, int y);
 char getCharAtxy(short int x, short int y);
 void printenemy();
 void eraseenemy();
 void printenemy2();
 void eraseenemy2();
 void printenemy3();
 void eraseenemy3();
 void eraseplayer();
 void printplayer();
 void moveplayerleft();
Anas Faiz 2023-CS-26
Grow

 void moveplayerright();
 void moveenemy(int digit);
 void moveenemy2(int digit);
 void moveenemy3(int digit);
 void moveBullet();
 void removefire();
 void header();
 bool checkCollision();
 void printmaze();
 void enemyhealth();
 void enemyShoot();
 void printEnemyBullets();
 void moveEnemyBullet();
 void printplayerhealth();
 void gamelost();
 void gamewon();
 int random(int min, int max);

 // final level stuff


 int playerfX = 2;
//x axis of the final player
 int playerfY = 2;
//y axis of the final player
 int enemyfX = 50;
//x axis of final enemy
 int enemyfY = 3;
 int finalenemyhealth = 300;
 int finalplayerhealth = 100;
 int playerbulletfX;
 int playerbulletfY;
 int finalenemybulletX, finalenemybulletY;
 bool checkfinalenemy = true;
 bool checkfinalplayerbullet = false;
 bool checkfinalenemybullet = false;
 bool finallevel = false;
 bool finish = false;
 bool lost = false;

 void printfinallevel();
 void printfinalmaze();
 void printfinalenemy();
 void erasefinalenemy();
 void printplayerfinal();
 void eraseplayerfinal();
 void printfinalplayerhealth();
 void printfinalenemyhealth();
 void finalenemyshoot();
 void movefinalenemybullet();
 void movefinalplayerbullet();
Anas Faiz 2023-CS-26
Grow

 int movefinalenemy(int digit);


 void movefinalplayerup();
 void movefinalplayerdown();
 void erasefinalplayerbullet();
 void printfinalenemybullet();
 // firstlevelvariables

 int eX = 2, eY = 2;

//enemy level one x and y axis


 int eX2 = 30, eY2 = 15;
 int eX3 = 2, eY3 = 8;
 int pX = 20, pY = 22;
//player x and y axis in level one
 int digit;
 int bX, bY;
//bullet axis
 int enemey1bulletX, enemey1bulletY, enemey2bulletX, enemey2bulletY, enemey3bulletX,
enemey3bullety;
 int enemyhealth1 = 200;
 int enemyhealth2 = 200;
 int enemyhealth3 = 200;
 int playerhealth = 300;

 bool checkenemy1 = true, checkenemy2 = true, checkenemy3 = true;


 bool playerbulletcheck = false;
 bool enemy1bulletcheck = false;
 bool enemy2bulletcheck = false;
 bool enemy3bulletcheck = false;
 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

 Complete Code
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;

void gotoxy(int x, int y);


char getCharAtxy(short int x, short int y);
void printenemy();
void eraseenemy();

Anas Faiz 2023-CS-26


Grow

void printenemy2();
void eraseenemy2();
void printenemy3();
void eraseenemy3();
void eraseplayer();
void printplayer();
void moveplayerleft();
void moveplayerright();
void moveenemy(int digit);
void moveenemy2(int digit);
void moveenemy3(int digit);
void moveBullet();
void removefire();
void header();
bool checkCollision();
void printmaze();
void enemyhealth();
void enemyShoot();
void printEnemyBullets();
void moveEnemyBullet();
void printplayerhealth();
void gamelost();
void gamewon();
int random(int min, int max);

// final level stuff


int playerfX = 2;
int playerfY = 2;
int enemyfX = 50;
int enemyfY = 3;
int finalenemyhealth = 300;
Anas Faiz 2023-CS-26
Grow

int finalplayerhealth = 100;


int playerbulletfX;
int playerbulletfY;
int finalenemybulletX, finalenemybulletY;
bool checkfinalenemy = true;
bool checkfinalplayerbullet = false;
bool checkfinalenemybullet = false;
bool finallevel = false;
bool finish = false;
bool lost = false;

void printfinallevel();
void printfinalmaze();
void printfinalenemy();
void erasefinalenemy();
void printplayerfinal();
void eraseplayerfinal();
void printfinalplayerhealth();
void printfinalenemyhealth();
void finalenemyshoot();
void movefinalenemybullet();
void movefinalplayerbullet();
int movefinalenemy(int digit);
void movefinalplayerup();
void movefinalplayerdown();
void erasefinalplayerbullet();
void printfinalenemybullet();
// firstlevelvariables

int eX = 2, eY = 2;
int eX2 = 30, eY2 = 15;
Anas Faiz 2023-CS-26
Grow

int eX3 = 2, eY3 = 8;


int pX = 20, pY = 22;
int digit;
int bX, bY;
int enemey1bulletX, enemey1bulletY, enemey2bulletX, enemey2bulletY, enemey3bulletX,
enemey3bullety;
int enemyhealth1 = 200;
int enemyhealth2 = 200;
int enemyhealth3 = 200;
int playerhealth = 300;

bool checkenemy1 = true, checkenemy2 = true, checkenemy3 = true;


bool playerbulletcheck = false;
bool enemy1bulletcheck = false;
bool enemy2bulletcheck = false;
bool enemy3bulletcheck = false;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

int main()
{
system("cls");
system("Color 04");
header();
system("Color 0A");
system("cls");
printmaze();
printenemy();
printenemy2();
printenemy3();
printplayer();
// bool isFiring = false;

Anas Faiz 2023-CS-26


Grow

while (true)
{
if (playerhealth < 0)
{
playerhealth = 0;
break;
}
if (playerhealth >= 0 && !checkenemy1 && !checkenemy2 && !checkenemy3)
{
finallevel = true;
}
enemyhealth();
enemyShoot();
moveEnemyBullet();
printEnemyBullets();
printplayerhealth();
if (enemyhealth1 <= 0)
{
enemyhealth1 = 0;
checkenemy1 = false;
enemy1bulletcheck = true;
gotoxy(enemey1bulletX, enemey1bulletY);
cout << " ";
}
if (enemyhealth2 <= 0)
{
enemyhealth2 = 0;
checkenemy2 = false;
enemy2bulletcheck = true;
gotoxy(enemey2bulletX, enemey2bulletY);
Anas Faiz 2023-CS-26
Grow

cout << " ";


}
if (enemyhealth3 <= 0)
{
enemyhealth3 = 0;
checkenemy3 = false;
enemy3bulletcheck = true;
gotoxy(enemey3bulletX, enemey3bullety);
cout << " ";
}
if (GetAsyncKeyState(VK_LEFT))
{
moveplayerleft();
}
if (GetAsyncKeyState(VK_RIGHT))
{
moveplayerright();
}

int a = random(0, 1);


moveenemy(a);
moveenemy2(a);
moveenemy3(a);

if (GetAsyncKeyState(VK_ESCAPE))
{
break;
}

if (GetAsyncKeyState(VK_SPACE))
{
Anas Faiz 2023-CS-26
Grow

if (!playerbulletcheck)
{
bX = pX + 6;
bY = pY - 1;
playerbulletcheck = true;
}
}

if (playerbulletcheck)
{
moveBullet();
}
if (playerhealth <= 0)
{
system("cls");
gamelost();
getch();
lost = true;
break;
}
if (finallevel)
{

system("cls");
printfinallevel();
Sleep(3000);
system("cls");
printfinalmaze();
printplayerfinal();
printfinalenemy();

Anas Faiz 2023-CS-26


Grow

while (true)
{
finalenemyshoot();
movefinalenemybullet();
printfinalenemybullet();
printfinalenemyhealth();
printfinalplayerhealth();
Sleep(100);

if (finalplayerhealth > 0 && !checkfinalenemy)


{
finish = true;
break;
}

if (finalenemyhealth <= 0)
{
checkfinalenemy = false;
checkfinalenemybullet = true;
gotoxy(finalenemybulletX, finalenemybulletY);
cout << " ";
lost = true;
}

if (GetAsyncKeyState(VK_UP))
{
movefinalplayerup();
}
if (GetAsyncKeyState(VK_DOWN))
{
movefinalplayerdown();
Anas Faiz 2023-CS-26
Grow

}
if (GetAsyncKeyState(VK_SPACE))
{
if (!checkfinalplayerbullet)
{
playerbulletfX = playerfX + 21;
playerbulletfY = playerfY;
checkfinalplayerbullet = true;
}
}
if (checkfinalplayerbullet)
{
movefinalplayerbullet();
}

int b = random(0, 1);


movefinalenemy(b);
if (finalplayerhealth <= 0)
{
lost = true;
break;
}
}
}

Sleep(100);
if (lost)
{
break;
}
if (finish)
Anas Faiz 2023-CS-26
Grow

{
break;
}
}
if (lost)
{
system("cls");
gamelost();
getch;
exit(0);
}
if (finish)
{
system("cls");
gamewon();
getch;
exit(0);
}
return 0;
}

void printmaze()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout <<
"##########################################################################
##########################" << endl;
cout << "# # #" << endl;
cout << "# # #" << endl;
cout << "# # #" << endl;
cout << "# # #" << endl;

Anas Faiz 2023-CS-26


Grow

cout << "# #################" <<


endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout <<
"##########################################################################
##########" << endl;
cout << "# #" << endl;
cout <<
"##########################################################################
##########" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
}

Anas Faiz 2023-CS-26


Grow

void printenemy()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
gotoxy(eX, eY);
cout << " _____ ";
gotoxy(eX, eY + 1);
cout << " __|_>o<_|__ ";
gotoxy(eX, eY + 2);
cout << "/___________\\ ";
gotoxy(eX, eY + 3);
cout << "\\=\\>-----</=/";
gotoxy(eX, eY + 4);
cout << "_______________";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
}

void printenemy2()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
gotoxy(eX2, eY2);
cout << " _____/_o_\\_____ ";
gotoxy(eX2, eY2 + 1);
cout << "(==(/_______\\)==) ";
gotoxy(eX2, eY2 + 2);
cout << " \\==\\/ \\/==/";
gotoxy(eX2, eY2 + 3);
cout << "===================";
}

void printenemy3()
Anas Faiz 2023-CS-26
Grow

{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
gotoxy(eX3, eY3);
cout << " _____ ";
gotoxy(eX3, eY3 + 1);
cout << " __|_>o<_|__ ";
gotoxy(eX3, eY3 + 2);
cout << "/___________\\ ";
gotoxy(eX3, eY3 + 3);
cout << "\\=\\>-----</=/";
gotoxy(eX3, eY3 + 4);
cout << "---------------";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
}

void eraseenemy()
{
gotoxy(eX, eY);
cout << " ";
gotoxy(eX, eY + 1);
cout << " ";
gotoxy(eX, eY + 2);
cout << " ";
gotoxy(eX, eY + 3);
cout << " ";
gotoxy(eX, eY + 4);
cout << " ";
}

void eraseenemy2()
{
Anas Faiz 2023-CS-26
Grow

gotoxy(eX2, eY2);
cout << " ";
gotoxy(eX2, eY2 + 1);
cout << " ";
gotoxy(eX2, eY2 + 2);
cout << " ";
gotoxy(eX2, eY2 + 3);
cout << " ";
}

void eraseenemy3()
{
gotoxy(eX3, eY3);
cout << " ";
gotoxy(eX3, eY3 + 1);
cout << " ";
gotoxy(eX3, eY3 + 2);
cout << " ";
gotoxy(eX3, eY3 + 3);
cout << " ";
gotoxy(eX3, eY3 + 4);
cout << " ";
}

void moveenemy(int digit)


{
eraseenemy();
if (checkenemy1)
{
if (digit == 1)
{
Anas Faiz 2023-CS-26
Grow

eX += 5;
}
else
{
eX -= 5;
}
if (eX >= 60)
{
eX = 2;
}
if (eX <= 2)
{
eX = 60;
}
printenemy();
}
}

void moveenemy2(int digit)


{
eraseenemy2();
if (checkenemy2)
{
if (digit == 1)
{
eX2 += 5;
}
else
{
eX2 -= 5;
}
Anas Faiz 2023-CS-26
Grow

if (eX2 >= 60)


{
eX2 = 15;
}
if (eX2 <= 2)
{
eX2 = 60;
}
printenemy2();
}
}

void moveenemy3(int digit)


{
eraseenemy3();
if (checkenemy3)
{
if (digit == 0)
{
eX3 += 5;
}
else
{
eX3 -= 5;
}
if (eX3 >= 60)
{
eX3 = 2;
}
if (eX3 <= 2)
{
Anas Faiz 2023-CS-26
Grow

eX3 = 60;
}
printenemy3();
}
}

void eraseplayer()
{
gotoxy(pX, pY);
cout << " ";
gotoxy(pX, pY + 1);
cout << " ";
gotoxy(pX, pY + 2);
cout << " ";
gotoxy(pX, pY + 3);
cout << " ";
gotoxy(pX, pY + 4);
cout << " ";
}

void printplayer()
{
gotoxy(pX, pY);
cout << "!!!!!!o!!!!!!!";
gotoxy(pX, pY + 1);
cout << " || ";
gotoxy(pX, pY + 2);
cout << " ___( )___ ";
gotoxy(pX, pY + 3);
cout << "/~~~~~~~~~~~\\";
gotoxy(pX, pY + 4);
Anas Faiz 2023-CS-26
Grow

cout << "\\0.0.0.0.0.0/";


}

void moveplayerleft()
{
if (getCharAtxy(pX - 2, pY) == ' ' && getCharAtxy(pX - 2, pY + 1) == ' ' &&
getCharAtxy(pX - 2, pY + 2) == ' ')
{
eraseplayer();
pX = pX - 3;
printplayer();
}
}

void moveplayerright()
{
if (getCharAtxy(pX + 15, pY) != '#')
{
eraseplayer();
pX += 3;
printplayer();
}
}

int random(int min, int max)


{
return rand() % (max - min + 1) + min;
}

void removefire()
{

Anas Faiz 2023-CS-26


Grow

gotoxy(bX, bY);
cout << " ";
}
void moveBullet()
{
removefire();
if (getCharAtxy(bX, bY) != '#')
{
bY -= 1; // Move up
}
else
{
playerbulletcheck = false;
}
if (getCharAtxy(bX, bY) == '_')
{
if (enemyhealth1 != 0)
{
enemyhealth1 -= 50;
}
playerbulletcheck = false; // Bullet should be inactive after hitting an enemy
removefire();
}

if (getCharAtxy(bX, bY) == '=')


{
if (enemyhealth2 != 0)
{
enemyhealth2 -= 50;
}
playerbulletcheck = false;
Anas Faiz 2023-CS-26
Grow

removefire();
}

if (getCharAtxy(bX, bY) == '-')


{
if (enemyhealth3 != 0)
{
enemyhealth3 -= 50;
}
playerbulletcheck = false;
removefire();
}
if (getCharAtxy(bX, bY) == '#' || bY < 2)
{
playerbulletcheck = false;
removefire();
}
else
{
gotoxy(bX, bY);
cout << "O";
}
}
void header()
{
cout << R"(
_____ _ _ _
|_ _| || || ||
| | __ _ _ __ | | __ | | | | __ _ _ __ ___
| | / _` || '_ \ | |/ / | |/\| | / _` || '__|/ __|
| || (_| || | | || < \ /\ /| (_| || | \__ \
Anas Faiz 2023-CS-26
Grow

\_/ \__,_||_| |_||_|\_\ \/ \/ \__,_||_| |___/

press any key to start

-------------------Instructions--------------------------------
1: Press right arrow key to move player right.
2: Press left arrow key to move player left.
3: Press up space key to shoot bullet from the tank of player.
4: Enemies will spawn randomly on screen and you need
to kill them by shooting at them with your bullet.
5: Press escape key to exit the game.
6: Avoid player's contact with enemy bullet and kill them before they do.
7: You can see health bar of enemies in bottom part of the screen.

)";
getch();
}
void enemyhealth()
{
gotoxy(2, 28);
cout << "Enemy1: " << enemyhealth1;
gotoxy(16, 28);
cout << "Enemy2: " << enemyhealth2;
gotoxy(32, 28);
cout << "Enemy3: " << enemyhealth3;
}
void moveEnemyBullet()
{
Anas Faiz 2023-CS-26
Grow

if (enemy1bulletcheck && checkenemy1)


{
gotoxy(enemey1bulletX, enemey1bulletY);
cout << " ";
enemey1bulletY += 1;
if (getCharAtxy(enemey1bulletX, enemey1bulletY) == '#')
{
enemy1bulletcheck = false;
}
if (getCharAtxy(enemey1bulletX, enemey1bulletY) == 'o' ||
getCharAtxy(enemey1bulletX, enemey1bulletY) == '!')
{
playerhealth -= 50;
}
}
if (enemy2bulletcheck && checkenemy2)
{
gotoxy(enemey2bulletX, enemey2bulletY);
cout << " ";
enemey2bulletY += 1;
if (getCharAtxy(enemey2bulletX, enemey2bulletY) == '#')
{
enemy2bulletcheck = false;
}

if (getCharAtxy(enemey2bulletX, enemey2bulletY) == 'o' ||


getCharAtxy(enemey2bulletX, enemey2bulletY) == '!')
{
playerhealth -= 50;
}
}

Anas Faiz 2023-CS-26


Grow

if (enemy3bulletcheck && checkenemy3)


{
gotoxy(enemey3bulletX, enemey3bullety);
cout << " ";
enemey3bullety += 1;
if (getCharAtxy(enemey3bulletX, enemey3bullety) == '#')
{
enemy3bulletcheck = false;
}

if (getCharAtxy(enemey3bulletX, enemey3bullety) == 'o' ||


getCharAtxy(enemey3bulletX, enemey3bullety) == '!')
{
playerhealth -= 50;
}
}
}
void printEnemyBullets()
{
if (enemy1bulletcheck)
{
gotoxy(enemey1bulletX, enemey1bulletY);
cout << "o";
}
if (enemy2bulletcheck)
{
gotoxy(enemey2bulletX, enemey2bulletY);
cout << "o";
}
if (enemy3bulletcheck)
{

Anas Faiz 2023-CS-26


Grow

gotoxy(enemey3bulletX, enemey3bullety);
cout << "o";
}
}
void enemyShoot()
{
if (!enemy1bulletcheck)
{
enemey1bulletX = eX + 7;
enemey1bulletY = eY + 2;
enemy1bulletcheck = true;
}
if (!enemy2bulletcheck)
{
enemey2bulletX = eX2 + 7;
enemey2bulletY = eY2 + 2;
enemy2bulletcheck = true;
}
if (!enemy3bulletcheck)
{
enemey3bulletX = eX3 + 7;
enemey3bullety = eY3 + 2;
enemy3bulletcheck = true;
}
}
void printplayerhealth()
{
gotoxy(84, 2);
cout << "Player Health: " << endl;
gotoxy(88, 3);
cout << " ";
Anas Faiz 2023-CS-26
Grow

gotoxy(88, 3);
cout << playerhealth;
}
char getCharAtxy(short int x, short int y)
{
CHAR_INFO ci;
COORD xy = {0, 0};
SMALL_RECT rect = {x, y, x, y};
COORD coordBufSize;
coordBufSize.X = 1;
coordBufSize.Y = 1;
return ReadConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE), &ci, coordBufSize,
xy, &rect) ? ci.Char.AsciiChar : ' ';
}
void gotoxy(int x, int y)
{
COORD coordinates;
coordinates.X = x;
coordinates.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinates);
}
void gamelost()
{
cout << R"(
____ __ _ _ _
/ ___| __ _ _ __ ___ ___ / _(_)_ __ (_)___| |__
| | _ / _` | '_ ` _ \ / _ \ | |_| | '_ \| / __| '_ \
| |_| | (_| | | | | | | __/ | _| | | | | \__ \ | | |
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_|_|___/_| |_|
\ \ / /__ _ _ | | ___ ___| |_
\ V / _ \| | | | | |/ _ \/ __| __|

Anas Faiz 2023-CS-26


Grow

| | (_) | |_| | | | (_) \__ \ |_


|_|\___/ \__,_| |_|\___/|___/\__|

)";
}
void gamewon()
{
cout << R"(
____ __ _ _ _
/ ___| __ _ _ __ ___ ___ / _(_)_ __ (_)___| |__
| | _ / _` | '_ ` _ \ / _ \ | |_| | '_ \| / __| '_ \
| |_| | (_| | | | | | | __/ | _| | | | | \__ \ | | |
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_|_|___/_| |_|
\ \ / /__ _ _ \ \ / /__ _ __
\ V / _ \| | | | \ \ /\ / / _ \| '_ \
| | (_) | |_| | \ V V / (_) | | | |
|_|\___/ \__,_| \_/\_/ \___/|_| |_|

)";
}
void printfinallevel()
{
cout << R"(
_____ _ _ _ _
| ___(_)_ __ __ _| | | | _____ _____| |
| |_ | | '_ \ / _` | | | |/ _ \ \ / / _ \ |
| _| | | | | | (_| | | | | __/\ V / __/ |
|_| |_|_| |_|\__,_|_| |_|\___| \_/ \___|_|
)";
Anas Faiz 2023-CS-26
Grow

}
void printfinalmaze()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout <<
"##########################################################################
##########################" << endl;
cout << "# * # #" << endl;
cout << "# * # #" << endl;
cout << "# * # #" << endl;
cout << "# * # #" << endl;
cout << "# * #################" <<
endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# * #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
cout << "# #" << endl;
Anas Faiz 2023-CS-26
Grow

cout << "# #" << endl;


cout << "# #" << endl;
cout <<
"##########################################################################
##########" << endl;
cout << "# #" << endl;
cout <<
"##########################################################################
##########" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
}
void printfinalenemy()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
gotoxy(enemyfX, enemyfY);
cout << " !___ ";
gotoxy(enemyfX, enemyfY + 1);
cout << "::====( )__ ";
gotoxy(enemyfX, enemyfY + 2);
cout << " !/~~~~~~~~~\\";
gotoxy(enemyfX, enemyfY + 3);
cout << " !\\O.O.O.O.O/";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
}
void erasefinalenemy()
{
gotoxy(enemyfX, enemyfY);
cout << " ";
gotoxy(enemyfX, enemyfY + 1);
cout << " ";
gotoxy(enemyfX, enemyfY + 2);
cout << " ";

Anas Faiz 2023-CS-26


Grow

gotoxy(enemyfX, enemyfY + 3);


cout << " ";
}
void printplayerfinal()
{
gotoxy(playerfX, playerfY);
cout << "! /-----\\======@ ";
gotoxy(playerfX, playerfY + 1);
cout << "|_____/_______\\_____> ";
gotoxy(playerfX, playerfY + 2);
cout << "/____________________\\>";
gotoxy(playerfX, playerfY + 3);
cout << "\\+__+__+__+__+__+__+/> ";
}
void eraseplayerfinal()
{
gotoxy(playerfX, playerfY);
cout << " ";
gotoxy(playerfX, playerfY + 1);
cout << " ";
gotoxy(playerfX, playerfY + 2);
cout << " ";
gotoxy(playerfX, playerfY + 3);
cout << " ";
}
void printfinalplayerhealth()
{
gotoxy(84, 2);
cout << "Player Health: " << endl;
gotoxy(88, 3);
cout << " ";
Anas Faiz 2023-CS-26
Grow

gotoxy(88, 3);
cout << finalplayerhealth;
}
void printfinalenemyhealth()
{
gotoxy(20, 28);
cout << "Enemy: ";
gotoxy(27, 28);
cout << " ";
gotoxy(27, 28);
cout << finalenemyhealth;
}
void finalenemyshoot()
{
if (!checkfinalenemybullet)
{
finalenemybulletX = enemyfX;
finalenemybulletY = enemyfY + 2;
checkfinalenemybullet = true;
}
}
void printfinalenemybullet()
{
if (checkfinalenemybullet)
{
gotoxy(finalenemybulletX, finalenemybulletY);
cout << "O";
}
}
void movefinalenemybullet()
{
Anas Faiz 2023-CS-26
Grow

if (checkfinalenemybullet && checkfinalenemy)


{
gotoxy(finalenemybulletX, finalenemybulletY);
cout << " ";
finalenemybulletX -= 2;
if (getCharAtxy(finalenemybulletX, finalenemybulletY) == '#')
{
checkfinalenemybullet = false;
}
if (getCharAtxy(finalenemybulletX, finalenemybulletY) == '@' ||
getCharAtxy(finalenemybulletX, finalenemybulletY) == '>' ||
getCharAtxy(finalenemybulletX, finalenemybulletY) == '\\' ||
getCharAtxy(finalenemybulletX, finalenemybulletY) == '/' ||
getCharAtxy(finalenemybulletX, finalenemybulletY) == '_')
{
finalplayerhealth -= 50;
checkfinalenemybullet = false;
}
}
}
void erasefinalplayerbullet()
{
gotoxy(playerbulletfX, playerbulletfY);
cout << " ";
}
void movefinalplayerbullet()
{
erasefinalplayerbullet();
if (getCharAtxy(playerbulletfX + 2, playerbulletfY) != '#' || getCharAtxy(playerbulletfX +
2, playerbulletfY) != '*')
{
playerbulletfX += 2; // Move right

Anas Faiz 2023-CS-26


Grow

}
else
{
checkfinalplayerbullet = false;
}
if (getCharAtxy(playerbulletfX + 1, playerbulletfY) == ':' || getCharAtxy(playerbulletfX +
1, playerbulletfY) == '!')
{
if (finalenemyhealth != 0)
{
finalenemyhealth -= 50;
}
checkfinalplayerbullet = false; // Bullet should be inactive after hitting an enemy
erasefinalplayerbullet();
}
if (getCharAtxy(playerbulletfX + 2, playerbulletfY) == '#' || getCharAtxy(playerbulletfX +
2, playerbulletfY) == '*')
{
checkfinalplayerbullet = false;
erasefinalplayerbullet();
}
else
{
gotoxy(playerbulletfX, playerbulletfY);
cout << "O";
}
}
int movefinalenemy(int digit)
{
{
erasefinalenemy();

Anas Faiz 2023-CS-26


Grow

if (checkfinalenemy)
{
if (digit == 0)
{
enemyfY += 3;
}
else
{
enemyfY -= 3;
}
if (enemyfY >= 23)
{
enemyfY = 2;
}
if (enemyfY <= 2)
{
enemyfY = 23;
}
printfinalenemy();
}
}
}
void movefinalplayerup()
{
if (getCharAtxy(playerfX, playerfY - 1) != '#' && playerfY > 2)
{
eraseplayerfinal();
playerfY -= 1;
printplayerfinal();
}
}
Anas Faiz 2023-CS-26
Grow

void movefinalplayerdown()
{
if (getCharAtxy(playerfX, playerfY + 1) != '#' && playerfY < 23) //== ' ' &&
getCharAtxy(pX - 2, pY + 1) == ' ' && getCharAtxy(pX - 2, pY + 2) == ' ')
{
eraseplayerfinal();
playerfY = playerfY + 1;
printplayerfinal();
}
}

Anas Faiz 2023-CS-26

You might also like