| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 768 人关注过本帖
标题:tic tac toe 的问题,请问怎么做?已经花了4小时了,仍然不知道怎么做。
只看楼主 加入收藏
fengzengqqq
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-7-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
tic tac toe 的问题,请问怎么做?已经花了4小时了,仍然不知道怎么做。
1. Implement displayBoard to display Tic Tac Toe board.
2. Prompt User for a box on the board to select, i.e. a number between 1 and 9 with 1 being the upper left corner.

   use cin.get(box) to get the box number and isdigit to verify it is a
number;
   1 | 2 | 3
   4 | 5 | 6
   7 | 8 | 9
   If the box is available put the appropriate X or O in there and switch players, i.e. X becomes O and vice versa.
   If the box is NOT available warn the user and get another box until they select a valid open box.

3. After all spots have been select Display "Game Over!";
4. Write a main function to use the TicTacToe class and test all of the above functionality.


#include<iostream>

using namespace std;


class TicTacToe {
public:
 void displayBoard();
 void getMove();
 void playGame();
private:
 char board[9];
 char player; // Switch after each move.
};

int main ()
{
 TicTacToe ttt;

 // you need to do the following in a loop 9 times
 ttt.playGame();
}

void TicTacToe::playGame()
{
 getMove();
 getMove();
 // Your implementation here...
}

void TicTacToe::displayBoard()
{
 // Your implementation here...
}

void TicTacToe::getMove()
{
    cout << "Enter Box: ";
    int c;
    cin >> c;
    if (c > 9 || c < 0) {
        cout << "Invalid #\n";
        return;
    }
        // Error message here.

    cout << "your number is " << c << endl;
}

void junk()
{
char t[1];
cin.get(t,2);
cin.clear();
cin.ignore(1024, '\n');
char c = t[0];
if (c > '9' || c < '0'){
    cout << "Invalid #\n";
    return;
}

[ 本帖最后由 fengzengqqq 于 2011-7-29 05:40 编辑 ]
搜索更多相关主题的帖子: available another between 
2011-07-29 05:32
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:10 
虽然英文看得懂,但是沉不住气看完。
2011-07-29 08:52
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:10 
回复 2楼 lucky563591
一共也就四条,看来你的气真的好短呀。
2011-07-29 18:27
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
回复 2楼 lucky563591
1. 实现 displayBoard 函数来绘制 tic tac toe 的棋盘。
2. 提示玩家选择一个位置。(让玩家选择1至9的一个数,1表示左上角,其余类推。见下图)
  用 cin.get(box) 来读入数字,并用 isdigit 来验证它是否是数字。
    1 | 2 | 3
    4 | 5 | 6
    7 | 8 | 9
    如果那个格子是空的,就用与玩家对应的 X 或者 O 来标记那个格子。并切换到另一个玩家(即从用 X 的玩家变成用 O 的玩家,或者是反过来)
    如果格子不是空的,就警告玩家,并且要求他再次选择,直到他的选择是合理的。
3. 所有的格子都被填满了之后,显示“Game Over!”(这个有点诡异,难道不应该在某一方横竖斜连成一条直线之后显示胜负吗?相信这个游戏大家都玩过吧?)
4. 写一个 main 函数,使用 TicTacToe 这个类,并测试上述述的所有功能。

[ 本帖最后由 pangding 于 2011-7-29 18:43 编辑 ]
2011-07-29 18:27
快速回复:tic tac toe 的问题,请问怎么做?已经花了4小时了,仍然不知道怎么做 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017395 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved