{{{~cpp #include #include using namespace std; typedef struct __IntPair { int n1; int n2; } IntPair; class Board { public: int m_nMaxCol; int m_nMaxRow; IntPair m_nRoachPos; Board () { for (int i=0;i<100;i++) { for (int j=0;j<100;j++) { boardArray[i][j] = 0; } } } int boardArray[100][100]; void setSize (int nCol, int nRow) { m_nMaxCol = nCol; m_nMaxRow = nRow; } void printBoardStatus () { for (int i=0;isetRoachPosition(nStartRow, nStartCol); } void run () { while (!isFinished ()) { move (m_pJourney->getNextJourney ()); } } void move (int nLocation) { } int isFinished () { return 1; } void printMoveCount () { cout << "move count : " << m_nMoveCount << endl; } }; class Inputer { public: int m_nBoardCol; int m_nBoardRow; int m_nStartCol; int m_nStartRow; Journey* journey; void getData () { cin >> m_nBoardRow >> m_nBoardCol; cin >> m_nStartRow >> m_nStartCol; char buffer[100]; scanf ("%s", buffer); } int getBoardCol () { return m_nBoardRow; } int getBoardRow () { return m_nBoardCol; } int getStartCol () { return 0; } int getStartRow () { return 0; } Journey* getJourney () { return journey; } }; class Game { public: Inputer* inputer; Board board; Roach* roach; Game () { } ~Game () { } void setInputer (Inputer* pInputer) { inputer = pInputer; } void start () { roach = new Roach (inputer->getJourney ()); board.setSize (inputer->getBoardRow (), inputer->getBoardCol ()); roach->goAboard (&board, inputer->getStartRow(), inputer->getStartCol()); roach->run (); roach->printMoveCount (); board.printBoardStatus (); } }; void testJourney () { char buffer[100] = "112"; Journey* journey = new Journey(buffer); int actual; int expectedSet[5] = {1,1,2,-1,-1}; for (int i=0;i<5;i++) { actual = journey->getNextJourney(); assert (actual == expectedSet[i]); } cout << "Journey.getNextJourney() Ok \n"; } void testRoach () { Board board; board.setSize(5,5); Roach roach; roach.goAboard(&board, 1, 2); assert (board.getRoachPosition ().n1 == 1); assert (board.getRoachPosition ().n2 == 2); cout << "Roach.goAboard () Ok \n"; } int main () { /* Game game; Inputer inputer; inputer.getData(); game.setInputer (&inputer); game.start (); */ testJourney(); testRoach(); return 0; } }}}