From f90b8a7fad292b4515d7bcfd8adc364cfdcea334 Mon Sep 17 00:00:00 2001 From: yarb00 Date: Sat, 27 Jan 2024 18:00:49 +0800 Subject: [PATCH] v1.0.0 --- russian-roulette-plus-plus.sln | 31 +++ russian-roulette-plus-plus/main.cpp | 10 + .../russian-roulette-plus-plus.vcxproj | 141 ++++++++++++ ...russian-roulette-plus-plus.vcxproj.filters | 30 +++ .../russian-roulette-plus-plus.vcxproj.user | 4 + .../russian_roulette_plus_plus.cpp | 210 ++++++++++++++++++ .../russian_roulette_plus_plus.h | 31 +++ 7 files changed, 457 insertions(+) create mode 100644 russian-roulette-plus-plus.sln create mode 100644 russian-roulette-plus-plus/main.cpp create mode 100644 russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj create mode 100644 russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.filters create mode 100644 russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.user create mode 100644 russian-roulette-plus-plus/russian_roulette_plus_plus.cpp create mode 100644 russian-roulette-plus-plus/russian_roulette_plus_plus.h diff --git a/russian-roulette-plus-plus.sln b/russian-roulette-plus-plus.sln new file mode 100644 index 0000000..afd7bd0 --- /dev/null +++ b/russian-roulette-plus-plus.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "russian-roulette-plus-plus", "russian-roulette-plus-plus\russian-roulette-plus-plus.vcxproj", "{CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}" +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 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Debug|x64.ActiveCfg = Debug|x64 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Debug|x64.Build.0 = Debug|x64 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Debug|x86.ActiveCfg = Debug|Win32 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Debug|x86.Build.0 = Debug|Win32 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Release|x64.ActiveCfg = Release|x64 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Release|x64.Build.0 = Release|x64 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Release|x86.ActiveCfg = Release|Win32 + {CA393C5B-57E4-4B7D-9CF1-5ACEF15BD8BA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {508643CC-69E7-4CFA-8043-4975D8A0D5D3} + EndGlobalSection +EndGlobal diff --git a/russian-roulette-plus-plus/main.cpp b/russian-roulette-plus-plus/main.cpp new file mode 100644 index 0000000..2fbb5db --- /dev/null +++ b/russian-roulette-plus-plus/main.cpp @@ -0,0 +1,10 @@ +#include "russian_roulette_plus_plus.h" + +int main() +{ + Russian_roulette_plus_plus game{}; + + game.start(); + + return 0; +} \ No newline at end of file diff --git a/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj new file mode 100644 index 0000000..a9b669f --- /dev/null +++ b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj @@ -0,0 +1,141 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ca393c5b-57e4-4b7d-9cf1-5acef15bd8ba} + russianrouletteplusplus + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + stdc17 + + + 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/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.filters b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.filters new file mode 100644 index 0000000..a2a030e --- /dev/null +++ b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {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 diff --git a/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.user b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/russian-roulette-plus-plus/russian-roulette-plus-plus.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/russian-roulette-plus-plus/russian_roulette_plus_plus.cpp b/russian-roulette-plus-plus/russian_roulette_plus_plus.cpp new file mode 100644 index 0000000..3517410 --- /dev/null +++ b/russian-roulette-plus-plus/russian_roulette_plus_plus.cpp @@ -0,0 +1,210 @@ +#include "russian_roulette_plus_plus.h" +#include +#include + +void Russian_roulette_plus_plus::start() +{ + this->main(); +} + +void Russian_roulette_plus_plus::print_title() +{ + const std::string version{ "1.0.0" }; + + std::cout << "\033[7mRussianRoulette++\033[27m (\033[4mhttps://github.com/yarb00/russian-roulette-plus-plus\033[24m)" << std::endl << " yarb00 (\033[4mhttps://github.com/yarb00\033[24m)" << std::endl << std::endl << "v" << version << std::endl << std::endl << "-----" << std::endl << std::endl; +} + +void Russian_roulette_plus_plus::menu() +{ + system("cls"); + + this->print_title(); + std::cout << " !" << std::endl << std::endl << " , ..."; + + system("pause > nul 2>&1"); + + while (true) + { + int gamemode{ -1 }; + bool is_exit{ false }; + + system("color 9f"); + + system("cls"); + + this->print_title(); + std::cout << " :" << std::endl << std::endl << "0. " << std::endl << std::endl << "1. 6 ( 6 /) [\033[7m\033[27m]" << std::endl << "2. (, - )" << std::endl << "3. 12 ( 12 /) [\033[7m\033[27m]" << std::endl << "4. 24 ( 24 /)" << std::endl << std::endl; + std::cout << " Enter |>>> "; + std::cin >> gamemode; + + switch (gamemode) + { + case 0: + is_exit = true; + + break; + case 1: + this->game(gamemodes::ATTEMPTS_6); + + break; + case 2: + this->game(gamemodes::ENDLESS); + + break; + case 3: + this->game(gamemodes::ATTEMPTS_12); + + break; + case 4: + this->game(gamemodes::ATTEMPTS_24); + + break; + default: + std::cout << ": . , ."; + system("pause > nul 2>&1"); + + break; + } + + if (is_exit) break; + } +} + +void Russian_roulette_plus_plus::game(gamemodes _gamemode) +{ + system("color 1f"); + + system("cls"); + + const int number_two{ rand() % 6 + 1 }; + int attempts_left{}; + bool is_player_move{ false }; + game_results game_result{ game_results::DRAW }; + + if (_gamemode == gamemodes::ENDLESS) + { + for (attempts_left; true; attempts_left) + { + int number_one{ rand() % 6 + 1 }; + + if (number_one == number_two && is_player_move) + { + game_result = game_results::OPPONENT_WIN; + break; + } + else if (number_one == number_two && !is_player_move) + { + game_result = game_results::PLAYER_WIN; + break; + } + + is_player_move = !is_player_move; + + system("cls"); + + this->print_title(); + std::cout << " ." << std::endl << std::endl; + + if (is_player_move) + { + std::cout << " \033[7m\033[27m ." << std::endl << std::endl << " , ..."; + } + else + { + std::cout << " \033[7m\033[27m." << std::endl << std::endl << " , ..."; + } + + system("pause > nul 2>&1"); + } + } + else if (_gamemode == gamemodes::ATTEMPTS_6) + { + attempts_left = 6; + } + else if (_gamemode == gamemodes::ATTEMPTS_12) + { + attempts_left = 12; + } + else if (_gamemode == gamemodes::ATTEMPTS_24) + { + attempts_left = 24; + } + + if (_gamemode != gamemodes::ENDLESS) + { + for (attempts_left; attempts_left > 0; attempts_left--) + { + int number_one{ rand() % 6 + 1 }; + + if (number_one == number_two && is_player_move) + { + game_result = game_results::OPPONENT_WIN; + break; + } + else if (number_one == number_two && !is_player_move) + { + game_result = game_results::PLAYER_WIN; + break; + } + + is_player_move = !is_player_move; + + system("cls"); + + this->print_title(); + std::cout << " ." << std::endl << std::endl; + std::cout << " \033[7m" << attempts_left << "\033[27m ." << std::endl << std::endl; + + if (is_player_move) + { + std::cout << " \033[7m\033[27m ." << std::endl << std::endl << " , ..."; + } + else + { + std::cout << " \033[7m\033[27m." << std::endl << std::endl << " , ..."; + } + + system("pause > nul 2>&1"); + } + } + + system("cls"); + + this->print_title(); + + if (game_result == game_results::DRAW) + { + system("color 8f"); + + std::cout << "\033[7m\033[27m" << std::endl << std::endl; + std::cout << " , . ." << std::endl << std::endl; + } + else if (game_result == game_results::PLAYER_WIN) + { + system("color 2f"); + + std::cout << "\033[7m\033[27m" << std::endl << std::endl; + std::cout << " . !" << std::endl << std::endl; + } + else if (game_result == game_results::OPPONENT_WIN) + { + system("color 4f"); + + std::cout << "\033[7m\033[27m" << std::endl << std::endl; + std::cout << " . !" << std::endl << std::endl; + } + + std::cout << " ." << std::endl << " , ..."; + system("pause > nul 2>&1"); +} + +void Russian_roulette_plus_plus::main() +{ + srand(time(NULL)); + + setlocale(LC_ALL, "ru-RU"); + + system("title RussianRoulette++"); + + this->menu(); +} \ No newline at end of file diff --git a/russian-roulette-plus-plus/russian_roulette_plus_plus.h b/russian-roulette-plus-plus/russian_roulette_plus_plus.h new file mode 100644 index 0000000..9ab3c42 --- /dev/null +++ b/russian-roulette-plus-plus/russian_roulette_plus_plus.h @@ -0,0 +1,31 @@ +#pragma once + +class Russian_roulette_plus_plus +{ +public: + void start(); +private: + enum class gamemodes + { + ATTEMPTS_6 = 0, + ENDLESS, + ATTEMPTS_12, + ATTEMPTS_24 + }; + + enum class game_results + { + PLAYER_WIN = 0, + OPPONENT_LOST = 0, + + PLAYER_LOST = 1, + OPPONENT_WIN = 1, + + DRAW = 2 + }; + + void print_title(); + void menu(); + void game(gamemodes _gamemode = gamemodes::ATTEMPTS_6); + void main(); +}; \ No newline at end of file