From 991db29a5aca62534bb5d7ab83daaa872f5dbb0a Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 24 Jul 2018 09:15:30 -0500 Subject: [PATCH 1/9] TicTacToe --- TicTacToe/TicTacToe.cs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index c5751176..acf734d7 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -16,9 +16,10 @@ public static void Main() { do { + /*swap player turn */ DrawBoard(); GetInput(); - + /*loop */ } while (!CheckForWin() && !CheckForTie()); // leave this command at the end so your program does not close automatically @@ -32,18 +33,26 @@ public static void GetInput() int row = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); + PlaceMark(row, column); } - + /*update board with correct value and position */ public static void PlaceMark(int row, int column) { + board[row][column] = playerTurn; // your code goes here } public static bool CheckForWin() { // your code goes here + bool won = false; + if(HorizontalWin() || VerticalWin() || DiagonalWin()) + { + won = true; + Console.Write("You Won!"); + } - return false; + return won; } public static bool CheckForTie() @@ -52,12 +61,25 @@ public static bool CheckForTie() return false; } - + /*this method will return true when any row has three of a kind in said row otherwise it will return false */ public static bool HorizontalWin() { - // your code goes here + /*Todo if cells are empty what happens, make sure empty doesnt caount as win */ + bool WonHorizontally = false; + if(board [0][0] == board[0][1] && board [0][1] == board [0][2]) + { + WonHorizontally = true; + } + else if(board [1][0] == board[1][1] && board [1][1] == board [1][2]) + { + WonHorizontally = true; + } + else if(board [2][0] == board[2][1] && board [2][1] == board [2][2]) + { + WonHorizontally = true; + } + return WonHorizontally; - return false; } public static bool VerticalWin() From bf51ab81c1b871686fc01da472603568e769ae05 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 24 Jul 2018 09:27:29 -0500 Subject: [PATCH 2/9] TicTacToe --- TicTacToe/TicTacToe.cs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index acf734d7..292173ea 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -64,7 +64,7 @@ public static bool CheckForTie() /*this method will return true when any row has three of a kind in said row otherwise it will return false */ public static bool HorizontalWin() { - /*Todo if cells are empty what happens, make sure empty doesnt caount as win */ + /*TODO!!! if cells are empty what happens, make sure empty doesnt caount as win */ bool WonHorizontally = false; if(board [0][0] == board[0][1] && board [0][1] == board [0][2]) { @@ -84,16 +84,35 @@ public static bool HorizontalWin() public static bool VerticalWin() { - // your code goes here - - return false; + bool WonVertically = false; + if(board [0][0] == board[1][0] && board [1][0] == board [2][0]) + { + WonVertically = true; + } + else if(board [0][1] == board[1][1] && board [1][1] == board [2][1]) + { + WonVertically = true; + } + else if(board [0][2] == board[1][2] && board [1][2] == board [2][2]) + { + WonVertically = true; + } + return WonVertically; } public static bool DiagonalWin() { - // your code goes here + bool WonDiagonally = false; + if(board [0][0] == board[1][1] && board [1][1] == board [2][2]) + { + WonDiagonally = true; + } + else if(board [0][2] == board[1][1] && board [1][1] == board [2][0]) + { + WonDiagonally = true; + } - return false; + return WonDiagonally; } public static void DrawBoard() From 03b252beeca9ce1f12f10e393eb02291c2af92d9 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 24 Jul 2018 11:31:04 -0500 Subject: [PATCH 3/9] TicTacToe --- TicTacToe/TicTacToe.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index 292173ea..f3ff4125 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -17,6 +17,7 @@ public static void Main() do { /*swap player turn */ + DrawBoard(); GetInput(); /*loop */ @@ -62,6 +63,7 @@ public static bool CheckForTie() return false; } /*this method will return true when any row has three of a kind in said row otherwise it will return false */ + public static bool HorizontalWin() { /*TODO!!! if cells are empty what happens, make sure empty doesnt caount as win */ From 010af050f96f77432ba16cbec1950d616c11b1be Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 24 Jul 2018 14:04:21 -0500 Subject: [PATCH 4/9] TicTacToe --- TicTacToe/TicTacToe.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index f3ff4125..df623f96 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -10,13 +10,30 @@ class Program new string[] {" ", " ", " "}, new string[] {" ", " ", " "}, new string[] {" ", " ", " "} + }; public static void Main() { do { - /*swap player turn */ + /*swap player turn ? Does this make sence to execute*/ + if (playerTurn==1) + { + playerTurn='X'; + } + else + { + playerTurn='O'; + } + if (turn%2) + { + playerTurn=1; + } + else + { + player=2; + } DrawBoard(); GetInput(); From b2253170aa706db3a89d2865acad5ab2bc30597d Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 24 Jul 2018 14:05:58 -0500 Subject: [PATCH 5/9] TicTacToe --- TicTacToe/TicTacToe.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index df623f96..4b66119e 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -79,7 +79,7 @@ public static bool CheckForTie() return false; } - /*this method will return true when any row has three of a kind in said row otherwise it will return false */ + /*this method will return true when any row has three of a kind, otherwise it will return false */ public static bool HorizontalWin() { From ce71b6ff937a979a714e5202f2b681ce9c1ae4ab Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 30 Jul 2018 14:42:48 -0500 Subject: [PATCH 6/9] TicTacToe --- TicTacToe/TicTacToe.cs | 71 +++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index 4b66119e..48d6caba 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -17,24 +17,8 @@ public static void Main() { do { - /*swap player turn ? Does this make sence to execute*/ - if (playerTurn==1) - { - playerTurn='X'; - } - else - { - playerTurn='O'; - } - if (turn%2) - { - playerTurn=1; - } - else - { - player=2; - } - + /*swap player turn ? Does this make sence to execute*/ + DrawBoard(); GetInput(); /*loop */ @@ -52,12 +36,23 @@ public static void GetInput() Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); PlaceMark(row, column); + if (playerTurn == "O") + { + playerTurn = "X"; + } + else + { + playerTurn = "O"; + } + DrawBoard(); } /*update board with correct value and position */ public static void PlaceMark(int row, int column) { board[row][column] = playerTurn; // your code goes here + + } public static bool CheckForWin() @@ -76,27 +71,37 @@ public static bool CheckForWin() public static bool CheckForTie() { // your code goes here - - return false; + bool tie = false; + if(board [0][0] != " " && board [0][1] != " " && board [0][2] != " " ) + { + tie = true; + Console.Write("Tie!"); } - /*this method will return true when any row has three of a kind, otherwise it will return false */ + return tie; + } + /*this method will return true when any row has three of a kind in said row otherwise it will return false */ public static bool HorizontalWin() { - /*TODO!!! if cells are empty what happens, make sure empty doesnt caount as win */ + /*TODO!!! if cells are empty what happens, make sure empty doesnt count as win */ + bool WonHorizontally = false; - if(board [0][0] == board[0][1] && board [0][1] == board [0][2]) + if(board [0][0] == board[0][1] && board [0][1] == board [0][2] && board [0][0] != " " && board [0][1] != " " && board [0][2] != " ") { + //Console.Write("Horizon one"); WonHorizontally = true; } - else if(board [1][0] == board[1][1] && board [1][1] == board [1][2]) + else if(board [1][0] == board[1][1] && board [1][1] == board [1][2] && board [1][0] != " " && board [1][1] != " " && board [1][2] != " ") { + //Console.Write("Horizon two"); WonHorizontally = true; } - else if(board [2][0] == board[2][1] && board [2][1] == board [2][2]) + else if(board [2][0] == board[2][1] && board [2][1] == board [2][2] && board [2][0] != " " && board [2][1] != " " && board [2][2] != " ") { + //Console.Write("Horizon three"); WonHorizontally = true; } + //Console.Write("Horizontal Won"); return WonHorizontally; } @@ -104,36 +109,38 @@ public static bool HorizontalWin() public static bool VerticalWin() { bool WonVertically = false; - if(board [0][0] == board[1][0] && board [1][0] == board [2][0]) + if(board [0][0] == board[1][0] && board [1][0] == board [2][0] && board [0][0] != " " && board [1][0] != " " && board [2][0] != " ") { WonVertically = true; - } - else if(board [0][1] == board[1][1] && board [1][1] == board [2][1]) + } + else if(board [0][1] == board[1][1] && board [1][1] == board [2][1] && board [0][1] != " " && board [1][1] != " " && board [2][1] != " ") { WonVertically = true; } - else if(board [0][2] == board[1][2] && board [1][2] == board [2][2]) + else if(board [0][2] == board[1][2] && board [1][2] == board [2][2] && board [0][2] != " " && board [1][2] != " " && board [2][2] != " ") { WonVertically = true; } + //0Console.Write("Vertical Won"); return WonVertically; } public static bool DiagonalWin() { bool WonDiagonally = false; - if(board [0][0] == board[1][1] && board [1][1] == board [2][2]) + if(board [0][0] == board[1][1] && board [1][1] == board [2][2] && board [0][0] != " " && board [1][1] != " " && board [2][2] != " ") { WonDiagonally = true; } - else if(board [0][2] == board[1][1] && board [1][1] == board [2][0]) + else if(board [0][2] == board[1][1] && board [1][1] == board [2][0] && board [0][2] != " " && board [1][1] != " " && board [0][2] != " ") { WonDiagonally = true; } - + //Console.Write("Diagonal Won"); return WonDiagonally; } + public static void DrawBoard() { Console.WriteLine(" 0 1 2"); From 95a1f488ffb70cde14ede5fd5f4d50ee13fc782b Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 30 Jul 2018 15:34:45 -0500 Subject: [PATCH 7/9] TicTacToe --- TicTacToe/TicTacToe.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index 48d6caba..b899d0de 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -70,9 +70,9 @@ public static bool CheckForWin() public static bool CheckForTie() { - // your code goes here + // checking for Tie bool tie = false; - if(board [0][0] != " " && board [0][1] != " " && board [0][2] != " " ) + if(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] != " ") { tie = true; Console.Write("Tie!"); @@ -83,7 +83,7 @@ public static bool CheckForTie() public static bool HorizontalWin() { - /*TODO!!! if cells are empty what happens, make sure empty doesnt count as win */ + /* if cells are empty what happens, make sure empty does not count as win */ bool WonHorizontally = false; if(board [0][0] == board[0][1] && board [0][1] == board [0][2] && board [0][0] != " " && board [0][1] != " " && board [0][2] != " ") From e92044cf0adce29f1c468a5d456cf1f1bdabaab8 Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Tue, 31 Jul 2018 13:34:29 -0500 Subject: [PATCH 8/9] TicTacToe --- TicTacToe/TicTacToe.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index b899d0de..72e60130 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -32,9 +32,23 @@ public static void GetInput() { Console.WriteLine("Player " + playerTurn); Console.WriteLine("Enter Row:"); - int row = int.Parse(Console.ReadLine()); + + string input = Console.ReadLine(); + // limits input to 0, 1, 2 + bool sweet = false; + while(sweet == false) + Console.Write("Please Enter 0 ,1 or 2"); + if(input == "0" || input == "1" || input == "2") + { + sweet = true; + Console.Write("Sweet"); + } + int row = int.Parse(input); + //int row = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter Column:"); int column = int.Parse(Console.ReadLine()); + PlaceMark(row, column); if (playerTurn == "O") { From 8a82adb38bf085ea7652a880785207c1e469ce6a Mon Sep 17 00:00:00 2001 From: Jason Connolly Date: Mon, 6 Aug 2018 15:34:52 -0500 Subject: [PATCH 9/9] TicTacToe --- TicTacToe/TicTacToe.cs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/TicTacToe/TicTacToe.cs b/TicTacToe/TicTacToe.cs index 72e60130..ca9aafcb 100644 --- a/TicTacToe/TicTacToe.cs +++ b/TicTacToe/TicTacToe.cs @@ -34,30 +34,42 @@ public static void GetInput() Console.WriteLine("Enter Row:"); string input = Console.ReadLine(); + int row = 0; // limits input to 0, 1, 2 - bool sweet = false; - while(sweet == false) - Console.Write("Please Enter 0 ,1 or 2"); - if(input == "0" || input == "1" || input == "2") - { - sweet = true; - Console.Write("Sweet"); - } - int row = int.Parse(input); - //int row = int.Parse(Console.ReadLine()); + if(input == "0" || input == "1" || input == "2") + { + row = int.Parse(input); + } + else + { + Console.WriteLine("Invalid Input, Try Again"); + GetInput(); + } + Console.WriteLine("Enter Column:"); - int column = int.Parse(Console.ReadLine()); + string inputtwo = Console.ReadLine(); + int column = 0; + if(inputtwo == "0" || inputtwo == "1" || inputtwo == "2") + { + column = int.Parse(inputtwo); + } + else + { + Console.WriteLine("Invalid Input, Try Again"); + GetInput(); + } - PlaceMark(row, column); + PlaceMark(row,column); if (playerTurn == "O") { playerTurn = "X"; } - else + else { - playerTurn = "O"; + playerTurn ="O"; } + DrawBoard(); } /*update board with correct value and position */