Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- //http://dis.4chan.org/read/prog/1374070050/1-40
- void setcolor(unsigned short color)
- {
- HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hcon,color);
- }
- using namespace std;
- int Gamespeed = 100;
- int Level = 1;
- int menu = 0;
- int Hp = 1;
- int MaxHp = 100;
- int randnum;
- int key;
- string input;
- bool stopgame = false;
- bool running = true;
- char Map[10][10] = {"#########",
- "# # #",
- "# # # # #",
- "# # # # #",
- "#+# # #+#",
- "# # # # #",
- "# # # # #",
- "# # # # #",
- "#@# * # #",
- "#######-#"};
- char Map2[18][40] = {
- "#####################################-#",
- "#@ # # # * * # # #",
- "# ###### # #++# # # * * + * # # # #",
- "# ## # # #### # # * # # # #",
- "# # # # # # ## #******* # # #",
- "###### ##### #### # # # #####",
- "# # # ## # ******# #",
- "# ########## #### # ## #### #",
- "# #****** #* #",
- "##### ############ ## # #* #",
- "# ## ## # ******#**** #",
- "# ## +++ ####### # #* #",
- "# # ####### ######## #* ***#",
- "# # ####### * * * #",
- "# ## * * * * * * * #",
- "# ### * * * * * * * * * #",
- "#++ +### * * * * #",
- "#######################################"};
- char Map3[18][40] = {
- "#######################################",
- "#@ # # #********## # #",
- "########## # # # # # ####",
- "# # #+# ###### # # #",
- "###### ##### ### # # # #### #",
- "# # # # #",
- "# ###### # #####********########## ####",
- "# # # # #",
- "########## # # *## *## #",
- "#++++# # ######::###### *## *## #",
- "#++++# ### # # #",
- "####### ###### ######**####",
- "# # # K#",
- "# ******** # #**********#",
- "# ******** ######::###### +++ #",
- "# ******** # # +++ #",
- "# # # #",
- "####################--#################"};
- char Map4[18][40] = {
- "########### ###########",
- "#@ # #*********#",
- "# ###################*********#",
- "# *****#",
- "# ###################*** *****#",
- "########### # # ##### ######",
- " #K# # # # # ####### # # #",
- " #*# # ##### # # # # # # ###### #",
- " #*# # # ##### ### # # #",
- " #*# # ##### ### ##############",
- " #*# ##### ##### ####### #",
- " #*# # # ########## ####",
- "##*############### ##### #####",
- "#* *******###################**** #",
- "#* * * ******* #",
- "#** * * * ########:::######## ******* #",
- "#** * # # # # #",
- "########### #---# ###########"};
- void m1()
- {
- for (int y = 0; y < 10; y++)
- {
- for (int x = 0; x < 10; x++)
- {
- switch(Map[y][x])
- {
- //let make it look cooler
- case '#':
- {
- //we gonna use ascii characters
- Map[y][x] = 219;
- }
- case '@':
- {
- if (GetAsyncKeyState(VK_UP) != 0)
- {
- int y2 = (y-1);
- switch(Map[y2][x])
- {
- case ' ':
- {
- Map[y][x] = ' ';
- y -= 1;
- Map[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 2;
- }break;
- case '*':
- {
- Hp -= 5;
- Map[y][x] = ' ';
- y -= 1;
- Map[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map[y][x] = ' ';
- y -= 1;
- Map[y2][x] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_DOWN) != 0)
- {
- int y2 = (y+1);
- switch(Map[y2][x])
- {
- case ' ':
- {
- Map[y][x] = ' ';
- y += 1;
- Map[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 2;
- }break;
- case '*':
- {
- Hp -= 5;
- Map[y][x] = ' ';
- y += 1;
- Map[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map[y][x] = ' ';
- y += 1;
- Map[y2][x] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_LEFT) != 0)
- {
- int x2 = (x-1);
- switch(Map[y][x2])
- {
- case ' ':
- {
- Map[y][x] = ' ';
- x -= 1;
- Map[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 2;
- }break;
- case '*':
- {
- Hp -= 5;
- Map[y][x] = ' ';
- x -= 1;
- Map[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map[y][x] = ' ';
- x -= 1;
- Map[y][x2] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_RIGHT) != 0)
- {
- int x2 = (x+1);
- switch(Map[y][x2])
- {
- case ' ':
- {
- Map[y][x] = ' ';
- x += 1;
- Map[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 2;
- }break;
- case '*':
- {
- Hp -= 5;
- Map[y][x] = ' ';
- x += 1;
- Map[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map[y][x] = ' ';
- x += 1;
- Map[y][x2] = '@';
- }break;
- }
- }
- }break;
- }
- }
- }
- }
- void m2()
- {
- for (int y = 0; y < 18; y++)
- {
- for (int x = 0; x < 40; x++)
- {
- switch(Map2[y][x])
- {
- //let make it look cooler
- case '#':
- {
- //we gonna use ascii characters
- Map2[y][x] = 219;
- }
- case '@':
- {
- if (GetAsyncKeyState(VK_UP) != 0)
- {
- int y2 = (y-1);
- switch(Map2[y2][x])
- {
- case ' ':
- {
- Map2[y][x] = ' ';
- y -= 1;
- Map2[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 3;
- }break;
- case '*':
- {
- Hp -= 5;
- Map2[y][x] = ' ';
- y -= 1;
- Map2[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map2[y][x] = ' ';
- y -= 1;
- Map2[y2][x] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_DOWN) != 0)
- {
- int y2 = (y+1);
- switch(Map2[y2][x])
- {
- case ' ':
- {
- Map2[y][x] = ' ';
- y += 1;
- Map2[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 3;
- }break;
- case '*':
- {
- Hp -= 5;
- Map2[y][x] = ' ';
- y += 1;
- Map2[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map2[y][x] = ' ';
- y += 1;
- Map2[y2][x] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_LEFT) != 0)
- {
- int x2 = (x-1);
- switch(Map2[y][x2])
- {
- case ' ':
- {
- Map2[y][x] = ' ';
- x -= 1;
- Map2[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 3;
- }break;
- case '*':
- {
- Hp -= 5;
- Map2[y][x] = ' ';
- x -= 1;
- Map2[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map2[y][x] = ' ';
- x -= 1;
- Map2[y][x2] = '@';
- }break;
- }
- }
- if (GetAsyncKeyState(VK_RIGHT) != 0)
- {
- int x2 = (x+1);
- switch(Map2[y][x2])
- {
- case ' ':
- {
- Map2[y][x] = ' ';
- x += 1;
- Map2[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 3;
- }break;
- case '*':
- {
- Hp -= 5;
- Map2[y][x] = ' ';
- x += 1;
- Map2[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map2[y][x] = ' ';
- x += 1;
- Map2[y][x2] = '@';
- }break;
- }
- }
- }break;
- }
- }
- }
- }
- void m3()
- {
- for (int y = 0; y < 18; y++)
- {
- for (int x = 0; x < 40; x++)
- {
- switch(Map3[y][x])
- {
- //let make it look cooler
- case '#':
- {
- //we gonna use ascii characters
- Map3[y][x] = 219;
- }
- case '@':
- {
- if (GetAsyncKeyState(VK_UP) != 0)
- {
- int y2 = (y-1);
- switch(Map3[y2][x])
- {
- case ' ':
- {
- Map3[y][x] = ' ';
- y -= 1;
- Map3[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 4;
- }break;
- case '*':
- {
- Hp -= 5;
- Map3[y][x] = ' ';
- y -= 1;
- Map3[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map3[y][x] = ' ';
- y -= 1;
- Map3[y2][x] = '@';
- }break;
- case 'K':
- {
- key = 1;
- Map3[y][x] = ' ';
- y -= 1;
- Map3[y2][x] = '@';
- }break;
- case ':':
- {
- if (key >= 1)
- {
- Map3[y][x] = ' ';
- y -= 1;
- Map3[y2][x] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_DOWN) != 0)
- {
- int y2 = (y+1);
- switch(Map3[y2][x])
- {
- case ' ':
- {
- Map3[y][x] = ' ';
- y += 1;
- Map3[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 4;
- }break;
- case '*':
- {
- Hp -= 5;
- Map3[y][x] = ' ';
- y += 1;
- Map3[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map3[y][x] = ' ';
- y += 1;
- Map3[y2][x] = '@';
- }break;
- case 'K':
- {
- key = 1;
- Map3[y][x] = ' ';
- y += 1;
- Map3[y2][x] = '@';
- }break;
- case ':':
- {
- if (key >= 1)
- {
- Map3[y][x] = ' ';
- y += 1;
- Map3[y2][x] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_LEFT) != 0)
- {
- int x2 = (x-1);
- switch(Map3[y][x2])
- {
- case ' ':
- {
- Map3[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 4;
- }break;
- case '*':
- {
- Hp -= 5;
- Map3[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map3[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }break;
- case 'K':
- {
- key = 1;
- Map3[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }break;
- case ':':
- {
- if (key >= 1)
- {
- Map3[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_RIGHT) != 0)
- {
- int x2 = (x+1);
- switch(Map3[y][x2])
- {
- case ' ':
- {
- Map3[y][x] = ' ';
- x += 1;
- Map3[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 4;
- }break;
- case '*':
- {
- Hp -= 5;
- Map3[y][x] = ' ';
- x += 1;
- Map3[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map3[y][x] = ' ';
- x += 1;
- Map3[y][x2] = '@';
- }break;
- case 'K':
- {
- key = 1;
- Map3[y][x] = ' ';
- x += 1;
- Map3[y][x2] = '@';
- }break;
- case ':':
- {
- if (key >= 1)
- {
- Map3[y][x] = ' ';
- x += 1;
- Map3[y][x2] = '@';
- }
- }break;
- }
- }
- }break;
- }
- }
- }
- }
- void m4()
- {
- for (int y = 0; y < 18; y++)
- {
- for (int x = 0; x < 40; x++)
- {
- switch(Map4[y][x])
- {
- //let make it look cooler
- case '#':
- {
- //we gonna use ascii characters
- Map4[y][x] = 219;
- }
- case '@':
- {
- if (GetAsyncKeyState(VK_UP) != 0)
- {
- int y2 = (y-1);
- switch(Map4[y2][x])
- {
- case ' ':
- {
- Map4[y][x] = ' ';
- y -= 1;
- Map4[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 5;
- }break;
- case '*':
- {
- Hp -= 5;
- Map4[y][x] = ' ';
- y -= 1;
- Map4[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map4[y][x] = ' ';
- y -= 1;
- Map4[y2][x] = '@';
- }break;
- case 'K':
- {
- key = 2;
- Map4[y][x] = ' ';
- y -= 1;
- Map4[y2][x] = '@';
- }break;
- case ':':
- {
- if (key >= 2)
- {
- Map4[y][x] = ' ';
- y -= 1;
- Map4[y2][x] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_DOWN) != 0)
- {
- int y2 = (y+1);
- switch(Map4[y2][x])
- {
- case ' ':
- {
- Map4[y][x] = ' ';
- y += 1;
- Map4[y2][x] = '@';
- }break;
- case '-':
- {
- Level = 5;
- }break;
- case '*':
- {
- Hp -= 5;
- Map4[y][x] = ' ';
- y += 1;
- Map4[y2][x] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map4[y][x] = ' ';
- y += 1;
- Map4[y2][x] = '@';
- }break;
- case 'K':
- {
- key = 2;
- Map4[y][x] = ' ';
- y += 1;
- Map4[y2][x] = '@';
- }break;
- case ':':
- {
- if (key >= 2)
- {
- Map4[y][x] = ' ';
- y += 1;
- Map4[y2][x] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_LEFT) != 0)
- {
- int x2 = (x-1);
- switch(Map4[y][x2])
- {
- case ' ':
- {
- Map4[y][x] = ' ';
- x -= 1;
- Map4[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 5;
- }break;
- case '*':
- {
- Hp -= 5;
- Map4[y][x] = ' ';
- x -= 1;
- Map4[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map4[y][x] = ' ';
- x -= 1;
- Map3[y][x2] = '@';
- }break;
- case 'K':
- {
- key = 2;
- Map4[y][x] = ' ';
- x -= 1;
- Map4[y][x2] = '@';
- }break;
- case ':':
- {
- if (key >= 2)
- {
- Map4[y][x] = ' ';
- x -= 1;
- Map4[y][x2] = '@';
- }
- }break;
- }
- }
- if (GetAsyncKeyState(VK_RIGHT) != 0)
- {
- int x2 = (x+1);
- switch(Map4[y][x2])
- {
- case ' ':
- {
- Map4[y][x] = ' ';
- x += 1;
- Map4[y][x2] = '@';
- }break;
- case '-':
- {
- Level = 5;
- }break;
- case '*':
- {
- Hp -= 5;
- Map4[y][x] = ' ';
- x += 1;
- Map4[y][x2] = '@';
- }break;
- case '+':
- {
- Hp += 5;
- Map4[y][x] = ' ';
- x += 1;
- Map4[y][x2] = '@';
- }break;
- case 'K':
- {
- key = 2;
- Map4[y][x] = ' ';
- x += 1;
- Map4[y][x2] = '@';
- }break;
- case ':':
- {
- if (key >= 2)
- {
- Map4[y][x] = ' ';
- x += 1;
- Map4[y][x2] = '@';
- }
- }break;
- }
- }
- }break;
- }
- }
- }
- }
- void gameover()
- {
- if (Hp <= 0)
- {
- setcolor(12);
- cout << "\n\n\n###########\n";
- cout << "#GAME OVER#\n";
- cout << "###########\n";
- setcolor(7);
- system("pause >nul");
- }
- }
- void stat()
- {
- cout << "KEY: " << key << "\n";
- cout << "\n\nHP: ";
- setcolor(10); cout << Hp;
- setcolor(7);
- cout << " / ";
- setcolor(12); cout << MaxHp << endl;
- setcolor(7);
- setcolor(10);
- cout << "Level: " << Level;
- setcolor(7);
- Sleep(Gamespeed);
- }
- int main()
- {
- while(stopgame == false && menu == 0)
- {
- menu:
- system("cls");
- setcolor(202);
- cout << "######################################\n";
- cout << "# #\n";
- cout << "# MENU #\n";
- cout << "# #\n";
- cout << "# 1. Start Game #\n";
- cout << "# 2. Level Select #\n";
- cout << "# 3. Instructions #\n";
- cout << "# 4. EXIT #\n";
- cout << "# #\n";
- cout << "# #\n";
- cout << "######################################\n\n";
- setcolor(7);
- cout << "Enter a choise: "; setcolor(10); cin >> input; setcolor(7);
- if(input == "1")
- {
- input.clear();
- goto lvl1;
- }
- if(input == "2")
- {
- input.clear();
- goto lvlselect;
- }
- if(input == "3")
- {
- input.clear();
- goto lvl1;
- }
- if(input == "4")
- {
- input.clear();
- return 0;
- }
- else
- {
- setcolor(10);
- cout << input;
- cout << " is not an option. Try again...\n";
- setcolor(7);
- system("pause >nul");
- input.clear();
- goto menu;
- }
- }
- lvlselect:
- system("cls");
- setcolor(202);
- cout << "#############################################\n";
- cout << "# #\n";
- cout << "# LevelSelect #\n";
- cout << "# #\n";
- cout << "# 1. level1 5. level5 10. level10 #\n";
- cout << "# 2. level2 6. level6 11. level11 #\n";
- cout << "# 3. level3 7. level7 12. level12 #\n";
- cout << "# 4. level4 8. level8 13. level13 #\n";
- cout << "# 5. level5 9. level9 14. level14 #\n";
- cout << "# #\n";
- cout << "# R - Return to main #\n";
- cout << "#############################################\n\n";
- setcolor(7);
- cout << "Enter a choise: "; setcolor(10); cin >> input; setcolor(7);
- if(input == "1")
- {
- input.clear();
- goto lvl1;
- }
- if(input == "2")
- {
- input.clear();
- goto lvl2;
- }
- if(input == "3")
- {
- input.clear();
- goto lvl3;
- }
- if(input == "4")
- {
- input.clear();
- goto lvl4;
- }
- if(input == "5")
- {
- input.clear();
- goto lvl5;
- }
- if(input == "R" | input == "r")
- {
- input.clear();
- goto menu;
- }
- else
- {
- setcolor(10);
- cout << input;
- cout << " is not an option. Try again...\n";
- setcolor(7);
- system("pause >nul");
- input.clear();
- goto lvlselect;
- }
- while(stopgame == false && Level == 1)
- {
- lvl1:
- Level = 1;
- system("cls");
- gameover();
- for(int y = 0; y < 10; y++)
- {
- cout << Map[y] << endl;
- }
- stat();
- m1();
- }
- while(stopgame == false && Level == 2)
- {
- lvl2:
- Level = 2;
- system("cls");
- gameover();
- for(int y = 0; y < 18; y++)
- {
- cout << Map2[y] << endl;
- }
- stat();
- m2();
- }
- while(stopgame == false && Level == 3)
- {
- lvl3:
- Level = 3;
- system("cls");
- gameover();
- for(int y = 0; y < 18; y++)
- {
- cout << Map3[y] << endl;
- }
- stat();
- m3();
- }
- while(stopgame == false && Level == 4)
- {
- lvl4:
- Level = 4;
- system("cls");
- gameover();
- for(int y = 0; y < 18; y++)
- {
- cout << Map4[y] << endl;
- }
- stat();
- m4();
- }
- while(stopgame == false && Level == 5)
- {
- lvl5:
- Level = 5;
- system("cls");
- gameover();
- for(int y = 0; y < 18; y++)
- {
- cout << Map4[y] << endl;
- }
- stat();
- m4();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment