www.pudn.com > wuziqi.rar > Board.cpp
// Board.cpp: implementation of the Board class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "Board.h" #include////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Board::Board() { //chess = new Chess; } Board::~Board() { } void Board::initate() { for ( int j = 0; j < 15; ++j ) // 初始化棋子 for ( int k = 0; k < 15; ++k ) stone[ j ][ k ] = ' '; player1.name='A'; player1.symbol='O'; player2.name='B'; player2.symbol='X'; } void Board::drawboard( void ) { /***********************************画棋盘**********************************/ cout << setw(1); for(int t = 0; t < 15; t ++) cout << setiosflags(ios::right) << setw(5) << t; cout << '\n' << '\n'; for ( int r = 0; r < 15; ++r ) { cout << setw(2) << r; for ( int c = 0; c < 15; ++c ) { cout << setiosflags(ios::internal) << setw( 3 ) << static_cast< char > ( stone[ r ][ c ] );//类型转换INT到CHAR if ( c != 14 ) cout << " |"; } if ( r != 14 ) { cout << '\n' << setw(2) << ' '; for(int l = 0; l < 14; l ++) cout << "____|"; cout << "____"; cout << '\n' << setw(2) << ' '; cout << '\n'; } } cout << '\n'; cout << setw(1); for( t = 0; t < 15; t ++) cout << setiosflags(ios::right) << setw(5) << t; cout << '\n'; cout << '\n'; } int Board::modelchoice() { cout << "\n*****************请选择对战模式*****************\n" << "1----双人游戏\n" << "2----人机对奕\n" << "0----结束程序\n"; char choice = 1; do { cout << "请输入: "; cin >> choice; }while(!(choice == 49 || choice == 50));//1的ascii值是49,2的ascii值是50 return (int)choice;//转换类型 } int Board::firsthandchoice() { cout << "\n*****************请选择先手*****************\n" << "1---玩家\n" << "2---计算机\n"; char choice = 1; do { cout << "请输入: "; cin >> choice; } while(!(choice == 49 || choice == 50)); return (int)choice; }