New Text Document
New Text Document
#include<conio.h>
#include<time.h>
#include<ctime>
#include<iomanip>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<windows.h>
void Coins();
void movement();
void playGame();
void nameOfPlayer();
void mainMenu();
void gameplay();
void gameHistoryOnFile();
void gameHistoryInFile();
void loadGame();
void mainScreen();
string name;
char ch;
int n, turn = -1, inpt = 1;
bool win = false, flag = false;
char map[row][cols];
int main()
{
mainScreen();
loadGame();
mainMenu();
system("pause");
return 0;
}
void mainScreen() {
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tENDLESS";
Sleep(1000);
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tRUNNER";
Sleep(1000);
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tGAME!";
Sleep(1000);
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\tENDLESS RUNNER GAME!
";
system("pause");
system("cls");
}
void playGame() //playGame in the menu
{
nameOfPlayer();
while (life != 0)
{
if (win == true) {
break;
}
stage();
character();
print();
movement();
Coins();
::distance += 50;
colDist += 50;
Colors();
system("cls");
}
void gameplay()
{
cout << "1.The game will start with the player character running
automatically" << endl;
cout << "2.The player can control the character's movement by using
arrow keys jump,
sliding,left,right, forward, backward." << endl;
cout << endl;
cout << "left movement=left arrow key\n";
cout << "right movement=right arrow key\n";
cout << "forward movement=up arrow key\n";
cout << "backward movement= down arrow key\n";
cout << endl;
cout << "3.The player character will have three lives at the start of
the game, and they will lose a
life if they hit an obstacle." << endl;
cout << "4.The game will end when the player runs out of lives."
<< endl;
cout << "5.The player character will collect coins while running, and
the score will increase with
each coin collected." << endl;
cout << "6.The distance covered by the player character will be
measured, and the game's speed
will increase as the distance increases." << endl;
cout << "7.When the distance covered by the player character exceeds
2000 meters, a computer
player will be introduced in the game that will follow the player character and try
to collide with them."
<< endl;
cout << "8.The player cannot pass through the walls on the side."
<< endl;
cout << "\n || enter x to return to main menu ||
\n ";
do
{
cin >> ch;
} while (ch != 'x');
system("cls");
}
void loadGame() {
cout << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tLoading.";
Sleep(1000);
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tLoading..";
Sleep(1);
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\tLoading...";
Sleep(1000);
system("cls");
}
void mainMenu()
{
cout << " ------------------------------------- " << endl;
cout << "| 1- PLAY GAME |" << endl;
cout << "| 2- GAME PLAY |" << endl;
cout << "| 3- GAME HISTORY |" << endl;
cout << "| 4- EXIT |" << endl;
case'3':
system("cls");
gameHistoryInFile();
if (ch == 'x')
mainMenu();
break;
case'4':
system("cls");
system("pause");
cout << "thank you for playing the game ! " << endl;
return;
break;
default:
cout << "invalid character input , enter again " << endl;
}
}
void nameOfPlayer() //takes name of player
{
cout << "enter your name player " << endl;
cin >> name;
}
void stage()
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < cols; j++)
{
map[i][j] = ' ';
if (i == 0)
{
map[i][j] = '-';
}
if (i == 19)
{
map[i][j] = '-';
}
if (j == 0)
{
map[i][j] = '|';
}
if (j == 39)
{
map[i][j] = '|';
}
}
}
}
void Colors() {
if (colDist < 1000) {
system("Color 0E");
}
else if (colDist < 2000) {
system("Color 0A");
}
else if (colDist < 3000) {
system("Color 0B");
}
else if (colDist < 4000) {
system("Color 0C");
}
else if (colDist < 5000) {
system("Color 0D");
}
else if (colDist > 5000) {
colDist -= 5000;
}
}
void character()
{
for (int i = 0; i < 3; i++)
{
if (h_i[i] == x && h_j[i] == y)
{
life--;
h_i[i] = rand() % 20;
h_j[i] = rand() % 40;
}
}
if (h_j[i] == 40)
h_j[i] = 1;
if (h_i[i] == 20)
h_i[i] = rand() % 20;
if (cy < y)
{
cy++;
}
else if (cy > y)
{
cy--;
}
if (cx == x && cy == y)
{
life--;
cx = rand() % 20;
cy = rand() % 40;
}
}
map[x][y] = 'X';
map[x][y - 1] = '|';
map[x + 1][y] = '-';
map[x - 1][y] = '^';
map[x][y + 1] = '|';
c_i[i]++;
c_j[i];
if (c_j[i] == 40)
c_j[i] = 1;
if (c_i[i] == 20)
c_i[i] = rand() % 20;
else
{
cout << map[i][j];
}
}
cout << endl;
}
cout << " LIFES : " << life << " SCORE : "
<< score << " DISTANCE: " << ::distance << endl;
}
void movement()
{
char ch;
ch = _getch();
}
else if (int(ch) == 'P')//for down movement
{
if (x < 18)
{
x = x + 1;
}
}
else if (int(ch) == 'M')//for right movement
{
if (y < 37)
{
y = y + 1;
}
}
else if (int(ch) == 'K')//for left movement
{
if (y > 2)
{
y = y - 1;
}
}
void gameHistoryOnFile() //puts data in the file
{
ofstream fout;
fout.open("Endless runner Game History", ios::app);
if (!fout.is_open())
{
std::cout << "file not found \n";
return;
}
return;
}