我是C ++编程的新手。我必须做一个国际象棋游戏,我必须创建一个片段(我有游戏的所有部分的类,使用层次结构)和一个具有对象矩阵的板
Piece* board[8][8];
我有Piece类标题
class Piece{
public:
Piece(char color1);
char getColor();
char getName();
virtual bool isValid(int row, int col, int rowDest, int colDest, Piece* board[][8]);
private:
char name;
char color;
};
然后我有Board类标题:
class Board{
public:
Board();
~Board();
void Board();
bool ehValido(int,int,int,int,Piece*);
private:
Piece* board [8][8];
};
我尝试为董事会做以下方法:
Board::Board(){
Piece* piece;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(i = 0 && j = 0) { piece = Rook('B');
else if(i == 0 && j == 1){ piece = Knight('B'); }
else if(i == 0 && j == 2){ piece = Bishop('B'); }
else if(i == 0 && j == 3){ piece = King('B'); }
else if(i == 0 && j == 4){ piece = Queen('B'); }
else if(i == 0 && j == 5){ piece = Bishop('B'); }
else if(i == 0 && j == 6){ piece = Knight('B'); }
else if(i == 0 && j == 7){ piece = Rook('B'); }
else if(i == 1) { piece == Pawn('B'); }
else if(i == 7 && j == 0){ piece = Rook('W'); }
else if(i == 7 && j == 1){ piece = Knight('W'); }
else if(i == 7 && j == 2{ piece = Bispo('W'); }
else if(i == 7 && j == 3){ piece = Queen('W'); }
else if(i == 7 && j == 4){ piece = King('W'); }
else if(i == 7 && j == 5){ piece = Bishop('W'); }
else if(i == 7 && j == 6){ piece = Knight('W'); }
else if(i == 7 && j == 7){ piece = Rook('W'); }
else if(i == 6){ piece = Pawn('W'); }
board[i][j] = piece;
}
}
}
然后我尝试在主要课程中将其打印出来:
#include "Piece.h"
#include "Board.h"
int main()
{
Board t;
t.show(); //show was created to show the board, probably it's wrong
}
所以,我想知道如何打印这个主板?把所有的东西放在正确的地方。如果有必要,您可以展示完全不同的解决方案,我只想知道可能的答案!
谢谢!