From 0efcbd071b1f9eab129606e1a400f3d6b2f7d1ab Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Mon, 7 Jan 2019 20:52:04 -0600 Subject: [PATCH 1/4] Finished --- HelloWorld/HelloWorld.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/HelloWorld/HelloWorld.cs b/HelloWorld/HelloWorld.cs index d25a8c44..3a382d3c 100644 --- a/HelloWorld/HelloWorld.cs +++ b/HelloWorld/HelloWorld.cs @@ -12,4 +12,5 @@ static void Main(string[] args) Console.Write(yourName); } } + } From 564526b8e31cf9b0c12d40ec75885e4cbf72a98c Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Wed, 23 Jan 2019 17:56:14 -0600 Subject: [PATCH 2/4] Added input --- TicTacToe/.vscode/launch.json | 28 ++++++++++++++++++++++++++++ TicTacToe/.vscode/tasks.json | 15 +++++++++++++++ TicTacToe/TicTacToe.cs | 29 +++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 TicTacToe/.vscode/launch.json create mode 100644 TicTacToe/.vscode/tasks.json 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..7305d4c5 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -4,7 +4,8 @@ namespace TicTacToe { class Program { - public static string playerTurn = "X"; + public static string playerTurn = "O"; + // string playerTurn = (playerTurn == "X") ? "O" : "X"; public static string[][] board = new string[][] { new string[] {" ", " ", " "}, @@ -32,11 +33,16 @@ public static void GetInput() int row = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); + PlaceMark(row, column); + } public static void PlaceMark(int row, int column) { - // your code goes here + // your code goes here + DrawBoard(); + board[row][column] = playerTurn = (playerTurn == "X") ? "O" : "X"; ; + DrawBoard(); } public static bool CheckForWin() @@ -52,19 +58,30 @@ public static bool CheckForTie() return false; } - + public static bool HorizontalWin() { - // your code goes here + // your code goes here - return false; + if (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn) + { + return (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn); + } + else if (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn) + { + return (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn); + } + else if (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn) + { + return (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn); + } } public static bool VerticalWin() { // your code goes here - return false; + return (board[0][0] == playerTurn && board[1][0] == playerTurn && board[2][0] == playerTurn); } public static bool DiagonalWin() From 00b950027fc83988e96fa0941fa99f6b4a670095 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Sun, 27 Jan 2019 17:35:32 -0600 Subject: [PATCH 3/4] Finished specs --- TicTacToe/TicTacToe.cs | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index 7305d4c5..f083336d 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -17,11 +17,20 @@ public static void Main() { do { + playerTurn = (playerTurn == "X") ? "O" : "X"; ; DrawBoard(); GetInput(); } while (!CheckForWin() && !CheckForTie()); - + DrawBoard(); + if (CheckForWin()) + { + System.Console.WriteLine(playerTurn + " wins!"); + } + else + { + System.Console.WriteLine("It's a tie!"); + } // leave this command at the end so your program does not close automatically Console.ReadLine(); } @@ -40,55 +49,50 @@ public static void GetInput() public static void PlaceMark(int row, int column) { // your code goes here - DrawBoard(); - board[row][column] = playerTurn = (playerTurn == "X") ? "O" : "X"; ; - DrawBoard(); + board[row][column] = playerTurn; + } public static bool CheckForWin() { - // your code goes here - - return false; + return (HorizontalWin() || VerticalWin() || DiagonalWin()); } public static bool CheckForTie() { // your code goes here - - return false; + return (!CheckForWin() && board[0][0] != " " && board[0][1] != " " && board[0][2] != " " + && board[1][0] != " " && board[1][1] != " " && board[1][2] != " " + && board[2][0] != " " && board[2][1] != " " && board[2][2] != " "); } public static bool HorizontalWin() { // your code goes here + // return false; + bool row1 = (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn); + bool row2 = (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn); + bool row3 = (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn); - if (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn) - { - return (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn); - } - else if (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn) - { - return (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn); - } - else if (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn) - { - return (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn); - } + return (row1 || row2 || row3); } public static bool VerticalWin() { // your code goes here - - return (board[0][0] == playerTurn && board[1][0] == playerTurn && board[2][0] == playerTurn); + bool column1 = (board[0][0] == playerTurn && board[1][0] == playerTurn && board[2][0] == playerTurn); + bool column2 = (board[0][1] == playerTurn && board[1][1] == playerTurn && board[2][1] == playerTurn); + bool column3 = (board[0][2] == playerTurn && board[1][2] == playerTurn && board[2][2] == playerTurn); + return (column1 || column2 || column3); } public static bool DiagonalWin() { // your code goes here + bool diagonal1 = (board[0][0] == playerTurn && board[1][1] == playerTurn && board[2][2] == playerTurn); + bool diagonal2 = (board[0][2] == playerTurn && board[1][1] == playerTurn && board[2][0] == playerTurn); - return false; + return (diagonal1 || diagonal2); } public static void DrawBoard() From 6cb148abc66f4cfa39b1b433b0505f592ac6fefa Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Sun, 27 Jan 2019 17:55:03 -0600 Subject: [PATCH 4/4] Finished --- TicTacToe/TicTacToe.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index f083336d..aa4b20aa 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -5,7 +5,6 @@ namespace TicTacToe class Program { public static string playerTurn = "O"; - // string playerTurn = (playerTurn == "X") ? "O" : "X"; public static string[][] board = new string[][] { new string[] {" ", " ", " "}, @@ -43,14 +42,12 @@ public static void GetInput() Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); PlaceMark(row, column); - } public static void PlaceMark(int row, int column) { // your code goes here board[row][column] = playerTurn; - } public static bool CheckForWin() @@ -69,7 +66,6 @@ public static bool CheckForTie() public static bool HorizontalWin() { // your code goes here - // return false; bool row1 = (board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn); bool row2 = (board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playerTurn); bool row3 = (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn); @@ -91,7 +87,6 @@ public static bool DiagonalWin() // your code goes here bool diagonal1 = (board[0][0] == playerTurn && board[1][1] == playerTurn && board[2][2] == playerTurn); bool diagonal2 = (board[0][2] == playerTurn && board[1][1] == playerTurn && board[2][0] == playerTurn); - return (diagonal1 || diagonal2); }