Untitled 1
Untitled 1
#include <conio.h>
#include <windows.h>
#include <time.h>
#define DINO_POS 2
#define HURDLE_POS 74
int dinoY = 0;
int speed = 40;
int gameover = 0;
void init() {
system("cls");
gameover = 0;
gotoxy(3, 2);
cout << "SCORE: ";
for (int i = 0; i < 79; i++) {
gotoxy(1 + i, 1);
cout << "=";
gotoxy(1 + i, 25);
cout << "=";
}
}
if (jump == 0) dinoY = 0;
else if (jump == 2) dinoY--;
else dinoY++;
for (int i = 0; i < 10; i++) {
gotoxy(DINO_POS, 15 - dinoY + i);
cout << " ";
}
gotoxy(DINO_POS, 15 - dinoY);
cout << " ÜÛÛÛÛÜ";
gotoxy(DINO_POS, 16 - dinoY);
cout << " ÛÛÛÛÛÛ";
gotoxy(DINO_POS, 17 - dinoY);
cout << " ÛÛÛÛßßß";
gotoxy(DINO_POS, 18 - dinoY);
cout << " ÜÛÛÛÛÛÛÜÜ";
gotoxy(DINO_POS, 19 - dinoY);
if (jump == 1 || jump == 2) {
cout << " ÛÛÛÛÛß ßÛ";
gotoxy(DINO_POS, 20 - dinoY);
cout << " ÛÛ ";
} else if (foot == 0) {
cout << " ßÛÜß ßÛ";
gotoxy(DINO_POS, 20 - dinoY);
cout << " ÛÛ ";
foot = !foot;
} else {
cout << " ßÛÜ ßÜ ";
gotoxy(DINO_POS, 20 - dinoY);
cout << " ÛÛ ";
foot = !foot;
}
gotoxy(DINO_POS, 25 - dinoY);
if (jump == 0) {
cout << "============";
} else {
cout << " ";
}
Sleep(speed);
}
void drawHurdle() {
static int hurdleX = 0;
static int score = 0;
score = 0;
speed = 40;
gotoxy(36, 8);
cout << "GAME OVER!";
getch();
gameover = 1;
return;
}
hurdleX++;
if (hurdleX == 73) {
hurdleX = 0;
score++;
gotoxy(11, 2);
cout << score;
if (speed > 20) speed--;
}
}
void play() {
system("cls");
char ch;
int i;
init();
while (true) {
while (!kbhit()) {
if (gameover == 1) return;
moveDino();
drawHurdle();
}
ch = getch();
if (ch == 32) {
i = 0;
while (i < 12) {
moveDino(1);
drawHurdle();
i++;
}
while (i > 0) {
moveDino(2);
drawHurdle();
i--;
}
} else if (ch == 'p' || ch == 'P') {
getch();
} else if (ch == 27) {
break;
}
}
}
void instruction() {
system("cls");
cout << "Instructions\n";
cout << "--------------------\n";
cout << "1. Avoid hurdles by jumping.\n";
cout << "2. Press Spacebar to jump.\n";
cout << "3. Press P to pause the game.\n";
cout << "4. Press ESC to quit the game.\n";
cout << "Press any key to return to the menu.";
getch();
}
int main() {
setcursor(0, 0);
do {
system("cls");
gotoxy(10, 5);
cout << "-----------------------------";
gotoxy(10, 6);
cout << "|--------- Go Dino ---------|";
gotoxy(10, 7);
cout << "-----------------------------";
gotoxy(10, 9);
cout << "1. Start Game";
gotoxy(10, 10);
cout << "2. Instructions";
gotoxy(10, 11);
cout << "3. Quit";
gotoxy(10, 13);
cout << "Select Option: ";
char op = getch();
if (op == '1') {
play();
} else if (op == '2') {
instruction();
} else if (op == '3') {
exit(0);
} else {
gotoxy(10, 15);
cout << "Invalid option! Try again.";
Sleep(1000);
}
} while (1);
return 0;
}