I have organized it a bunch using a switch statement. as for the edges i have thought of using something like this but im not sure if its really going to work im too tired to finish tonight but heres what i have.
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
class cMakeBoard
{
private:
int iSide;
int iSize;
int **cSpace;
int playerX; // x coordinate
int playerY; // y coordinate
public:
cMakeBoard(int x) // constructor makes dynamic array for given size
{
iSide = x;
cSpace = new int *[iSide]; //create rows
for(int i = 0 ; i < iSide ; i++ )
{
cSpace[i] = new int[iSide]; //create columns
}
int iXPos;
int iYPos;
// initialize board
for(iXPos = 0; iXPos < iSide; iXPos++)
{
for(iYPos = 0; iYPos < iSide; iYPos++)
{
cSpace[iXPos][iYPos] = 9; // initial integer for empty spot
}
}
}
~cMakeBoard() // destructor deletes dynamic array for given size
{
//delete dynamic arrays
for( int i = 0 ; i < iSide ; i++ )
{
delete [] cSpace[i] ;
}
delete [] cSpace;
}
void displayBoard()
{
// display board
for(int iXPos = 0; iXPos < iSide; iXPos++)
{
for(int iYPos = 0; iYPos < iSide; iYPos++)
{
cout << cSpace[iXPos][iYPos] << " ";
}
cout << endl;
}
}
void getHero()
{
char cCell;
playerX = -1;
playerY = -1;
for(int iXPos = 0; iXPos < iSide; iXPos++)
{
for(int iYPos = 0; iYPos < iSide; iYPos++)
{
cCell = cSpace[iXPos][iYPos];
if(cCell == 0)
{
playerX = iXPos;
playerY = iYPos;
}
}
}
cout << playerX << ", " << playerY << endl;
}
int iCreate();
char getViewerSpot(int NumKey)
{
int iTemp = -1;
char cTemp = ' ';
int iXSpot;
int iYSpot;
switch(NumKey)
{
case 1:
iXSpot = playerX-1;
if(iXSpot <0 )
{
iTemp = '|';
}
iYSpot = playerY+1;
if(iYSpot = iSide)
{
iTemp = '=';
}
iTemp = cSpace[iXSpot][iYSpot]; // 1 - down & left of player
break;
case 2:
iTemp = cSpace[playerX+0][playerY+1]; // 2 - down from player
break;
case 3:
iTemp = cSpace[playerX+1][playerY+1]; // 3 - down & right of player
break;
case 4:
iTemp = cSpace[playerX-1][playerY+0]; // 4 - left of player
break;
case 5:
iTemp = cSpace[playerX+0][playerY+0]; // 5 - player
break;
case 6:
iTemp = cSpace[playerX+1][playerY+0]; // 6 - right of player
break;
case 7:
iTemp = cSpace[playerX-1][playerY-1]; // 7 - up & left of player
break;
case 8:
iTemp = cSpace[playerX+0][playerY-1]; // 8 - up from player
break;
case 9:
iTemp = cSpace[playerX+1][playerY-1]; // 9 - up & right of player
break;
default:
break;
}
if(iTemp == 0)
{
cTemp = '~'; // get display char for player
}
return cTemp;
}
};
cMakeBoard::iCreate()
{
// spawn player 0
srand ( time(NULL) );
cSpace[rand() % iSide][rand() % iSide] = 0; // then create character object
// class object(0, '~', 500, 30); // set attributes in constructor
// spawn player 1
cSpace[rand() % iSide][rand() % iSide] = 1;
// class object(1, 'M', 100, 60); // set attributes in constructor
// spawn player 2
cSpace[rand() % iSide][rand() % iSide] = 2;
// class object(1, 'D', 100, 60); // set attributes in constructor
// spawn player 3
cSpace[rand() % iSide][rand() % iSide] = 3;
// class object(1, 'B', 100, 60); // set attributes in constructor
displayBoard();
getHero();
cout << getViewerSpot(7);
cout << getViewerSpot(8);
cout << getViewerSpot(9);
cout << endl;
cout << getViewerSpot(4);
cout << getViewerSpot(5);
cout << getViewerSpot(6);
cout << endl;
cout << getViewerSpot(1);
cout << getViewerSpot(2);
cout << getViewerSpot(3);
cout << endl;
return 0;
}
class cViewer
{
private:
static const int iMAX = 3;
char cViewer[iMAX][iMAX];
public:
void InitViewer()
{
for(int x = 0; x < iMAX; x++)
{
for(int y = 0; y < iMAX; y++)
{
cViewer[x][y] = ' ';
}
}
}
void DisplayViewer()
{
for(int x = 0; x < iMAX; x++)
{
for(int y = 0; y < iMAX; y++)
{
cout << cViewer[x][y];
}
cout << endl;
}
}
};
int main ()
{
int iHold;
srand ( time(NULL) );
iHold = rand() % 12 + 9;
cMakeBoard oBoard(iHold);
cViewer oViewer;
oViewer.InitViewer();
oViewer.DisplayViewer();
oBoard.iCreate();
cin >> iHold;
return 0;
}