码迷,mamicode.com
首页 > 其他好文 > 详细

命令行Hangman

时间:2015-12-14 14:25:03      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

单词部分借用了过去写的,重新写了一个命令行下的Hangman。

https://github.com/shalliestera/hangman

// 猜单词游戏
#ifndef HANGMAN_H_
#define HANGMAN_H_
#include <string>
class Hangman {
private:
    static const int NUM = 26;
    const char* wordList[NUM] = {
		"apiary", "beetle", "cereal", "danger", "ensign", "florid", "garage",
		"health", "insult", "jackal", "keeper", "loaner", "manage", "nonce",
		"onset", "plaid", "quilt", "remote", "stolid", "train",
		"useful", "valid", "whence", "xenon", "yearn", "zippy"
	};
	std::string m_word;	// 保存随机选中的单词
	std::string m_show;	// 保存猜对的的字母,同时是提示
	std::string m_wrong;	// 保存猜错的字母
	int m_chances;
	// private methods # 不公开的内部方法
  void init(int chances = 6);	//	初始化
	void Check(char ch);	// 检查字母对不对
  void YouWin();
  void GameOver();
  const std::string& RightWord() const {return m_word;}
  const std::string& YouGuess() const {return m_show;}
public:
	explicit Hangman(int chances = 6); // ctors
	// 猜中则返回true, 猜错返回false
  void Guess();
	void Tips() const;
};
#endif  // HANGMAN_H_

 

命令行Hangman

标签:

原文地址:http://www.cnblogs.com/rurigokou/p/5044984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!