00001 #ifndef CONSOLEDISPLAY_HPP 00002 #define CONSOLEDISPLAY_HPP 00003 00004 #include "Renderer2D.hpp" 00005 00006 #include "Game/Boards/ChessBoard.hpp" 00007 #include "Game/Move.hpp" 00008 00009 #include <iostream> 00010 00011 class ConsoleChessDisplay : public Renderer2D<ChessBoard> 00012 { 00013 private: 00014 00015 public: 00016 00019 void notify(const Move<ChessBoard::Coords> & move) 00020 { 00021 (void)move; 00022 00023 displayBoard(); 00024 } 00025 00026 virtual void displayBoard() 00027 { 00028 for ( int x = Renderer<ChessBoard>::m_pBoard->getDimensionLength(1)-1 ; x >= 0 ; x-- ) 00029 { 00030 for ( int y = 0 ; y < Renderer<ChessBoard>::m_pBoard->getDimensionLength(0) ; y++ ) 00031 { 00032 displayPiece(ChessBoard::Coords(y,x)); 00033 std::cout << " "; 00034 } 00035 std::cout << std::endl; 00036 } 00037 } 00038 00039 void displayPiece(const ChessBoard::Coords& position) 00040 { 00041 const Piece& piece = m_pBoard->get(position.get()); 00042 char pieceDisp = ' '; 00043 switch (piece.type()) 00044 { 00045 case 1: 00046 pieceDisp = 'p'; 00047 break; 00048 case 2: 00049 pieceDisp = 'r'; 00050 break; 00051 case 3: 00052 pieceDisp = 'n'; 00053 break; 00054 case 4: 00055 pieceDisp = 'b'; 00056 break; 00057 case 5: 00058 pieceDisp = 'q'; 00059 break; 00060 case 6: 00061 pieceDisp = 'k'; 00062 break; 00063 case 0: 00064 default: 00065 pieceDisp = '.'; 00066 break; 00067 } 00068 00069 if ( piece.color() == 0 ) 00070 { 00071 pieceDisp = toupper(pieceDisp); 00072 } 00073 00074 std::cout << pieceDisp; 00075 } 00076 }; 00077 00094 #endif