diff --git a/PigLatin/.vscode/launch.json b/PigLatin/.vscode/launch.json new file mode 100644 index 00000000..dbee6e56 --- /dev/null +++ b/PigLatin/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/PigLatin.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/PigLatin/.vscode/tasks.json b/PigLatin/.vscode/tasks.json new file mode 100644 index 00000000..a705ed07 --- /dev/null +++ b/PigLatin/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/PigLatin.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/RockPaperScissors/.vscode/launch.json b/RockPaperScissors/.vscode/launch.json new file mode 100644 index 00000000..d468e5fb --- /dev/null +++ b/RockPaperScissors/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/RockPaperScissors.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/RockPaperScissors/.vscode/tasks.json b/RockPaperScissors/.vscode/tasks.json new file mode 100644 index 00000000..9cdb0334 --- /dev/null +++ b/RockPaperScissors/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/RockPaperScissors.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 470ae756..9c30ccbf 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,20 +6,129 @@ class Program { public static void Main() { - Console.WriteLine("Enter hand 1:"); - string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("Enter hand 2:"); - string hand2 = Console.ReadLine().ToLower(); - Console.WriteLine(CompareHands(hand1, hand2)); - - // leave this command at the end so your program does not close automatically - Console.ReadLine(); - } - - public static string CompareHands(string hand1, string hand2) - { - // Your code here - return hand1 + ' ' + hand2; + string player1Hand = ""; + int player1Score = 0; + string comHand = ""; + int comScore = 0; + int ties = 0; + string[] rps = new string[] {"rock", "paper", "scissors"}; + + PlayerTurn(); + ComTurn(); + WinCheck(); + Scoreboard(); + PlayAgain(); + + void PlayerTurn(){ + Console.WriteLine("Please type 1 for Rock, 2 for Paper, or 3 for Scissors and press the Enter key: "); + // int player1Choice = Convert.ToInt32(Console.ReadLine()) - 1; + string player1Choice = Console.ReadLine(); + System.Threading.Thread.Sleep(500); + if ((player1Choice == "1") || (player1Choice == "2") || (player1Choice == "3")) + { + player1Hand = rps[Convert.ToInt32(player1Choice) - 1]; + Console.WriteLine("You chose " + player1Hand +"."); + System.Threading.Thread.Sleep(500); + } + else + { + Console.WriteLine("Your choice is invalid. Choose again."); + System.Threading.Thread.Sleep(500); + PlayerTurn(); + } + } + + void ComTurn(){ + Random rnd = new Random(); + int roll = rnd.Next(0, 3); + comHand = rps[roll]; + Console.WriteLine("The Computer Mastermind chose " + comHand + "."); + System.Threading.Thread.Sleep(500); + } + + void WinCheck(){ + + if (player1Hand == comHand){ + Console.WriteLine("That's a tie!"); + ties ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "rock" && comHand == "paper"){ + Console.WriteLine("Paper beats rock! You lose!"); + comScore ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "rock" && comHand == "scissors"){ + Console.WriteLine("Rock beats scissors! You win!"); + player1Score ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "scissors" && comHand == "paper"){ + Console.WriteLine("Scissors beats paper! You win!"); + player1Score ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "scissors" && comHand == "rock"){ + Console.WriteLine("Rock beats scissors! You lose!"); + comScore ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "paper" && comHand == "rock"){ + Console.WriteLine("Paper beats rock! You win!"); + player1Score ++; + System.Threading.Thread.Sleep(500); + } + else if (player1Hand == "paper" && comHand == "scissors"){ + Console.WriteLine("Scissors beats paper! You lose!"); + comScore ++; + System.Threading.Thread.Sleep(500); + } + } + + // void WinCheckSmall(){ + // if (player1Hand == comHand){ + // Console.WriteLine("That's a tie!"); + // ties ++; + // } + // else if (player1Hand == "rock" && comHand == "paper") || (player1Hand == "scissors" && comHand == "rock") { + // Console.WriteLine("Paper beats rock! You lose!"); + // comScore ++; + // } + // } + + void Scoreboard(){ + // Console.WriteLine("CURRENT SCORE: \n PLAYER 1: " + player1Score + "\nCOMPUTER MASTERMIND SCORE: " + comScore); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Console.WriteLine(" CURRENT SCORE: "); + Console.WriteLine(" PLAYER 1: " + player1Score); + Console.WriteLine(" COMPUTER MASTERMIND: " + comScore); + Console.WriteLine(" TIES: " + ties); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + System.Threading.Thread.Sleep(500); + } + + void PlayAgain() { + string[] yes = { Convert.ToString('y'), Convert.ToString('Y'), "yes", "Yes", "YES"}; + Console.WriteLine("Do you want to try again? [y/n]"); + for (int i = 0; i < yes.Length; i++) + { + string choice = Console.ReadLine(); + if (choice == yes[i]) + { + Console.Clear(); + PlayerTurn(); + ComTurn(); + WinCheck(); + Scoreboard(); + PlayAgain(); + } + else + { + Console.WriteLine("Bye! Thanks for playing!"); + Environment.Exit(0); + } + } + } } } } diff --git a/TicTacToe/.vscode/launch.json b/TicTacToe/.vscode/launch.json new file mode 100644 index 00000000..b35dd83d --- /dev/null +++ b/TicTacToe/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/TicTacToe.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ,] +} \ No newline at end of file diff --git a/TicTacToe/.vscode/tasks.json b/TicTacToe/.vscode/tasks.json new file mode 100644 index 00000000..a6ea07f7 --- /dev/null +++ b/TicTacToe/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/TicTacToe.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index c5751176..b2545853 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -4,7 +4,9 @@ namespace TicTacToe { class Program { - public static string playerTurn = "X"; + public static string playerTurn = "O"; + public static int turnNumber = 0; + public static string[][] board = new string[][] { new string[] {" ", " ", " "}, @@ -13,65 +15,150 @@ class Program }; public static void Main() + { do { DrawBoard(); + ChangePlayer(); GetInput(); } while (!CheckForWin() && !CheckForTie()); - + // leave this command at the end so your program does not close automatically - Console.ReadLine(); + PlayAgain(); + Console.ReadLine(); } public static void GetInput() { + Console.WriteLine("Turn #" + turnNumber); Console.WriteLine("Player " + playerTurn); Console.WriteLine("Enter Row:"); int row = int.Parse(Console.ReadLine()); + + if ((row == 0) || (row == 1) || (row == 2)) //check to make sure row input is valid + { + + Console.WriteLine("You chose " + row +"."); + } + else + { + Console.WriteLine("Your row choice is invalid. Choose again."); + GetInput(); + } + Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); + + if ((column == 0) || (column == 1) || (column == 2)) //check to see if column input is valid + { + + Console.WriteLine("You chose " + column +"."); + } + else + { + Console.WriteLine("Your column choice is invalid. Choose again."); + GetInput(); + } + + if (board[row][column] == " ") //checks to see if space is already occupied + { + PlaceMark(row, column); + } + else + { + Console.WriteLine("That space is already taken, please choose another space"); + GetInput(); + } } public static void PlaceMark(int row, int column) { - // your code goes here + board[row][column] = playerTurn; + //DrawBoard(); + turnNumber ++; } public static bool CheckForWin() { - // your code goes here - - return false; + bool won = false; + if (HorizontalWin() || VerticalWin() || DiagonalWin()) + { + won = true; + Console.WriteLine("Player " + playerTurn + " Wins in " + turnNumber + " moves!"); + turnNumber = 0; + } + + return won; + } public static bool CheckForTie() { - // your code goes here + bool tie = false; + if (turnNumber >= 9 ) + + { + turnNumber = 0; + tie = true; + Console.WriteLine("It's a tie! No one wins! Sucker!"); + } - return false; + return tie; + } public static bool HorizontalWin() { // your code goes here - + if (board[0][0] == playerTurn && board[0][0] == board[0][1] && board[0][1] == board[0][2]) //check row 0 + { + return true; + } + else if (board[1][0] == playerTurn && board[1][0] == board[1][1] && board[1][1] == board[1][2]) //check row 1 + { + return true; + } + else if ((board[2][0] == playerTurn && board[2][0] == board[2][1] && board[2][1] == board[2][2])) //check row 2 + { + return true; + } return false; } public static bool VerticalWin() { - // your code goes here - - return false; + if (board[0][0] == playerTurn && board[1][0] == board[0][0] && board[1][0] == board[2][0]) //check col 0 + { + return true; } - + else if (board[0][1] == playerTurn && board[1][1] == board[0][1] && board[1][1] == board[2][1]) //check col 2 + { + return true; + } + else if (board[0][2] == playerTurn && board[1][2] == board[0][2] && board[1][2] == board[2][2]) //check col 3 + { + return true; + } + return false; + } + public static bool DiagonalWin() { - // your code goes here - - return false; + if (board[0][0] == playerTurn && board[0][0] == board[1][1] && board[0][0] == board[2][2]) + { + return true; + } + else if (board[0][2] == playerTurn && board[0][2] == board[1][1] && board[1][1] == board[2][0]) + { + return true; + } + else + { + return false; + } + } public static void DrawBoard() @@ -83,5 +170,40 @@ public static void DrawBoard() Console.WriteLine(" -----"); Console.WriteLine("2 " + String.Join("|", board[2])); } + + public static void ChangePlayer() + { + if (playerTurn == "O") + { + playerTurn = "X"; + } + else + { + playerTurn = "O"; + } + + + + } -} + + public static void PlayAgain() { + string[] yes = { Convert.ToString('y'), Convert.ToString('Y'), "yes", "Yes", "YES"}; + Console.WriteLine("Do you want to try again? [y/n]"); + for (int i = 0; i < yes.Length; i++) + { + string choice = Console.ReadLine(); + if (choice == yes[i]) + { + Console.Clear(); + Main(); + } + else + { + Console.WriteLine("Bye! Thanks for playing!"); + Environment.Exit(0); + + + + } +}}}}