Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HelloWorld/HelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ static void Main(string[] args)
Console.Write(yourName);
}
}

}
28 changes: 28 additions & 0 deletions TicTacToe/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
,]
}
15 changes: 15 additions & 0 deletions TicTacToe/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TicTacToe.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
46 changes: 31 additions & 15 deletions TicTacToe/TicTacToe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TicTacToe
{
class Program
{
public static string playerTurn = "X";
public static string playerTurn = "O";
public static string[][] board = new string[][]
{
new string[] {" ", " ", " "},
Expand All @@ -16,11 +16,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();
}
Expand All @@ -32,46 +41,53 @@ 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
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
// your code goes here
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);

return false;
return (row1 || row2 || row3);
}

public static bool VerticalWin()
{
// your code goes here

return false;
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

return false;
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);
}

public static void DrawBoard()
Expand Down