Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- #include <conio.h>
- #include "maps.h"
- #include <ctime>
- using std::ofstream;
- using std::ifstream;
- using std::cout;
- using std::endl;
- using std::cin;
- using std::cerr;
- using std::string;
- class infinite
- {
- public:
- friend class maps;
- infinite();
- ~infinite();
- void drawMap(char amap[20][50]);
- void moves();
- void gotoxy(int x, int y);
- void moves(char map[20][50]);
- void ask();
- void checkClose();
- void choose_level();
- void level1_data();
- void level2_data();
- void level3_data();
- void shop();
- void sp(int choosecolor);
- void stdcolor();
- void reset();
- void instructions();
- void ClearScreen();
- void cursor();
- void choose_character();
- int checkLevelUnlockedVar;
- protected:
- unsigned int gamespeed;
- int gamerunning;
- int health;
- bool treasureopen;
- bool dooropen;
- bool passtreasure;
- int coins;
- int lastlevel;
- int level;
- bool speed_potion_bought;
- bool health_potion_bought;
- int howmanyhealth;
- int howmanyspeed;
- bool islevel3;
- int i, j;///bomb
- int a, b;///chance
- int c, d;///finish line
- int r, t;///shoot
- int chance;
- int speed_uses;
- bool finishline_drew;
- int s, z;
- bool wallbreaker;
- int howmanywallbreaker;
- bool drawingPermission;
- public:
- static const char p = 3;
- static const char health8[8];
- static const char health7[7];
- static const char health6[6];
- static const char health5[5];
- static const char health4[4];
- static const char health3[3];
- static const char health2[2];
- static const char health1[1];
- };
- const char infinite::health8[8] = { p, p, p, p, p, p, p, p };
- const char infinite::health7[7] = { p, p, p, p, p, p, p };
- const char infinite::health6[6] = { p, p, p, p, p, p };
- const char infinite::health5[5] = { p, p, p, p, p };
- const char infinite::health4[4] = { p, p, p, p };
- const char infinite::health3[3] = { p, p, p };
- const char infinite::health2[2] = { p, p };
- const char infinite::health1[1] = { p };
- void infinite::choose_level()
- {
- system("cls");
- system("color 1a");
- cout << "\t\t\t\t\t CHOOSE YOUR LEVEL:" << endl;
- cout << "\t\t\t\t\t LEVEL 1" << endl
- << "\t\t\t\t\t LEVEL 2" << endl
- << "\t\t\t\t\t LEVEL 3" << endl << endl << endl;
- cout << "\t\t\t\t\t press 9 to enter shop" << endl;
- cout << "\t\t\t\t\t press 0 to close" << endl
- << "\t\t\t\t\t press 10 to see how to play (recommended) \n";
- int choice;
- cout << "\t\t\t\t\t ";
- cin >> choice;
- switch (choice)
- {
- case 1:
- system("cls");
- level = 1;
- break;
- case 2:
- {
- system("cls");
- ifstream checkLevelUnlocked("clu.txt");
- checkLevelUnlocked >> checkLevelUnlockedVar;
- if (checkLevelUnlockedVar >= 2)
- {
- level = 2;
- }
- else
- {
- cout << "Level Locked" << endl;
- }
- break;
- }
- case 3:
- system("cls");
- level = 3;
- break;
- case 9:
- system("cls");
- shop();
- break;
- case 0:
- cout << "saving..." << endl;
- Sleep(2000);
- gamerunning = false;
- break;
- case 10:
- instructions();
- break;
- }
- }
- void infinite::checkClose()
- {
- if (health == 0 || health < 0){
- gamerunning = false;
- cout << endl << "you died ! " << endl;
- system("pause");
- }
- if (GetAsyncKeyState(VK_ESCAPE))
- {
- gotoxy(20, 26);
- cout << "saving..." << endl;
- Sleep(2000);
- ofstream coinsSave_out;
- coinsSave_out.open("coins.dat");
- coinsSave_out << coins;
- coinsSave_out.close();
- gamerunning = false;
- }
- if (GetAsyncKeyState(VK_SPACE) != 0)
- {
- cout << '\n' << "Game Paused" << endl;
- system("pause");
- system("cls");
- }
- }
- void infinite::gotoxy(int x, int y)
- {
- HANDLE h;
- h = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(h, coord);
- }
- void infinite::drawMap(char amap[][50])
- {
- ifstream coinsSave_in;
- coinsSave_in.open("coins.dat");
- coinsSave_in >> coins;
- coinsSave_in.close();
- cout << endl;
- for (int y = 0; y<20; y++)
- {
- cout << amap[y] << endl;
- }
- gotoxy(52, 5);
- cout << "Press space to PAUSE" << endl;
- gotoxy(52, 7);
- cout << "Press ESC to quit" << endl;
- gotoxy(0, 23);
- cout << "Health : ";
- switch (health)
- {
- case 1:
- for (int i = 0; i<1; i++)
- {
- cout << health1[i];
- }
- break;
- case 2:
- for (int i = 0; i<2; i++)
- cout << health2[i];
- break;
- case 3:
- for (int i = 0; i<3; i++)
- cout << health3[i];
- break;
- case 4:
- for (int i = 0; i<4; i++)
- cout << health4[i];
- break;
- case 5:
- for (int i = 0; i<5; i++){
- cout << health5[i];
- }
- break;
- case 6:
- for (int i = 0; i<6; i++)
- cout << health6[i];
- break;
- case 7:
- for (int i = 0; i<7; i++)
- cout << health7[i];
- break;
- case 8:
- for (int i = 0; i<8; i++)
- cout << health8[i];
- break;
- }
- }
- void infinite::ask()
- {
- gotoxy(30, 24);
- cout << "2+2*4+2/2+2 = ";
- int answer;
- cin >> answer;
- cout << endl;
- if (answer == 13)
- {
- treasureopen = true;
- gotoxy(30, 25);
- cout << "correct answer ! i will open the door for you !!" << endl;
- system("cls");
- drawMap(maps::mem_amap);
- system("color 1a");
- _getch();
- }
- else if (answer != 13)
- {
- cout << "incorrect answer!" << endl
- << "the door will stay locked and you will restart the level !" << endl;
- gamerunning = false;
- }
- }
- void infinite::shop()
- {
- using std::cerr;
- using std::ios;
- shop:
- ifstream shop_coins;
- shop_coins.open("coins.dat", ios::in);
- shop_coins >> coins;
- system("cls");
- cout << "coins:" << coins << "." << endl;
- cout << "\t\t\t SHOP :" << endl;
- cout << "1)health potion $50 Use it with F2 key." << endl;
- cout << "2) speed potion $60 Use it with F1 key." << endl;
- cout << "3) wallbreaker $200" << endl;
- cout << "4) back" << endl;
- ifstream health_in("health.dat");
- health_in >> howmanyhealth;
- ifstream speed_in("speed.dat");
- speed_in >> howmanyspeed;
- ifstream wallbreaker_in("wallbreaker.dat");
- wallbreaker_in >> howmanywallbreaker;
- cout << "\n\n you have " << howmanyhealth << " health potions" << endl;
- cout << "\n you have " << howmanyspeed << " speed potions" << endl;
- cout << "\n you have " << howmanywallbreaker << " wallbreakers" << endl;
- int shop_choice;
- cout << " ";
- cin >> shop_choice;
- switch (shop_choice)
- {
- case 1:
- if (coins <= 0)coins = 0;
- if (coins > 50 || coins == 50){
- coins -= 50;
- ofstream shop_coins_out;
- shop_coins_out.open("coins.dat");
- shop_coins_out << coins;
- health_potion_bought = true;
- howmanyhealth++;
- ofstream shop_health_out;
- shop_health_out.open("health.dat");
- shop_health_out << howmanyhealth;
- shop_health_out.close();
- }
- else
- {
- cout << "you don 't have enough money" << endl;
- }
- goto shop;
- break;
- }
- if (shop_choice == 2)
- {
- if (coins <= 0) coins = 0;
- if (coins >= 50){
- coins -= 50;
- ofstream shop_coins_out;
- shop_coins_out.open("coins.dat");
- shop_coins_out << coins;
- speed_potion_bought = true;
- howmanyspeed++;
- ofstream shop_speed_out;
- shop_speed_out.open("speed.dat");
- shop_speed_out << howmanyspeed;
- shop_speed_out.close();
- goto shop;
- }
- else
- {
- cerr << "you don 't have enough money" << endl;
- }
- }
- if (shop_choice == 3)
- {
- if (coins <= 0)coins = 0;
- if (coins > 200 || coins == 200){
- coins -= 200;
- ofstream shop_coins_out("coins.dat");
- shop_coins_out << coins;
- shop_coins_out.close();
- wallbreaker = true;
- howmanywallbreaker++;
- ofstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out << howmanywallbreaker;
- shop_wallbreaker_out.close();
- goto shop;
- }
- }
- if (shop_choice == 4)
- {
- choose_level();
- }
- }
- infinite::infinite()
- {
- gamerunning = true;
- reset();
- choose_level();
- if (level == 1)
- level1_data();
- if (level == 2)
- level2_data();
- if (level == 3)
- level3_data();
- }
- infinite::~infinite()
- {
- cout << "BYE BYE !" << endl;
- }
- void infinite::moves(char map[20][50])
- {
- for (int y = 0; y<20; y++)
- {
- for (int x = 0; x<50; x++)
- {
- switch (map[y][x])
- {
- case '#':
- {
- map[y][x] = char(219);
- }break;
- case 'X':
- {
- map[y][x] = char(177);
- }break;
- case 'M':
- map[y][x] = char(2);
- break;
- case '*':
- map[y][x] = char(15);
- break;
- case '@':
- map[y][x] = char(1);
- break;
- case '=':
- map[y][x] = char(4);
- break;
- case 'j':
- map[y][x] = char(255);///invisible, used to define "if region reached"
- break;
- case 'v':
- map[y][x] = char(234);///ohmique
- break;
- case char(1) :
- {
- if (GetAsyncKeyState(VK_LSHIFT) != 0)
- if (drawingPermission)
- {
- int u, o;
- u = (y - 1);
- o = x;
- map[y][x] = char(1);
- map[u][o] = char(176);
- }
- if (health <= 3){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY); }
- if (health > 3){ system("color 1a"); }
- if (islevel3)
- if (chance == 5){
- if (finishline_drew == false){
- srand(static_cast<unsigned int> (time(NULL)));
- c = rand() % 14 + 4;
- d = rand() % 44 + 4;
- map[c + 1][d + 1] = '!';
- if (map[c + 1][d + 1] == char(219)){ map[c + 1][d + 1] = ' '; map[c - 3][d - 2] = '!'; }///if random is on line
- cout << "find the finish line fast " << endl;
- finishline_drew = true;
- }
- }
- if (islevel3)
- {
- srand(static_cast<unsigned int> (time(NULL)));
- a = rand() % 14 + 4;
- b = rand() % 44 + 4;
- i = rand() % 14 + 4;
- j = rand() % 44 + 4;
- map[i][j] = char(15);///bomb
- map[a][b] = char(6);///chance
- }
- using std::cerr;
- if (GetAsyncKeyState(VK_F2) != 0)///health
- {
- ifstream shop_health_in;
- shop_health_in.open("health.dat");
- shop_health_in >> howmanyhealth;
- if (howmanyhealth > 0)
- {
- health_potion_bought = true;
- if (health_potion_bought == true && howmanyhealth > 0)
- {
- if (howmanyhealth == 0 || howmanyhealth < 0 || !health_potion_bought)
- {
- cerr << "you don 't have health potion anymore" << endl;
- }
- else if (howmanyhealth > 0 && health < 5)
- {
- if (health > 5)health = 5;
- health += 1;
- howmanyhealth--;
- ofstream shop_health_out;
- shop_health_out.open("health.dat");
- shop_health_out << howmanyhealth;
- shop_health_out.close();
- }
- if (health >= 5)
- {
- cout << endl << endl;
- health = 5;
- cout << "your health is full" << endl;
- system("cls");
- }
- }
- else if (!health_potion_bought)
- cerr << "you don 't have a health potion" << endl;
- system("cls");
- }
- }
- if (GetAsyncKeyState(VK_F1) != 0)///speed
- {
- if (GetAsyncKeyState(VK_F1) != 0 && speed_uses == 2)
- {
- cout << "\n you can 't use speed potion anymore" << endl;
- }
- else if (speed_uses < 2){
- ifstream shop_speed_in;
- shop_speed_in.open("speed.dat");
- shop_speed_in >> howmanyspeed;
- if (howmanyspeed > 0)
- {
- speed_potion_bought = true;
- if (speed_potion_bought == false)
- {
- cout << "you don 't have a speed potion" << endl;
- }
- if (speed_potion_bought == true && howmanyspeed > 0)
- {
- gamespeed -= 50;
- speed_uses++;
- howmanyspeed--;
- ofstream shop_speed_out;
- shop_speed_out.open("speed.dat");
- shop_speed_out << howmanyspeed;
- shop_speed_out.close();
- }
- }
- }
- }
- if (GetAsyncKeyState(VK_UP) != 0)
- {
- int y2 = (y - 1);
- switch (map[y2][x])
- {
- case ' ':
- {
- map[y][x] = ' ';
- y -= 1;
- map[y2][x] = char(1);
- }break;
- case '!':
- {
- system("pause");
- gamerunning = false;
- }break;
- case char(15) :///bomb
- {
- if (islevel3){
- health = 0;
- }
- health -= 2;
- system("cls");
- map[y][x] = ' ';
- y -= 1;
- map[y2][x] = char(1);
- }break;
- case '^':
- {
- treasureopen = true;
- map[y][x] = ' ';
- y -= 1;
- map[y2][x] = char(1);
- }break;
- case '-':
- {
- if (treasureopen == false)
- {
- gotoxy(24, 16);
- cout << "go to the mage and answer his question" << endl;
- map[y][x] = ' ';
- map[y][x] = char(1);
- }
- else if (treasureopen == true)
- {
- map[y][x] = ' ';
- int y3 = (y - 2);
- y -= 2;
- map[y3][x] = char(1);
- passtreasure = true;
- }
- }break;
- case char(4) :/// coins
- {
- coins += 5;
- ofstream coins_out;
- coins_out.open("coins.dat");
- coins_out << coins;
- map[y][x] = ' ';
- y -= 1;
- map[y2][x] = char(1);
- }break;
- case char(6) :///chance
- {
- if (islevel3)
- {
- map[y][x] = ' ';
- y -= 1;
- chance++;
- map[y2][x] = char(1);
- }
- }break;
- case char(177) : {///inside wall
- if (GetAsyncKeyState(VK_F6) != 0)///wallbreaker
- {
- ifstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out >> howmanywallbreaker;
- if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
- {
- cerr << "you don 't have a wallbreaker" << endl;
- }
- if (howmanywallbreaker > 0)
- {
- wallbreaker = true;
- if (wallbreaker == true && howmanywallbreaker > 0)
- {
- map[y - 1][x] = ' ';
- howmanywallbreaker--;
- ofstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out << howmanywallbreaker;
- shop_wallbreaker_out.close();
- }
- }
- }
- }
- }
- }
- if (GetAsyncKeyState(VK_DOWN) != 0)
- {
- int y2 = (y + 1);
- switch (map[y2][x])
- {
- case ' ':
- {
- map[y][x] = ' ';
- y += 1;
- map[y2][x] = char(1);
- }break;
- case '!':
- {
- system("pause");
- gamerunning = false;
- }break;
- case char(15) :///bomb
- {
- if (islevel3)
- health = 0;
- health -= 2;
- system("cls");
- map[y][x] = ' ';
- y += 1;
- map[y2][x] = char(1);
- }break;
- case char(4) :
- {
- coins += 5;
- ofstream coins_out;
- coins_out.open("coins.dat");
- coins_out << coins;
- map[y][x] = ' ';
- y += 1;
- map[y2][x] = char(1);
- }break;
- case char(6) :
- {
- if (islevel3)
- {
- map[y][x] = ' ';
- y += 1;
- chance++;
- map[y2][x] = char(1);
- }
- }break;
- case char(177) : {///inside wall
- if (GetAsyncKeyState(VK_F6) != 0)
- {
- ifstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out >> howmanywallbreaker;
- if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
- {
- cerr << "you don 't have a wallbreaker" << endl;
- }
- if (howmanywallbreaker > 0)
- {
- wallbreaker = true;
- if (wallbreaker == true && howmanywallbreaker > 0)
- {
- map[y + 1][x] = ' ';
- howmanywallbreaker--;
- ofstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out << howmanywallbreaker;
- shop_wallbreaker_out.close();
- }
- }
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_RIGHT) != 0)
- {
- int x2 = (x + 1);
- switch (map[y][x2])
- {
- case ' ':
- {
- map[y][x] = ' ';
- x += 1;
- map[y][x2] = char(1);
- }break;
- case '!':
- {
- system("pause");
- gamerunning = false;
- }break;
- case char(15) :
- {
- if (islevel3)
- health = 0;
- health -= 2;
- system("cls");
- map[y][x] = ' ';
- x += 1;
- map[y][x2] = char(1);
- }break;
- case '|':
- {
- if (dooropen == false)
- {
- map[y][x] = ' ';
- map[y][x] = char(1);
- gotoxy(0, 22);
- cout << "find the key" << endl;
- }
- else if (dooropen == true)
- {
- map[y][x] = ' ';
- int x3 = (x + 2);
- x += 1;
- map[y][x3] = char(1);
- }break;
- case '<':
- {
- dooropen = true;
- map[y][x] = ' ';
- x += 1;
- map[y][x2] = char(1);
- }break;
- case char(4) :
- {
- coins += 5;
- ofstream coins_out;
- coins_out.open("coins.dat");
- coins_out << coins;
- map[y][x] = ' ';
- x += 1;
- map[y][x2] = char(1);
- }break;
- case char(6) :///chance
- {
- if (islevel3)
- {
- map[y][x] = ' ';
- x += 1;
- chance++;
- map[y][x2] = char(1);
- }
- }break;
- case char(177) : {///inside wall1
- if (GetAsyncKeyState(VK_F6) != 0)
- {
- ifstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out >> howmanywallbreaker;
- if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
- {
- cerr << "you don 't have a wallbreaker" << endl;
- }
- if (howmanywallbreaker > 0)
- {
- wallbreaker = true;
- if (wallbreaker == true && howmanywallbreaker > 0)
- {
- map[y][x + 1] = ' ';
- howmanywallbreaker--;
- ofstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out << howmanywallbreaker;
- shop_wallbreaker_out.close();
- }
- }
- }
- }break;
- case char(255) :
- {
- drawingPermission = true;
- map[y][x] = ' ';
- x += 1;
- map[y][x2] = char(1);
- }break;
- }
- }
- }
- if (GetAsyncKeyState(VK_LEFT))
- {
- int x2 = (x - 1);
- switch (map[y][x2])
- {
- case ' ':
- {
- map[y][x] = ' ';
- x -= 1;
- map[y][x2] = char(1);
- }
- break;
- case '!':
- {
- system("pause");
- gamerunning = false;
- }break;
- case char(15) :
- {
- if (islevel3)
- health = 0;
- health -= 2;
- system("cls");
- map[y][x] = ' ';
- x -= 1;
- map[y][x2] = char(1);
- }break;
- case '|':
- {
- map[y][x] = ' ';
- int x3 = (x - 2);
- x -= 1;
- map[y][x3] = char(1);
- }break;
- case ')':
- {
- if (treasureopen == false)
- {
- map[y][x] = ' ';
- map[y][x] = char(1);
- gotoxy(0, 21);
- cout << "find the second key" << endl;
- }
- else if (treasureopen == true)
- {
- map[y][x] = ' ';
- int x3 = (x - 3);
- x -= 3;
- map[y][x3] = char(1);
- }
- }break;
- case char(2) :
- {
- ask();
- }break;
- case char(4) :
- {
- coins += 5;
- ofstream coins_out;
- coins_out.open("coins.dat");
- coins_out << coins;
- coins_out.close();
- map[y][x] = ' ';
- x -= 1;
- map[y][x2] = char(1);
- }break;
- case char(6) :
- {
- if (islevel3)
- {
- map[y][x] = ' ';
- x -= 1;
- chance++;
- map[y][x2] = char(1);
- }
- }break;
- case char(177) : {///inside wall
- if (GetAsyncKeyState(VK_F6) != 0)
- {
- ifstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out >> howmanywallbreaker;
- if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
- {
- cerr << "you don 't have a wallbreaker" << endl;
- }
- if (howmanywallbreaker > 0)
- {
- wallbreaker = true;
- if (wallbreaker == true && howmanywallbreaker > 0)
- {
- map[y][x - 1] = ' ';
- howmanywallbreaker--;
- ofstream shop_wallbreaker_out("wallbreaker.dat");
- shop_wallbreaker_out << howmanywallbreaker;
- shop_wallbreaker_out.close();
- }
- }
- }
- }break;
- }
- }
- }
- }
- }
- }
- }
- void infinite::sp(int choosecolor)
- {
- HANDLE h;
- h = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h, choosecolor);
- }
- void infinite::stdcolor()
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
- }
- void infinite::reset()
- {
- howmanywallbreaker = 0;
- wallbreaker = false;
- s = z = 10;
- finishline_drew = false;
- speed_uses = 0;
- islevel3 = false;
- chance = 0;
- howmanyhealth = 0;
- howmanyspeed = 0;
- health_potion_bought = false;
- speed_potion_bought = false;
- coins = 0;
- passtreasure = false;
- gamerunning = true;
- gamespeed = 50;
- health = 8;
- treasureopen = false;
- dooropen = false;
- }
- void infinite::level1_data()
- {
- reset();
- while (gamerunning && level == 1)
- {
- cursor();
- cout << char(4) << " " << coins;
- cout << endl;
- drawMap(maps::mem_amap);
- moves(maps::mem_amap);
- checkClose();
- Sleep(gamespeed);
- }
- }
- void infinite::level2_data()
- {
- reset();
- gamerunning = true;
- memcpy(maps::mem_amap, maps::map2, sizeof(maps::mem_amap));
- while (gamerunning && level == 2)
- {
- cursor();
- cout << char(4) << " " << coins;
- drawMap(maps::mem_amap);
- moves(maps::mem_amap);
- checkClose();
- Sleep(gamespeed);
- }
- }
- void infinite::instructions()
- {
- system("cls");
- cout << "\t\t\t\t INSTRUCTIONS" << endl;
- cout << "\t\t\t\t ============ \n" << endl;
- system("color 1c");
- cout << " MOVES : UP - DOWN - LEFT - RIGHT Arrows \n" << endl
- << " THE : " << char(15) << " is a BOMB , if you step on it, you will loose 2 hearts \n" << endl
- << " THE : '!' is the finish line. You must reach it to pass the level \n" << endl
- << " THE : " << char(2) << " is the mage. Answer his question and see what he will give you \n" << endl
- << " THE : " << char(4) << " is a coin.each " << char(4) << " will give you 5 coins. collect coins and buy variety of potion from the shop \n" << endl
- << " THE : '<' and '^' are keys. use them to open locked doors" << endl << endl << endl;
- system("pause");
- choose_level();
- }
- void infinite::level3_data()
- {
- memcpy(maps::mem_amap, maps::map3, sizeof(maps::mem_amap));
- gamerunning = true;
- system("cls");
- gotoxy(25, 25);
- cout << "THIS IS A SPECIAL LEVEL, COLLECT 20 COINS TO GET THE FINISH LINE. DON 'T HIT A BOMB OR YOU WILL DIE DIRECTLY!";
- gotoxy(25, 26);
- cout << "THE MORE FAST YOU ARE, YOU HAVE MORE CHANCES TO WIN THIS LEVEL...";
- gotoxy(25, 28);
- _getch();
- system("cls");
- while (gamerunning && level == 3)
- {
- cursor();
- islevel3 = true;
- cout << char(6) << " " << chance;
- drawMap(maps::mem_amap);
- moves(maps::mem_amap);
- checkClose();
- Sleep(gamespeed);
- }
- }
- void infinite::ClearScreen()
- {
- HANDLE hStdOut;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD count;
- DWORD cellCount;
- COORD homeCoords = { 0, 0 };
- hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- if (hStdOut == INVALID_HANDLE_VALUE) return;
- /* Get the number of cells in the current buffer */
- if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) return;
- cellCount = csbi.dwSize.X *csbi.dwSize.Y;
- /* Fill the entire buffer with spaces */
- if (!FillConsoleOutputCharacter(
- hStdOut,
- (TCHAR) ' ',
- cellCount,
- homeCoords,
- &count
- )) return;
- /* Fill the entire buffer with the current colors and attributes */
- if (!FillConsoleOutputAttribute(
- hStdOut,
- csbi.wAttributes,
- cellCount,
- homeCoords,
- &count
- )) return;
- /* Move the cursor home */
- SetConsoleCursorPosition(hStdOut, homeCoords);
- }
- void infinite::cursor()
- {
- HANDLE h;
- h = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD coord;
- coord.X = 0;
- coord.Y = 0;
- SetConsoleCursorPosition(h, coord);
- }
- int main()
- {
- system("color 1a");
- infinite *go;
- go = new infinite;
- go->choose_level();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement