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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
using namespace std;
int main()
{
int coord1 = 0, coord2 = 0;
int coord3 = 0;
int coord4 = 0;
int TreasureX = ((int)(rand()%8));
int TreasureY = ((int)(rand()%7)) + 1;
int x = 0;
int RandomChance = 0;
string M;
string Response;
cout << "You, the player, is at the coordinates [0][0]. Your goal is to find the treasure" << endl;
cout << "Do you want to move: left, right, up, or down?" << endl;
cin >> M;
while (M == "left")
{
cout << "You moved one space to the left." << endl;
coord1 = coord1 - 1 ;
if (coord1 = coord1 - 1)
{
int pickedChoice = ((int)(rand() % 4)) + 1;
if (pickedChoice = 1)
{
coord3 --;
}
else if (pickedChoice = 2)
{
coord3 ++;
}
else if (pickedChoice = 3)
{
coord4 --;
}
else if (pickedChoice = 4)
{
coord4 ++;
}
cout << "The monster is now at coordinates: " << coord3 << "," << coord4 << endl;
}
if (coord1 == TreasureX && coord2 == TreasureY)
{
cout << "You've found the treasure and won the game!" << endl;
break;
}
cout << "You are at the coordinates: " << coord1 << "," << coord2 << endl;
cout << "Choose again, where do you want to go: left, right, up, or down?" << endl;
cin >> M;
std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
}
while (M == "right")
{
cout << "You moved one space to the right." << endl;
coord1++ ;
if (coord1++)
{
int pickedChoice = ((int)(rand() % 4)) + 1;
if (pickedChoice = 1)
{
coord3 --;
}
else if (pickedChoice = 2)
{
coord3 ++;
}
else if (pickedChoice = 3)
{
coord4 --;
}
else if (pickedChoice = 4)
{
coord4 ++;
}
cout << "The monster is now at coordinates: " << coord3 << "," << coord4 << endl;
}
if (coord1 == TreasureX && coord2 == TreasureY)
{
cout << "You've found the treasure and won the game!" << endl;
break;
}
cout << "You are at the coordinates: " << coord1 << "," << coord2 << endl;
cout << "Choose again, where do you want to go: left, right, up, or down?" << endl;
cin >> M;
std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
}
while (M == "up")
{
cout << "You moved one space upward." << endl;
coord2-- ;
if (coord2--)
{
int pickedChoice = ((int)(rand() % 4)) + 1;
if (pickedChoice = 1)
{
coord3 --;
}
else if (pickedChoice = 2)
{
coord3 ++;
}
else if (pickedChoice = 3)
{
coord4 --;
}
else if (pickedChoice = 4)
{
coord4 ++;
}
cout << "The monster is now at coordinates: " << coord3 << "," << coord4 << endl;
}
if (coord1 == TreasureX && coord2 == TreasureY)
{
cout << "You've found the treasure and won the game!" << endl;
break;
}
cout << "You are at the coordinates: " << coord1 << "," << coord2 << endl;
cout << "Choose again, where do you want to go: left, right, up, or down?" << endl;
cin >> M;
std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
}
while (M == "down")
{
cout << "You moved one space downward." << endl;
coord2++ ;
if (coord2++)
{
int pickedChoice = ((int)(rand() % 4)) + 1;
if (pickedChoice = 1)
{
coord3 --;
}
else if (pickedChoice = 2)
{
coord3 ++;
}
else if (pickedChoice = 3)
{
coord4 --;
}
else if (pickedChoice = 4)
{
coord4 ++;
}
cout << "The monster is now at coordinates: " << coord3 << "," << coord4 << endl;
}
if (coord1 == TreasureX && coord2 == TreasureY)
{
cout << "You've found the treasure and won the game!" << endl;
break;
}
cout << "You are at the coordinates: " << coord1 << "," << coord2 << endl;
cout << "Choose again, where do you want to go: left, right, up, or down?" << endl;
cin >> M;
std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
}
if (coord3 == coord1 && coord4 == coord2)
{
cout << "The monster caught you... game over." << endl;
}
return 0;
}
|