So my problem is that my function isn't working properly. I realize that this is not efficient but I need it done in one fucntion.
It is supposed to be a function that draws a room and lets you walk around in it using the arrow keys in console mode.
The Problem lies in the movement..Something is very messed up and I just can't understand why! :eek:
Here is the code and if ANYONE can help Thank You!!!
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
void MovementAndRoom(int height, int width){
/*
**corner - All refer to the corners ASCII code
*border - Refers to the border ASCII code
space - Refers to space ASCII code
o* - Refer to the original Values given to the function
//331 Left
//333 right
//328 UP
//336 Down
*/
char tleftcorner = 201;
char bleftcorner = 200;
char trightcorner = 187;
char brightcorner = 188;
char hborder = 186;
char vborder = 205;
char space = 040;
/*
int left = 331;
int right = 333;
int up = 328;
int down = 336;
*/
int oheight = height;
int owidth = width;
int currentLineNumber = 0;
int currentRowNumber = 0;
int rowNumber = 3;
int lineNumber = 6;
char move;
while(true){
move;
while(move = getch()){
currentRowNumber = 0;
currentLineNumber = 0;
//Use of the Color Console Code to Color the Box
cout << tleftcorner;
//Makes the top bar - vborder is shown twice because a line break is
//roughly twice as large as a space
width = owidth;
height = oheight;
while(width > 0){
cout << vborder << vborder;
width--;
}
//Show the Right Corner
cout << trightcorner << endl;
//Resets Width
width = owidth;
//Makes the rows with spaces in betwen for future expansion
while(height > 0){
//Shows Border
cout << hborder;
while(width > 0){
if(lineNumber == currentLineNumber && (rowNumber * currentLineNumber) == currentRowNumber){
cout << "X" << space;
} else{
//Adds Spaces
cout << space << space;
}
currentRowNumber++;
width--;
}
//Shows Right Border
cout << hborder << endl;
currentLineNumber++;
currentRowNumber = owidth;
//Resets Width
width = owidth;
//Lowers Height for new Row
height--;
}
//Shows Bottom Left Corner
cout << bleftcorner;
//Shows the bottom Border
while(width > 0){
cout << vborder << vborder;
width--;
}
//Shows Last Corner
cout << brightcorner << endl;
move;
move = getch();
switch(move){
case 331:
if(rowNumber == 1){
break;
}
rowNumber--;
move;
break;
case 333:
if(rowNumber == width - 1){
break;
}
rowNumber++;
move;
break;
case 328:
if(lineNumber == height - 1){
break;
}
move = 'a';
lineNumber--;
break;
case 336:
if(lineNumber == 1){
break;
}
move = 'a';
lineNumber++;
break;
}
}
}
}
int main(int argc, char *argv[])
{
int width = 5,height = 5;
//Calls room function
cout << "How Wide do you want to the room to be? ";
cin >> width;
cout << "How High do you want to the room to be? ";
cin >> height;
MovementAndRoom(height,width);
system("PAUSE");
return EXIT_SUCCESS;
}
This is in Dev-C++ on a windows machine.