嘿伙计们我正在编写游戏拼贴游戏的代码连接四个并且在运行它之后,它会在尝试放置一个玩家后抛弃我。 this is ss after i used the debugger
void Board :: PlacePlayer(int x,char a) {
int i=1; if (pboard[0][x] == ' ') { while (pboard[i][x] == ' ')//the problematic line { if (i == len-1) { pboard[i][x] = a; } i++; } } else { cout << "Invalid choise - column is full please try again!\n"; corrector = -1; return; } if (a == 'R') pboard[i][x] = 'R'; else pboard[i][x] = 'B'; i--; corrector = 0; line = i; if (Winner(i, x, a)) { if (a == 'R') cout << "Red player Has Won!\n"; else cout << "Blue player Has Won!\n"; } }
这是有问题的功能,这就是我创建板矩阵的方式
pboard = buildMat(len, width);//defined as char pboard** in the .h file
char** Board::buildMat(int l, int w)//building the char matrix (private method)in the .cpp file
{
char**mat;
mat = new char*[l];
for (int i = 0; i < l; i++)
mat[i] = new char[w];
return mat;
}
任何人都可以帮忙吗?我不知道为什么我会在这里遇到内存问题。 thx提前家伙
答案 0 :(得分:-2)
也许在你的Board类中你只需要重载[] operatator。之后,您可以使用此pboard [x] [y]制作矩阵。