Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <conio.h>
- using namespace std;
- void gotoxy(int x, int y);
- void setColour(int ink);
- void setConsoleSize(int rows, int columns);
- int main()
- {
- int BULLET_SPEED = 10;
- int ENEMY_SPEED = 50;
- int cyan = 0x0B;
- int white = 0x0F;
- int green = 0x0A;
- int red = 0x0C;
- int MAX_BULLETS = 30;
- int bulletX = 0;
- int bulletY = 0;
- int timer = BULLET_SPEED;
- bool Bulletalive = false;
- int numBullets = MAX_BULLETS;
- int enemyX = 3;
- int enemyY = 3;
- int enemyTimer = ENEMY_SPEED;
- int enemyAlive = true;
- char dirHorizontal = 'r';
- int hits = 0;
- char b = 232;
- char st = 153;
- char bt = 234;
- char slt = 2;
- char gm = 15;
- char em = 31;
- char el = 17;
- char er = 16;
- char ps = 24;
- char pm = 6;
- char pmj = 194;
- char q, ch1;
- char a = 221, bi=219;
- char bu = 15;
- char ms;
- const int MenuState = 0;
- const int MenuPlay = 1;
- const int MenuHelp = 2;
- const int MenuExit = 3;
- bool playing = true;
- char ch;
- int shipXPos = 39, shipYPos = 23;
- setConsoleSize(30, 89);
- system("title MAD SHOT");
- Beep(261,100);
- Beep(293,100);
- Beep(329,100);
- Beep(349,100);
- // this is just for the design, ignore it
- cout<<" *********** *********** 999999999999999 000000000000\n";
- Sleep(100);
- cout<<" **** ******* ******* **** 999999999999999 00 00\n";
- Sleep(100);
- cout<<" **** ******** ****** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** ******* ******* **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** ******* ******* **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** ************** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** ******** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** ****** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999 999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999999999999999 00 00\n";
- Sleep(100);
- cout<<" **** **** 999999999999999 00000000000\n";
- cout<<"\n\n PRESS ENTER TO PLAY";
- cin.ignore();
- for(q = 0; q<89; q++){
- cout<<a;
- Sleep(60);
- }
- system("CLS");
- // error starts from here
- MenuState ms=MenuPlay;
- char ch7=0;
- while (ch!='\r')
- {
- switch (ms)
- {
- case MenuPlay:
- cout<<"--> PLAY\n HELP\n EXIT\n";
- break;
- case MenuHelp:
- cout<<" PLAY\n--> HELP\n EXIT\n";
- break;
- case MenuExit:
- cout<<" PLAY\n HELP\n--> EXIT\n";
- break;
- default:
- break;
- cout<<"ERROR: Unknown state!\n";
- }
- ch=getch();
- switch (ch)
- {
- case 'w':
- case 'W':
- ms=MenuPlay;
- break;
- case 'e':
- case 'E':
- ms=MenuHelp;
- break;
- case 'r':
- case 'R':
- ms=MenuExit;
- break;
- default:
- break;
- }
- }
- switch (ms)
- {
- case MenuPlay:
- do
- {
- setColour(white);
- gotoxy(24, 0);
- cout << "Bullets Left: " << numBullets << " Ship Hits: " << hits;
- setColour(green);
- gotoxy(0,1);
- cout<<"_________________________________________________________________________________________";
- setColour(green);
- gotoxy(0,25);
- cout<<"_________________________________________________________________________________________";
- if (_kbhit())
- {
- ch = _getch();
- switch (ch)
- {
- case 'w':
- shipXPos--;
- if (shipXPos < 0) shipXPos = 0;
- break;
- case 'e':
- shipXPos++;
- if (shipXPos > 81) shipXPos = 81;
- break;
- case ' ':
- if (!Bulletalive)
- {
- bulletX = shipXPos + 1;
- bulletY = shipYPos;
- Bulletalive = true;
- numBullets--;
- }
- break;
- }
- system("cls");
- }
- if (enemyAlive)
- {
- enemyTimer--;
- if (enemyTimer == 0)
- {
- gotoxy(enemyX, enemyY);
- cout << " ";
- switch (dirHorizontal)
- {
- case 'l':
- enemyX--;
- if (enemyX == 3)
- dirHorizontal = 'r';
- break;
- case 'r':
- enemyX++;
- if (enemyX == 81)
- dirHorizontal = 'l';
- break;
- }
- setColour(cyan);
- gotoxy(enemyX, enemyY);
- cout << el<<em<<er;
- enemyTimer = ENEMY_SPEED;
- }
- }
- if (Bulletalive)
- {
- timer--;
- if (timer == 0) {
- gotoxy(bulletX, bulletY);
- cout << " ";
- bulletY--;
- if (bulletY < 0)
- Bulletalive = false;
- else
- {
- setColour(red);
- gotoxy(bulletX, bulletY);
- cout <<bu;
- }
- timer = BULLET_SPEED;
- }
- }
- setColour(red);
- gotoxy(shipXPos, shipYPos);
- cout <<" "<<pm;
- gotoxy(shipXPos, shipYPos + 1);
- cout << ps<<pmj<<ps;
- if (bulletX == enemyX && bulletY == enemyY && Bulletalive ||
- bulletX == enemyX + 1 && bulletY == enemyY && Bulletalive ||
- bulletX == enemyX + 2 && bulletY == enemyY && Bulletalive)
- {
- hits++;
- Bulletalive = false;
- }
- if (numBullets == 0)
- playing = false;
- } while (playing);
- if(hits <= 5){
- setColour(red);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" NO MEDAL";
- _getch();
- _getch();
- }
- else if(hits < 5){
- setColour(green);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" WOODEN MEDAL "<<b;
- _getch();
- _getch();
- }
- else if(hits <10){
- setColour(green);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" STONE MEDAL "<<st;
- _getch();
- _getch();
- }
- else if(hits < 15){
- setColour(green);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" BRONZE MEDAL "<<bt;
- _getch();
- _getch();
- }
- else if(hits >= 20){
- setColour(green);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" SILVER MEDAL "<<slt;
- _getch();
- _getch();
- }
- else if(hits >= 25){
- setColour(green);
- gotoxy(25, 10);
- cout << " Game Over"<<endl;
- cout<<" SHIPS HIT:"<< hits<<endl;
- cout<<" GOLD MEDAL "<<gm;
- _getch();
- _getch();
- }
- break;
- case MenuHelp:
- break;
- case MenuExit:
- break;
- }
- return 0;
- }
- void gotoxy(int x, int y)
- {
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- void setColour(int ink)
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ink);
- }
- void setConsoleSize(int rows, int columns)
- {
- _SMALL_RECT rect;
- COORD coord;
- coord.X = columns;
- coord.Y = rows;
- rect.Top = 0;
- rect.Left = 0;
- rect.Bottom = rows - 1;
- rect.Right = columns - 1;
- SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &rect);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement