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
219 changes: 186 additions & 33 deletions TicTacToe/TicTacToe.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;

using System;

namespace TicTacToe
{
class Program
{
//Starting turn.
public static string playerTurn = "X";
public static string[][] board = new string[][]
{
new string[] {" ", " ", " "},
new string[] {" ", " ", " "},
new string[] {" ", " ", " "}
//board array is used to create the board and hold the data for the game.
public static string[][] board = new string[][] {
new string[] { " ", " ", " " },
new string[] { " ", " ", " " },
new string[] { " ", " ", " " }
};

public static void Main()
Expand All @@ -18,70 +20,221 @@ public static void Main()
{
DrawBoard();
GetInput();

} while (!CheckForWin() && !CheckForTie());

// leave this command at the end so your program does not close automatically
if (CheckForWin() == true)
{
DrawBoard();
Console.WriteLine("{0} LOSES.!", playerTurn);
}
else if (CheckForTie())
{
DrawBoard();
Console.WriteLine("You tied!");
}
Console.ReadLine();
}

bool test = true;
if (!test)
{
test = testXO();
Console.WriteLine("Your test is {0}", test);
}
else
{
Console.WriteLine("Your test is {0}", test);
}
}
//getInput fx takes user input and uses it to fill board and call PlaceMark
public static void GetInput()
{
Console.WriteLine("Player " + playerTurn);
Console.WriteLine("Enter Row:");
int row = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Column:");
int column = int.Parse(Console.ReadLine());
PlaceMark(row, column);
playerTurn = (playerTurn == "X") ? "O" : "X";
}

public static void PlaceMark(int row, int column)
public static string PlaceMark(int row, int column)
{
// your code goes here
if (board[row][column] == " ")
{
board[row][column] = playerTurn;
return playerTurn;
}
else if (board[row][column] == "X" || board[row][column] == "O")
{
Console.WriteLine("There's something here, Chief.");
GetInput();
//Changes Turn.
playerTurn = (playerTurn == "X") ? "O" : "X";
}
return playerTurn;
}

//checks all win conditions for a win.
public static bool CheckForWin()
{
// your code goes here

return false;
if (HorizontalWin() == true)
{
return true;
}
else if (VerticalWin() == true)
{
return true;
}
else if (DiagonalWin() == true)
{
return true;
}
else
{
return false;
}
}

//looks at the number of spaces - players keep going until you win or tie.
public static bool CheckForTie()
{
// your code goes here

return false;
int spaceAvail = 9;
for (int i = 0; i < board.Length; i++)
{
for (int j = 0; j < board[i].Length; j++)
{
if (board[i][j] == "X" || board[i][j] == "O")
{
spaceAvail--;
}
}
}
if (spaceAvail <= 0 && !CheckForWin() == true)
{
return true;
}
else
{
return false;
}
}

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

return false;
if (board[0][0] == "X" && board[0][1] == "X" && board[0][2] == "X")
{
return true;
}
else if (board[0][0] == "O" && board[0][1] == "O" && board[0][2] == "O")
{
return true;
}
else if (board[1][0] == "X" && board[1][1] == "X" && board[1][2] == "X")
{
return true;
}
else if (board[1][0] == "O" && board[1][1] == "O" && board[1][2] == "O")
{
return true;
}
else if (board[2][0] == "X" && board[2][1] == "X" && board[2][2] == "X")
{
return true;
}
else if (board[2][0] == "O" && board[2][1] == "O" && board[2][2] == "O")
{
return true;
}
else
{
return false;
}
}

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

return false;
//Checks each column for a veritical win.
if (board[0][0] == "X" && board[1][0] == "X" && board[2][0] == "X")
{
return true;
}
else if (board[0][0] == "O" && board[1][0] == "O" && board[2][0] == "O")
{
return true;
}
else if (board[0][1] == "X" && board[1][1] == "X" && board[2][1] == "X")
{
return true;
}
else if (board[0][1] == "O" && board[1][1] == "O" && board[2][1] == "O")
{
return true;
}
else if (board[0][2] == "X" && board[1][2] == "X" && board[2][2] == "X")
{
return true;
}
else if (board[0][2] == "O" && board[1][2] == "O" && board[2][2] == "O")
{
return true;
}
else
{
return false;
}
}

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

return false;
if (board[0][0] == "X" && board[1][1] == "X" && board[2][2] == "X")
{
return true;
}
else if (board[0][0] == "O" && board[1][1] == "O" && board[2][2] == "O")
{
return true;
}
else if (board[0][2] == "O" && board[1][1] == "O" && board[2][0] == "O")
{
return true;
}
else if (board[0][2] == "O" && board[1][1] == "O" && board[2][0] == "O")
{
return true;
}
else
{
return false;
}
}

public static void DrawBoard()
{
Console.WriteLine(" 0 1 2");
Console.WriteLine(" 0 1 2 ");
Console.WriteLine("0 " + String.Join("|", board[0]));
Console.WriteLine(" -----");
Console.WriteLine(" ------");
Console.WriteLine("1 " + String.Join("|", board[1]));
Console.WriteLine(" -----");
Console.WriteLine(" ------");
Console.WriteLine("2 " + String.Join("|", board[2]));
}

public static bool testXO()
{
PlaceMark(0, 0);
PlaceMark(1, 0);
PlaceMark(0, 1);
PlaceMark(1, 1);
PlaceMark(0, 2);
if (CheckForWin() == true)
{
if (HorizontalWin() == true)
{
return true;
}
}
else
{
return false;
}
return false;
}
}
}
}
39 changes: 39 additions & 0 deletions Week3Quiz/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;

namespace Week3Quiz
{
class Program
{
static void Main(string[] args){
// ARRAYS
// String[] names = new String[4];

// names[0] = "John";
// names[1] = "Mike";
// names[2] = "Adam";
// names[3] = "Jane";

// String[] pets = {"Rocky", "Walter", "Bailey"};

// String[] cities;
// cities = new String[] {"Austin", "Dallas", "Houston"};

// Console.WriteLine("Names {0}, {1}, {2}, {3}.", names);

// int sizeOfArray = names.Length;
// int lastIndex = sizeOfArray-1;
// String lastName - names[lastIndex];

// Console.WriteLine("In the array of size {0}, {1} is at index {2}.", sizeOfArray, lastIndex, lastName);

List<String> names = new List<String>();
names.Add("John");
names.Add("Mike");
names.Add("Mark");

Console.WriteLine("This list has {0} elements", names.Count)
}

}
}
8 changes: 8 additions & 0 deletions Week3Quiz/Week3Quiz.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>