commit 9ed8f6fd5508d1e49e61a09f641d624ce7684c9a Author: ssbg04 <143066036+ssbg04@users.noreply.github.com> Date: Mon Oct 21 23:20:50 2024 +0800 Add files via upload diff --git a/InteractiveMenu.cs b/InteractiveMenu.cs new file mode 100644 index 0000000..8615965 --- /dev/null +++ b/InteractiveMenu.cs @@ -0,0 +1,56 @@ +using System; +using System.Linq; + +public class InteractiveMenu +{ + int selected = 1; + public void Menu() + { + Console.ForegroundColor = ConsoleColor.Yellow; + System.Console.WriteLine("Use Up and Down Arrow keys to navigate, press Enter/Return to select"); + Console.ResetColor(); + + bool IsSelected = false; + ConsoleKeyInfo key; + string hoverColor = "> \u001b[32m"; + (int left, int top) = Console.GetCursorPosition(); + + + while(!IsSelected) + { + Console.SetCursorPosition(left, top); + System.Console.WriteLine($"{(selected == 1? hoverColor: " ")}Singleplayer Mode (Against CPU)\u001b[0m"); + System.Console.WriteLine($"{(selected == 2? hoverColor: " ")}Two-Player Mode (P2P)\u001b[0m"); + + key = Console.ReadKey(true); + + switch(key.Key) + { + case ConsoleKey.DownArrow: + selected = (selected == 2? 1: selected + 1); + break; + case ConsoleKey.UpArrow: + selected = (selected == 1? 2: selected - 1); + break; + case ConsoleKey.Enter: + IsSelected = true; + break; + } + } + + + } + + public void playGame() + { + singlePlay play = new singlePlay(); + P2pPlay play1 = new P2pPlay(); + if(selected != 1) + { + play1.Play(); + }else{ + play.Play(); + } + } + +} \ No newline at end of file diff --git a/P2pPlay.cs b/P2pPlay.cs new file mode 100644 index 0000000..14570d8 --- /dev/null +++ b/P2pPlay.cs @@ -0,0 +1,55 @@ +class P2pPlay +{ + private Random _random = new Random(); + + public void Play() + { + bool restart = true; + + while (restart) + { + int playerOnePick = GetPlayerPick("Player One"); + if (playerOnePick == 4) return; + + int playerTwoPick = GetPlayerPick("Player Two"); + if (playerTwoPick == 4) return; + + DisplayResult(playerOnePick, playerTwoPick); + Thread.Sleep(2000); + } + } + + private int GetPlayerPick(string playerName) + { + Console.Clear(); + Console.WriteLine($"{playerName}, type and enter (1/2/3/4): 1 = Rock, 2 = Paper, 3 = Scissors, 4 = exit"); + Console.Write($"{playerName}: "); + return int.Parse(Console.ReadLine()); + } + + private void DisplayResult(int playerOnePick, int playerTwoPick) + { + string[] choices = { "Rock", "Paper", "Scissors" }; + string result; + + if (playerOnePick == playerTwoPick) + { + result = "NO WIN, TIE!"; + } + else if ((playerOnePick == 1 && playerTwoPick == 3) || + (playerOnePick == 2 && playerTwoPick == 1) || + (playerOnePick == 3 && playerTwoPick == 2)) + { + result = "PLAYER ONE WIN!"; + } + else + { + result = "PLAYER TWO WIN!"; + } + + Console.Clear(); + Console.WriteLine($"Player One Picked: {choices[playerOnePick - 1]}"); + Console.WriteLine($"Player Two Picked: {choices[playerTwoPick - 1]}"); + Console.WriteLine(result); + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..f5424e1 --- /dev/null +++ b/Program.cs @@ -0,0 +1,28 @@ +using System; +using System.Threading; + +class Program +{ + static void Main() + { + InteractiveMenu menuShow = new InteractiveMenu(); + Title(); + menuShow.Menu(); + menuShow.playGame(); + + } + + static void Title() + { + Console.Clear(); + Console.WriteLine("\u001b[31m"+@" +__________ __ __________ _________ .__ +\______ \ ____ ____ | | _\______ \_____ ______ ___________/ _____/ ____ |__| ______ _________________ ______ + | _// _ \_/ ___\| |/ /| ___/\__ \ \____ \_/ __ \_ __ \_____ \_/ ___\| |/ ___// ___/ _ \_ __ \/ ___/ + | | ( <_> ) \___| < | | / __ \| |_> > ___/| | \/ \ \___| |\___ \ \___ ( <_> ) | \/\___ \ + |____|_ /\____/ \___ >__|_ \|____| (____ / __/ \___ >__| /_______ /\___ >__/____ >____ >____/|__| /____ > + \/ \/ \/ \/|__| \/ \/ \/ \/ \/ \/ + "+"\u001b[0m"); + } + +} \ No newline at end of file diff --git a/RockPaperScissors.csproj b/RockPaperScissors.csproj new file mode 100644 index 0000000..206b89a --- /dev/null +++ b/RockPaperScissors.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/singlePlay.cs b/singlePlay.cs new file mode 100644 index 0000000..37623b7 --- /dev/null +++ b/singlePlay.cs @@ -0,0 +1,74 @@ +using System; + +public class singlePlay +{ + private int playerWinStreak; + + public void Play() + { + bool userRestart = true; + + while (userRestart) + { + Console.Clear(); + DisplayInstructions(); + int playerChoice = GetPlayerChoice(); + + if (playerChoice == 4) + { + Console.WriteLine("Game Exit..."); + break; + } + + int cpuChoice = new Random().Next(1, 4); + DisplayRoundResult(playerChoice, cpuChoice); + UpdateWinStreak(playerChoice, cpuChoice); + Thread.Sleep(1500); + } + } + + private void DisplayInstructions() + { + Console.WriteLine("Type and Enter (1/2/3/4): 1 = Rock, 2 = Paper, 3 = Scissors, 4 = Exit"); + Console.WriteLine($"Win Streak: {playerWinStreak} \t\tInput: "); + } + + private int GetPlayerChoice() + { + while (true) + { + if (int.TryParse(Console.ReadLine(), out int choice) && choice >= 1 && choice <= 4) + return choice; + + Console.WriteLine("Invalid input. Please choose 1, 2, 3, or 4."); + } + } + + private void DisplayRoundResult(int playerChoice, int cpuChoice) + { + string[] choices = { "Rock", "Paper", "Scissors" }; + Console.WriteLine($"You picked {choices[playerChoice - 1]}, CPU picked {choices[cpuChoice - 1]}"); + + if (playerChoice == cpuChoice) + { + Console.WriteLine("TIE!"); + } + else if ((playerChoice == 1 && cpuChoice == 3) || + (playerChoice == 2 && cpuChoice == 1) || + (playerChoice == 3 && cpuChoice == 2)) + { + Console.WriteLine("YOU WIN!"); + playerWinStreak++; + } + else + { + Console.WriteLine("YOU LOSE!"); + playerWinStreak = 0; + } + } + + private void UpdateWinStreak(int playerChoice, int cpuChoice) + { + // Win streak update logic is already handled in DisplayRoundResult + } +}