SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | #include <cstdlib> | |
| 3 | #include <iomanip> | |
| 4 | #include <ctime> | |
| 5 | #include <conio.h> | |
| 6 | using namespace std; | |
| 7 | ||
| 8 | int error=0, mass1=0; | |
| 9 | struct graph | |
| 10 | {
| |
| 11 | int x; | |
| 12 | int y; | |
| 13 | }; | |
| 14 | ||
| 15 | void draw(int, graph[], graph); | |
| 16 | int main() | |
| 17 | {
| |
| 18 | setlocale (0, ""); | |
| 19 | int minecount=0, mass2=0, r4; | |
| 20 | graph mine[21], player={9, 9};
| |
| 21 | srand(time(0)); | |
| 22 | minecount=rand()%16; | |
| 23 | minecount+=4; | |
| 24 | for (mass1=0; mass1<=minecount; mass1++) | |
| 25 | {
| |
| 26 | mine[mass1].x=rand()%19; | |
| 27 | mine[mass1].y=rand()%19; | |
| 28 | if ((mine[mass1].x==player.x)&&(mine[mass1].y==player.y)) do | |
| 29 | {
| |
| 30 | mine[mass1].x=rand()%19; | |
| 31 | mine[mass1].y=rand()%19; | |
| 32 | } while ((mine[mass1].x==player.x)&&(mine[mass1].y=player.y)); | |
| 33 | cout << '\n' << mine[mass1].x << ' ' << ' ' << mine[mass1].y << ' ' << ' ' << mass1; | |
| 34 | for (mass2=mass1-1; mass2>0; mass2--) | |
| 35 | {
| |
| 36 | if ((mine[mass1].x==mine[mass1-mass2].x)&&(mine[mass1].y==mine[mass1-mass2].y)) do | |
| 37 | {
| |
| 38 | mine[mass1].x=rand()%19; | |
| 39 | mine[mass1].y=rand()%19; | |
| 40 | } while ((mine[mass1].x==mine[mass1-mass2].x)&&(mine[mass1].y==mine[mass1-mass2].y)); | |
| 41 | } | |
| 42 | } | |
| 43 | draw (mass1, mine, player); | |
| 44 | while (error==0) | |
| 45 | {
| |
| 46 | char move=getch(); | |
| 47 | switch(move) | |
| 48 | {
| |
| 49 | case 'w': player.x-=1; cout << endl << endl << endl << endl << endl; draw(mass1, mine, player); break; | |
| 50 | case 'a': player.y-=1; cout << endl << endl << endl << endl << endl; draw(mass1, mine, player); break; | |
| 51 | case 's': player.x+=1; cout << endl << endl << endl << endl << endl; draw(mass1, mine, player); break; | |
| 52 | case 'd': player.y+=1; cout << endl << endl << endl << endl << endl; draw(mass1, mine, player); break; | |
| 53 | default: draw(mass1, mine, player); break; | |
| 54 | } | |
| 55 | } | |
| 56 | cout << "\nÂû ïðîèãðàëè!"; | |
| 57 | return 0; | |
| 58 | } | |
| 59 | ||
| 60 | void draw(int mass1, graph mine[], graph player) | |
| 61 | {
| |
| 62 | int minecheck=0, playercheck=0; | |
| 63 | for (int i=0; i<21; i++) cout << '='; | |
| 64 | cout << endl; | |
| 65 | for (int i=0; i<19; i++) | |
| 66 | {
| |
| 67 | cout << '='; | |
| 68 | for (int j=0; j<19; j++) | |
| 69 | {
| |
| 70 | for (int a=0; a<=mass1; a++) | |
| 71 | {
| |
| 72 | if ((mine[a].x==i)&&(mine[a].y==j)) minecheck++; | |
| 73 | if ((player.x==mine[a].x)&&(player.y==mine[a].y)) error=1; | |
| 74 | if ((player.x==i)&&(player.y==j)) playercheck++; | |
| 75 | - | if ((player.x==mine[mass1].x)&&(player.y==mine[mass1].y)) error=1; |
| 75 | + | |
| 76 | if ((player.x==-1)||(player.x==19)||(player.y==-1)||(player.y==19)) error=1; | |
| 77 | if (minecheck>0) | |
| 78 | {
| |
| 79 | cout << '*'; | |
| 80 | minecheck=0; | |
| 81 | continue; | |
| 82 | } | |
| 83 | if (playercheck>0) | |
| 84 | {
| |
| 85 | cout << '+'; | |
| 86 | playercheck=0; | |
| 87 | continue; | |
| 88 | } | |
| 89 | cout << ' '; | |
| 90 | } | |
| 91 | cout << '=' << endl; | |
| 92 | } | |
| 93 | for (int i=0; i<21; i++) cout << '='; | |
| 94 | } |