当前位置: 首页>>代码示例>>C++>>正文


C++ Piece::Draw方法代码示例

本文整理汇总了C++中Piece::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Piece::Draw方法的具体用法?C++ Piece::Draw怎么用?C++ Piece::Draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Piece的用法示例。


在下文中一共展示了Piece::Draw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestRook

void ChessBoard::TestRook() {
    Piece *p;
    bool v;

    // Initialize Rook
    CleanBoard();

    // Put only 2 pieces to test
    string origin = "b7";
    Rook *rk= new Rook(1, origin, board);
    board[1][1]=rk;

    Pawn *pw1= new Pawn(2, "a3", board);
    board[5][0]=pw1;

    Pawn *pw2= new Pawn(1, "h4", board);
    board[4][7]=pw2;

    Draw();


    // Testing movements
    cout<< "Putting a piece on the chessboard at "<< "b7"<<"\n";
    p= GetPiece("b7");

    if (p!=NULL) {
        p->Draw();
        cout<<"\nplayer: "<< p->player<<endl;
    }
    else cout<<"null";

    string dest="e4";
    cout<<"trying to move rook horizontally to "<<dest<<" \n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="a7";
    cout<<"trying to move rook vertically to "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="c4";
    cout<<"trying to make an invalid rook move to "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "a3";
    cout<<"trying to capture a piece at "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "h4";
    cout<<"trying to capture a piece from the same player at "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

}
开发者ID:UAQ2015,项目名称:Chess,代码行数:57,代码来源:chessboard.cpp

示例2: TestQueen

void ChessBoard::TestQueen() {
   Piece *p;
    bool v;

    // Initialize Queen
    CleanBoard();

    // Put only 2 pieces to test
    string origin = "b7";
    Queen *rk= new Queen(1, origin, board);
    board[1][1]=rk;

    Pawn *pw1= new Pawn(2, "a6", board);
    board[2][0]=pw1;

    Pawn *pw2= new Pawn(1, "c6", board);
    board[2][3]=pw2;

    Draw();
 // Testing movements
    cout<< "Putting a piece on the chessboard at "<< "b7"<<"\n";
    p= GetPiece("b7");

    if (p!=NULL) {
        p->Draw();
        cout<<"\nplayer: "<< p->player<<endl;
    }
    else cout<<"null";

    string dest="b6";
    cout<<"trying to move one vertically "<<dest<<" \n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="b1";
    cout<<"trying to move vertically to "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="a6";
    cout<<"trying to capture "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "c4";
    cout<<"trying to do an invalid move "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "h1";
    cout<<"trying to capture "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

}
开发者ID:UAQ2015,项目名称:Chess,代码行数:55,代码来源:chessboard.cpp

示例3: TestKnight

void ChessBoard::TestKnight() {
   Piece *p;
    bool v;

    // Initialize Bishop
    CleanBoard();

    // Put only 2 pieces to test
    string origin = "e5";
    Knight *rk= new Knight(1, origin, board);
    board[3][4]=rk;

    Pawn *pw1= new Pawn(1, "c4", board);
    board[4][2]=pw1;

    Pawn *pw2= new Pawn(1, "c6", board);
    board[2][3]=pw2;

    Draw();
 // Testing movements
    cout<< "Putting a piece on the chessboard at "<< "a4"<<"\n";
    p= GetPiece("e5");

    if (p!=NULL) {
        p->Draw();
        cout<<"\nplayer: "<< p->player<<endl;
    }
    else cout<<"null";

    string dest="g4";
    cout<<"trying to move to "<<dest<<" \n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="c6";
    cout<<"trying to move to "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest="c4";
    cout<<"trying to capture "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "h1";
    cout<<"trying to do an invalid move "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

    dest= "h1";
    cout<<"trying to capture "<<dest<<"\n";
    v= Validate(p, dest);
    cout << (v ? "\tvalid\n" : "\tinvalid\n");

}
开发者ID:UAQ2015,项目名称:Chess,代码行数:55,代码来源:chessboard.cpp

示例4: Draw

void NextPiece::Draw(Bitmap &canvas) {
	if (piece) {
		canvas.Clear(skin->c_face);
		piece->Draw(canvas, 0, 0);
	}
}
开发者ID:bambams,项目名称:ma5king,代码行数:6,代码来源:ex05.cpp


注:本文中的Piece::Draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。