0

我是 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
  }

所以,我想知道如何打印这个板?所有的碎片都放在正确的地方。如果有必要,你可以展示一个完全不同的解决方案,我只是想知道一个可能的答案!

谢谢!

4

0 回答 0