【C++】命令行Hangman #2015年12月15日 00:20:27
2015-12-14 13:27
756 查看
增加了可以在构造Hangman对象时通过传入参数设定“最大猜测次数”的功能。少量修改。# 2015年12月15日 00:20:22
https://github.com/shalliestera/hangman
单词部分借用了过去写的,重新写了一个命令行下的Hangman。
https://github.com/shalliestera/hangman
https://github.com/shalliestera/hangman
// 猜单词游戏 #ifndef HANGMAN_H_ #define HANGMAN_H_ #include <string> class Hangman { public: // 可以在创建时确定最大猜错次数 explicit Hangman(int chances = 6); // ctors // Guess()是主要操作 void Guess(); private: // 内置单词表[a-z] # word list, from a to z 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; // 保存随机选中的单词 # store the randomly choosing word std::string m_show; // 保存猜对的的字母,同时是提示 # correctly guessing std::string m_wrong; // 保存猜错的字母 # wrong guessing int m_chances; // 最多可以猜错的次数 # max chances int m_usrChances; // 构造时传入的次数 # // --- // 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;} void Tips() const; }; #endif // HANGMAN_H_
单词部分借用了过去写的,重新写了一个命令行下的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_
相关文章推荐
- C++中inline函数
- (C++)public private protected 的解释说明
- (C++)权限修饰符 public private protected的联系与区别
- 10个经典的C语言面试基础算法及代码
- C/C++小知识总结之四
- 设计模式C++实现:客户机-分配器-服务器模式
- c++中的强制转换static_cast、dynamic_cast、reinterpret_cast
- C++11 元编程 判断是否有std::hash<T>特例并提供hash函数通用实现
- 第12周项目5 迷宫问题之图深度优先遍历解法
- android如何在C++中打印调用堆栈
- 【c++】小技巧——在数组边遍历的过程中求出最值和最值的位置
- C语言字节对齐
- 图像去雾之何凯明暗通道先验去雾算法原理及c++代码实现
- 第12周项目4 利用遍历思想求解图问题
- C++ string
- 智锋互联第一期C语言培训视频
- C++静态成员变量
- STL中的binary_search upper_bounde lower_bound
- 第12周项目3 图遍历算法实现
- C/C++语言字符串操作总结大全(超详细)