hey, i am making a SIMPLE text based chess game and am having a problem when it gets to entering someones more... i don't know why, but here is my code:
Code:
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
// function prototypes
void setup_board();
void display_board();
void set_coords();
// global variables
char piece_moved;
char board[10][10];
char choice;
char *move;
short x, y;
short checkmate;
int main()
{
setup_board();
display_board();
while(!checkmate)
{
cout << "\nEnter Move From: ";
cin >> move; // ex: b2
set_coords();
piece_moved = board[x][y];
board[x][y] = ' ';
cout << "Enter Move To: ";
cin >> move; // ex: b4
set_coords();
board[x][y] = piece_moved;
display_board();
}
system("PAUSE");
return 0;
}
void setup_board()
{
// clear boxes
for(x=0;x<10;x++)
{
for(y=0;y<10;y++)
{
board[x][y] = ' ';
}
}
// color board
for(x=0;x<8;x++)
{
for(y=0;y<8;y++)
{
board[x][y] = '-';
}
}
// upper pieces
board[0][0] = 'P';
board[0][1] = 'P';
board[0][2] = 'P';
board[0][3] = 'P';
board[0][4] = 'P';
board[0][5] = 'P';
board[0][6] = 'P';
board[0][7] = 'P';
board[1][0] = 'R';
board[1][1] = 'N';
board[1][2] = 'B';
board[1][3] = 'Q';
board[1][4] = 'K';
board[1][5] = 'B';
board[1][6] = 'N';
board[1][7] = 'R';
// lower piece
board[6][0] = 'P';
board[6][1] = 'P';
board[6][2] = 'P';
board[6][3] = 'P';
board[6][4] = 'P';
board[6][5] = 'P';
board[6][6] = 'P';
board[6][7] = 'P';
board[7][0] = 'R';
board[7][1] = 'N';
board[7][2] = 'B';
board[7][3] = 'Q';
board[7][4] = 'K';
board[7][5] = 'B';
board[7][6] = 'N';
board[7][7] = 'R';
// notation help
board[7][9] = 'A';
board[6][9] = 'B';
board[5][9] = 'C';
board[4][9] = 'D';
board[3][9] = 'E';
board[2][9] = 'F';
board[1][9] = 'G';
board[0][9] = 'H';
board[9][0] = '1';
board[9][1] = '2';
board[9][2] = '3';
board[9][3] = '4';
board[9][4] = '5';
board[9][5] = '6';
board[9][6] = '7';
board[9][7] = '8';
}
void display_board()
{
for(x=0;x<10;x++)
{
for(y=0;y<10;y++)
{
cout << board[x][y];
}
cout << endl;
}
}
void set_coords()
{
// get x value from character
if(strchr(move,'a'))
{
x = 7;
}
else
{
if(strchr(move,'b'))
{
x = 6;
}
else
{
if(strchr(move,'c'))
{
x = 5;
}
else
{
if(strchr(move,'d'))
{
x = 4;
}
else
{
if(strchr(move,'e'))
{
x = 3;
}
else
{
if(strchr(move,'f'))
{
x = 2;
}
else
{
if(strchr(move,'g'))
{
x = 1;
}
else
{
if(strchr(move,'h'))
{
x = 0;
}
}
}
}
}
}
}
}
// get y
if(strchr(move,'1'))
{
y = 0;
}
else
{
if(strchr(move,'2'))
{
y = 1;
}
else
{
if(strchr(move,'3'))
{
y = 2;
}
else
{
if(strchr(move,'4'))
{
y = 3;
}
else
{
if(strchr(move,'5'))
{
y = 4;
}
else
{
if(strchr(move,'6'))
{
y = 5;
}
else
{
if(strchr(move,'7'))
{
y = 6;
}
else
{
if(strchr(move,'8'))
{
y = 7;
}
}
}
}
}
}
}
}
}
if you can help... it would help me out a lot!
thanks,
JDM