Hello,
I am making a program that runs off of a two dimentional array but I have made it into a game called MouseBot. I am trying to make the game so that you can move the mouse until you get the cheese. It has four different difficulty levels and you have obsticles in your way (the amount depends on the difficulty level).
The problem I am having is that when I move the 'M' (mousebot) into the array space that the cheese ('C') is in it doesn't give the message and end the game. It does the same thing with the obsticels the M just covers it up and continues the game.
Here is the code for the game (I know it is long but I am just in Computer Science I but I don't think there were any shortcuts....oh well can someone please help me with this...
Thanks
Erik
BTW, I am using Bloodshed Dev C++ version 4.9.9.2 and I am running my programs in the command prompt on Windows XP...I hope this helps.
The rest of the code is following...... ......
I am making a program that runs off of a two dimentional array but I have made it into a game called MouseBot. I am trying to make the game so that you can move the mouse until you get the cheese. It has four different difficulty levels and you have obsticles in your way (the amount depends on the difficulty level).
The problem I am having is that when I move the 'M' (mousebot) into the array space that the cheese ('C') is in it doesn't give the message and end the game. It does the same thing with the obsticels the M just covers it up and continues the game.
Here is the code for the game (I know it is long but I am just in Computer Science I but I don't think there were any shortcuts....oh well can someone please help me with this...
Thanks
Erik
BTW, I am using Bloodshed Dev C++ version 4.9.9.2 and I am running my programs in the command prompt on Windows XP...I hope this helps.
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
using namespace std;
enum Key{ LEFT = 75, RIGHT = 77, UP = 72, DOWN = 80 };
const int numColms = 10;
const int numRows = 10;
void centerText(string str, int numCols, bool printendl);
void Introduction();
void StartScreen();
void DifficultyLevel(int& obsticles);
void StartTable(int numColms, int numRows, char table[][numRows]);
void CheesePosition(int numColms, int numRows, char table[][numRows], int& cheesePosX, int& cheesePosY);
void ObsticalPositions(int obsticles, int numColms, int numRows, char table[][numRows]);
void MouseBotPosition(int numColms, int numRows, char table[][numRows], int& x, int& y);
void Movement(int numColms, int numRows, char table[][numRows], int x, int y, int& newMousePositionX, int& newMousePositionY, int cheesePosX, int cheesePosY);
void checkMovement(int newMousePositionX, int newMousePositionY, char table[][numRows], int numColms, int numRows, int x, int y, int& cheesePosX, int& cheesePosY);
void PrintNewScreen(char table[][numRows]);
int main()
{
int obsticles, numCols, x, y, newMousePositionX, newMousePositionY, cheesePosX, cheesePosY;
string str;
bool printendl;
char table[numColms][numRows];
Introduction();
StartScreen();
DifficultyLevel(obsticles);
StartTable(numColms, numRows, table);
CheesePosition(numColms, numRows, table, cheesePosX, cheesePosY);
ObsticalPositions(obsticles, numColms, numRows, table);
MouseBotPosition(numColms, numRows, table, x, y);
Movement(numColms, numRows, table, x, y, newMousePositionX, newMousePositionY, cheesePosX, cheesePosY);
system("pause");
return 0;
}
void centerText(string str, int numCols, bool printendl)
{
// center the string str over the number of cols specified in numCols
// if printendl is true then an "endl" is printed after str is printed
int len;
len = str.length();
cout << setw((numCols-len)/2) << " " << str << setw((numCols-len)/2) << " ";
if (printendl == true)
cout << endl;
}
void Introduction()
{
cout << "Erik Lindow" << endl;
cout << "Computer Science I" << endl;
cout << "Dr. Craig Varnell" << endl;
cout << endl;
centerText("Programming Assignment #6", 80, true);
cout << endl;
cout << "This program is a game where a mousebot is after a piece of cheese. The" << endl;
cout << "mousebot and the cheese are randomly placed on a 10x10 grid along with" << endl;
cout << "obsticals depending on difficulty level. The user then will control a" << endl;
cout << "mousebot and move it around obsticals in order to get the cheese. If" << endl;
cout << "the mousebot moves too many spaces up, down, left, or right it will fall off" << endl;
cout << "the table and the game will be over." << endl;
system("pause");
}
void StartScreen()
{
system("cls");
cout << setw(77) << left << "MMMM MMMM OOOOO UUU UUU SSSSSS EEEEEEEEEEE" << endl;
cout << setw(77) << left << "MMMMM MMMMM OOO OOO UUU UUU SSS SSS EEEEEEEEEEE" << endl;
cout << setw(77) << left << "MMM MM MM MMM OOO OOO UUU UUU SSS SS EEE" << endl;
cout << setw(77) << left << "MMM MM MM MMM OOO OOO UUU UUU SSS EEE" << endl;
cout << setw(77) << left << "MMM MMMM MMM OOO OOO UUU UUU SSSS EEEEEEE" << endl;
cout << setw(77) << left << "MMM MM MMM OOO OOO UUU UUU SSS EEEEEEE" << endl;
cout << setw(77) << left << "MMM MMM OOO OOO UUU UUU SS SSS EEE" << endl;
cout << setw(77) << left << "MMM MMM OOO OOO UUU UUU SSS SSS EEEEEEEEEEE" << endl;
cout << setw(77) << left << "MMM MMM OOOOO UUUUUU SSSSSS EEEEEEEEEEE" << endl;
cout << endl << endl;
cout << setw(77) << "BBBBBBBBB OOOOO TTTTTTTTTTTTT" << endl;
cout << setw(77) << "BBBB BBBB OOO OOO TTTTTTTTTTTTT" << endl;
cout << setw(77) << "BBB BBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBBB BBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBBBBBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBBB BBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBB BBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBBB BBBB OOO OOO TTT" << endl;
cout << setw(77) << "BBBBBBBBB OOOOO TTT" << setw(80) << right << "Programmed by Erik Lindow" << endl;
cout << endl;
system("pause");
}
void DifficultyLevel(int& obsticles)
{
char level;
bool test;
test = false;
while(test == false)
{
system("cls");
cout << "What difficulty level would you like to start out on?" << endl;
cout << "1. (E)asy" << endl;
cout << "2. (N)ormal" << endl;
cout << "3. (H)ard" << endl;
cout << "4. E(X)treme (Warning: Not all maps on Exteme level will have a solution!!!)" << endl;
cout << "Please enter your answer using E, N, H, or X. Thank you." << endl;
cin >> level;
cout << endl;
if (toupper(level) == 'E')
{
obsticles = 2;
cout << "You have chosen the Easy difficulty level." << endl;
cout << "There will be two obsticals on the map." << endl;
test = true;
}
else if (toupper(level) == 'N')
{
obsticles = 8;
cout << "You have chosen the Normal difficulty level." << endl;
cout << "There will be eight obsticals on the map." << endl;
test = true;
}
else if (toupper(level) == 'H')
{
obsticles = 15;
cout << "You have chosen the Hard difficulty level." << endl;
cout << "There will be fifteen obsticals on the map." << endl;
test = true;
}
else if (toupper(level) == 'X')
{
obsticles = 30;
cout << "You have chosen the Extreme difficulty level." << endl;
cout << "There will up to thirty obsticals on the map." << endl;
cout << "WARNING!!!! -- Remember not all maps on Extreme difficulty level" << endl;
cout << "will have solutions." << endl;
test = true;
}
else
{
cout << "You entered an incorrect choice. Please enter again." << endl;
test = false;
}
cout << endl;
system("pause");
}
}
void StartTable(int numColms, int numRows, char table[][numRows])
{
int i, j;
system("cls");
for(i = 0; i < numColms; i++)
{
for(j = 0; j < numRows; j++)
{
table[i][j] = '.';
}
}
}
void ObsticalPositions(int obsticles, int numColms, int numRows, char table[][numRows])
{
int i, x, y;
cout << obsticles << endl;
i = 0;
srand (time(NULL));
while(i < obsticles)
{
x = rand() % 10;
y = rand() % 10;
table[x][y] = 219;
i++;
}
}
void CheesePosition(int numColms, int numRows, char table[][numRows], int& cheesePosX, int& cheesePosY)
{
int x, y;
srand (time(NULL));
x = rand() % 12 - 3;
y = rand() % 12 - 3;
table[x][y] = 'C';
cheesePosX = x;
cheesePosY = y;
}
void MouseBotPosition(int numColms, int numRows, char table[][numRows], int& x, int& y)
{
srand (time(NULL));
x = rand() % 8;
y = rand() % 8;
table[x][y] = 'M';
for(int i = 0; i < numColms; i++)
{
for(int j = 0; j < numRows; j++)
{
cout << setw(3) << table[i][j] << setw(3) << " ";
}
cout << endl << endl;
}
system("pause");
}
Comment