<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      wordle game 猜字游戲

      wordle game

                              .___.__                                         
      __  _  _____________  __| _/|  |   ____      _________    _____   ____  
      \ \/ \/ /  _ \_  __ \/ __ | |  | _/ __ \    / ___\__  \  /     \_/ __ \ 
       \     (  <_> )  | \/ /_/ | |  |_\  ___/   / /_/  > __ \|  Y Y  \  ___/ 
        \/\_/ \____/|__|  \____ | |____/\___  >  \___  (____  /__|_|  /\___  >
                               \/           \/  /_____/     \/      \/     \/ 
      

      游戲規則介紹

      現有一個長度已知的單詞,用戶需要對該單詞進行猜測。

      對于用戶每次的猜測結果,單詞中未出現的字母用紅色標識,出現過但位置不對的字母用黃色標識,位置和字形都正確的字母用綠色標識。

      共有十次猜測機會

      EG.答案為bless 用戶猜測bleed,則程序返回的bleed中的字母顏色分別為:綠綠綠黃紅

      游戲畫面如圖所示:

      代碼實現

      (1)引用頭文件與定義宏

      #define path "dictionary.txt" //定義一個path
      
      #define reset "\033[0m"  //用于字體顏色的改變和重置
      #define red "\033[31m"
      #define green "\033[32m"
      #define yellow "\033[33m"
      
      std::set<std::string> words;  //定義一個set容器 用于存放單詞
      

      (2)函數體get_the_dictionary(獲取單詞字典)

      void get_the_dictionary()
      {
      	std::ifstream file(path);
      	for (std::string word; std::getline(file, word);)   //逐行讀取
      	{
      		int len = word.length();
      		if (len >= 4&&len <= 6)     //控制單詞長度為4-6
      		{
      			words.insert(word);
      		}
      	}
      	file.close();
      }
      

      (3)函數體get_random_word(生成隨機單詞)

      void get_random_word(std::string& ans) 
      {
      	static std::mt19937 rng(std::random_device{}());    //隨機數生成器
      	std::uniform_int_distribution<size_t> distribution(0, words.size() - 1);
      	auto it = words.begin();    //迭代器 初始化指向words的開始
      	std::advance(it, distribution(rng));
      	ans = *it;   //將迭代器 it 當前指向的單詞(即隨機選中的單詞)賦值給引用參數 ans
      }
      

      (4)函數體result(輸出結果)

      int result(std::string& input,std::string& ans)
      {
      	int res=0;
      	if (input.length() != ans.length())  //長度錯誤
      	{
      		std::cout << "Wrong length!";
      		return 0;
      	}
      	for (int i = 0; i < ans.length(); i++)  //歷遍每個字母并輸出對應顏色的字母
      	{
      		char c = input[i];
      		if (c == ans[i])
      		{
      			std::cout << green << c << reset;
      			res++;
      		}
      		else if (ans.find(c) != std::string::npos)   //在ans中尋找與c匹配的字母
      		{
      			std::cout << yellow << c << reset;
      		}
      		else
      			std::cout << red << c << reset;
      	}
      	std::cout << "\n";
      	return res;
      }
      

      (5)主體main函數

      int main()
      {
      	int res = 0;
      	int try_times_left = 10;
      	std::string ans, input;
      
      	get_the_dictionary();
      	get_random_word(ans);
      
      	std::cout << "The game starts\n";
      	std::cout << "The length of the word is " << ans.length() << "\nYou have " << try_times_left << " times to try\n";
      	while(res != ans.length())   //循環輸入,直到嘗試次數歸零
      	{
      		
      		if (try_times_left == 0)
      		{
      			std::cout <<red<< "Loser!Now you can continue to try.";
      		}
      		else
      			std::getline(std::cin, input);  //getline讀取輸入
      			result(input, ans);
      		if (res == ans.length())
      		{
      			std::cout << "Wuhoo,you win the game! >_<";   //QAQ
      		}
      		try_times_left--;
      	}
      	return 0;
      }
      

      注意

      將你自己的單詞字典文檔路徑在path中替換。單詞之間以換行符分隔以保證程序正常運行,請使用與執行環境一樣格式的文檔換行符

      posted @ 2024-12-03 22:22  黃花菜狗  閱讀(75)  評論(0)    收藏  舉報
      1
      主站蜘蛛池模板: 亚洲天堂在线观看完整版| 国产性生大片免费观看性| 97人妻无码一区| 91精品一区二区蜜桃| 泰宁县| 日本人一区二区在线观看| 夜夜躁狠狠躁日日躁| 九九热视频在线播放| 欧美老少配性行为| 亚洲男人天堂一级黄色片| 亚洲色一区二区三区四区| 免费无码肉片在线观看| 国产精品成人网址在线观看| 麻豆精产国品一二三产| 亚洲理论在线A中文字幕| 最近中文字幕免费手机版| 亚洲欧洲一区二区精品| 色狠狠综合天天综合综合| 国产一区二区内射最近更新| 国产精品无码免费播放| 日本亚洲一区二区精品| 欧美 变态 另类 人妖| 不卡无码人妻一区三区音频| 色婷婷亚洲精品综合影院| 99久久99这里只有免费费精品| 香蕉久久久久久久av网站| 国产日韩精品欧美一区灰| 日韩精品国产另类专区| 亚洲精品动漫一区二区三| 精品一区二区三区波多野结衣| 国产精品自在线拍国产手青青机版| 晴隆县| 日韩大片高清播放器| 亚洲精品天堂在线观看| 九九热爱视频精品视频| 美女自卫慰黄网站| 久久精品国产99久久久古代| 日韩在线视频一区二区三区| 中文字幕乱码人妻二区三区| 日韩大片看一区二区三区| 色噜噜久久综合伊人一本|