From aec8bb955bfa047f1e086bd7ec37bfc0ca8bb2c6 Mon Sep 17 00:00:00 2001 From: CJYKK Date: Sun, 27 Jun 2021 09:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\351\207\215\345\210\266\347\211\210.sln" | 31 ++++ .../resource.h" | 14 ++ ...0\351\207\215\345\210\266\347\211\210.cpp" | 135 ++++++++++++++++ ...60\351\207\215\345\210\266\347\211\210.rc" | 100 ++++++++++++ ...1\207\215\345\210\266\347\211\210.vcxproj" | 153 ++++++++++++++++++ ...5\345\210\266\347\211\210.vcxproj.filters" | 32 ++++ 6 files changed, 465 insertions(+) create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.sln" create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/resource.h" create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.cpp" create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.rc" create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj" create mode 100644 "\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj.filters" diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.sln" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.sln" new file mode 100644 index 0000000..e332cdd --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.sln" @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "猜数重制版", "猜数重制版\猜数重制版.vcxproj", "{F6B4440B-996F-4ADC-B58B-68978369A6BC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Debug|x64.ActiveCfg = Debug|x64 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Debug|x64.Build.0 = Debug|x64 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Debug|x86.ActiveCfg = Debug|Win32 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Debug|x86.Build.0 = Debug|Win32 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Release|x64.ActiveCfg = Release|x64 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Release|x64.Build.0 = Release|x64 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Release|x86.ActiveCfg = Release|Win32 + {F6B4440B-996F-4ADC-B58B-68978369A6BC}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B1F647BB-00C6-4878-9EF7-6E21DED1FE3E} + EndGlobalSection +EndGlobal diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/resource.h" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/resource.h" new file mode 100644 index 0000000..e176301 --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/resource.h" @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by ư.rc + +// ¶һĬֵ +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.cpp" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.cpp" new file mode 100644 index 0000000..f8943ec --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.cpp" @@ -0,0 +1,135 @@ +//各种头文件和将命名空间用关键字namespace来定义 +#include +#include +#include +#include +#include +#include +using namespace std; + +//清空屏幕 +void clear_screen() +{ +#ifdef __linux__ + system("clear"); +#elif defined(_WIN32) + system("cls"); +#endif +} + +//获取随机数 +long long random_number(int range) +{ + srand(time(NULL)); + int answer = rand() % range; + return answer; +} + +//保存成绩 +void save_score(long long answer, long long score) +{ + cout << "请问是否需要记录您的成绩?(Y/n)" << endl; + char save = _getch(); + if (save == 'Y' || save == 'y') + { + cout << "请输入您的姓名:"; + string name; + cin >> name; + cout << endl; + cout << "开始进行成绩记录……" << endl; + ofstream out("./CaishuReload2_Data/Score.txt", ios::app); + out << "记录者:" << name << ",正确答案:" << answer << ",猜测次数:" << score << "次" << endl; + out.close(); + cout << "记录完成,感谢您的游玩,再见!" << endl; + } + else if (save == 'n' || save == 'N') + { + cout << "感谢您的游玩,再见!" << endl; + } +} + +//游戏模式1 +void game_mode_1() +{ + long long range = 0; + cout << "请输入随机数的取值范围(最终的答案将会在0~x之间):"; + cin >> range; + int answer = random_number(range); + clear_screen(); + long long score = 0; + long long guess = 0; + while (true) + { + score++; + cout << "请进行您的第" << score << "次猜测:"; + cin >> guess; + if (guess > answer) + { + cout << "大了" << endl << endl; + } + if (guess < answer) + { + cout << "小了" << endl << endl; + } + if (guess == answer) + { + break; + } + } + clear_screen(); + cout << "太棒了,猜测正确!" << endl; + cout << "统计信息:" << endl; + cout << "正确答案是" << answer << ",您总共猜测了" << score << "次。" << endl; + save_score(answer, score); +} + +//查询成绩 +void read_score() +{ + ifstream in("./CaishuReload2_Data/Score.txt"); + string line; + if (in) //有该文件 + { + while (getline(in, line)) //line中不包括每行的换行符 + { + cout << line << endl; + } + } + else //没有该文件 + { + cout << "成绩读取失败,也许还没有记录的成绩呢?" << endl; + } +} + +//主菜单(无多平台支持:没有getch函数) +void main_menu() +{ + cout << "+------------------------+" << endl; + cout << "|欢迎来到猜数 - 重制版2!|" << endl; + cout << "|请选择您的游戏模式: |" << endl; + cout << "|1.经典模式(可选择范围)|" << endl; + cout << "|2.查询记录的游戏成绩 |" << endl; + cout << "+------------------------+" << endl; + cout << "请输入想玩的游戏模式的序号:"; + char mode = _getch(); + clear_screen(); + if (mode == '1') + { + game_mode_1(); + } + else if (mode == '2') + { + read_score(); + } +} + +//主函数 +int main() +{ +#ifdef _WIN32 + system("title 猜数 - 重制版2 // By CJYKK"); + system("color 17"); +#endif + main_menu(); + system("pause"); +} \ No newline at end of file diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.rc" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.rc" new file mode 100644 index 0000000..8c724ff --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.rc" @@ -0,0 +1,100 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// (壬й) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) +LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED +#pragma code_page(936) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,0,0,1 + PRODUCTVERSION 2,0,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080404b0" + BEGIN + VALUE "CompanyName", "Nope." + VALUE "FileDescription", "һ򵥵IJϷ" + VALUE "FileVersion", "0.0.0.1" + VALUE "InternalName", "ư.exe" + VALUE "LegalCopyright", "Copyright (C) 2021 CJYKK Personal" + VALUE "OriginalFilename", "ư.exe" + VALUE "ProductName", " - ư2" + VALUE "ProductVersion", "2.0.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x804, 1200 + END +END + +#endif // (壬й) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj" new file mode 100644 index 0000000..7701a2a --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj" @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {f6b4440b-996f-4adc-b58b-68978369a6bc} + 猜数重制版 + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj.filters" "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj.filters" new file mode 100644 index 0000000..fcf20f8 --- /dev/null +++ "b/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210/\347\214\234\346\225\260\351\207\215\345\210\266\347\211\210.vcxproj.filters" @@ -0,0 +1,32 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + + + 头文件 + + + + + 资源文件 + + + \ No newline at end of file