1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#include <stdlib.h>
#include <iostream>
#include <ctime>
#define WIDTH 16
#define HEIGHT 16
#define BOMB 1
#define TREASURE 2
#define PASS 0
using namespace std;
void grid(int,int);
void menu();
int check(int,int);
int bomb1[1][2];
int bomb2[1][2];
int bomb3[1][2];
int bomb4[1][2];
int treasure[1][2];
int main(){
int x_cord=1,y_cord=1;
int move=0;
srand(time(NULL));
bomb1[0][0] = rand() % WIDTH + 1;
bomb1[0][1] = rand() % HEIGHT + 1;
bomb2[0][0] = rand() % WIDTH + 1;
bomb2[0][1] = rand() % HEIGHT + 1;
bomb3[0][0] = rand() % WIDTH + 1;
bomb3[0][1] = rand() % HEIGHT + 1;
bomb4[0][0] = rand() % WIDTH + 1;
bomb4[0][1] = rand() % HEIGHT + 1;
treasure[0][0] = rand() % WIDTH + 1;
treasure[0][1] = rand() % HEIGHT + 1;
cout << "\t\t\t\tGrid Movement w/ Keyboard Input!" << endl << endl
<< "The goal is to move around the grid and just enjoy yourself while doing it" << endl
<< "In order to move your player (P) around you press...." << endl << endl
<< "\t2 --> Down" << endl
<< "\t4 --> Left" << endl
<< "\t8 --> Up" << endl
<< "\t6 --> Right" << endl
<< "\t88 --> Instructions (This menu)" << endl
<< "\t99 --> Quit" << endl;
cout << bomb1[0][0] << ", " << bomb1[0][1] << endl
<< bomb2[0][0] << ", " << bomb2[0][1] << endl
<< bomb3[0][0] << ", " << bomb3[0][1] << endl
<< bomb4[0][0] << ", " << bomb4[0][1] << endl
<< treasure[0][0] << ", " << treasure[0][1] << endl;
while(move != 99 && check(x_cord,y_cord) == PASS){
cout << "Move? (88 for Instructions)" << endl;
cin >> move;
switch (move){
case 8:
if(y_cord > 1){
y_cord = y_cord - 1;
grid(x_cord,y_cord);
}
else
cout << "Can't move upward off thy grid...Come on...ith!" << endl;
break;
case 4:
if(x_cord > 1){
x_cord = x_cord - 1;
grid(x_cord,y_cord);
}
else
cout << "You aren't allowed any futher West, try again!" << endl;
break;
case 2:
if(y_cord < HEIGHT){
y_cord++;
grid(x_cord,y_cord);
}
else
cout << "You're about to pop off the bottom of the grid!" << endl;
break;
case 6:
if(x_cord < WIDTH){
x_cord++;
grid(x_cord,y_cord);
}
else
cout << "Any farther right and you won't even be on the map!" << endl;
break;
case 99:
cout << "Exitting... Have a nice day!" << endl;
break;
case 88:
menu();
break;
default:
cout << "Invalid option... please do try again!" << endl;
}
}
if(check(x_cord,y_cord) == BOMB)
{
cout << "\n\nOoooooh, you totally hit a bomb!" << endl << endl << endl;
cout << "\tTreasure was at cordinates " << treasure[0][0] << ", " << treasure[0][1] << "! Better luck next time..." << endl;
}
else if(check(x_cord,y_cord) == TREASURE)
cout << "\n\nWhoa, you just found the hidden treasure!" << endl;
return 0;
}
void grid(int x,int y){
char grid[WIDTH][HEIGHT];
int i=0,j=0;
for(i=0;i<HEIGHT;i++){
for(j=0;j<WIDTH;j++){
grid[i][j] = 'o';
}
}
grid[y-1][x-1] = 'P';
for(i=0;i<25;i++){
cout << endl << endl;
}
for(i=0;i<HEIGHT;i++){
for(j=0;j<WIDTH;j++){
cout << grid[i][j];
}
cout << endl;
}
return;
}
void menu(){
cout << "\t2 --> Down" << endl
<< "\t4 --> Left" << endl
<< "\t8 --> Up" << endl
<< "\t6 --> Right" << endl
<< "\t99 --> Quit" << endl;
return;
}
int check(int x,int y){
int value;
if(bomb1[0][0] == x && bomb1[0][1] == y)
value = BOMB;
else
if(bomb2[0][0] == x && bomb2[0][1] == y)
value = BOMB;
else
if(bomb3[0][0] == x && bomb3[0][1] == y)
value = BOMB;
else
if(bomb4[0][0] == x && bomb4[0][1] == y)
value = BOMB;
else
if(treasure[0][0] == x && bomb4[0][1] == y)
value = TREASURE;
else
value = PASS;
return value;
}
|