Working On a new project as a beginner in C# and though I would get some feedback!
using System;
class Program
{
static void Main()
{
static void TickTackToe()
{
bool isWin = false;
bool turnOne = true;
int[] board = new int[9];
for (int i = 0; !isWin; i++)
{
int x = 0;
int y = 0;
bool validCoords = false;
while (!validCoords)
{
Console.WriteLine("Enter x Coodinate");
x = int.Parse(Console.ReadLine());
Console.WriteLine("Enter y Coodinate");
y = int.Parse(Console.ReadLine());
if (board[x + (y * 3)] == 0)
validCoords = true;
else
Console.WriteLine("Invalid Coordinates");
}
if (turnOne)
board[x + (y * 3)] = 1;
else
board[x + (y * 3)] = 2;
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
Console.Write(String.Join(", ", board[k + (j * 3)]));
}
Console.WriteLine();
}
Console.WriteLine("Stop?");
string r = Console.ReadLine();
if (r == "yes")
isWin = true;
turnOne = !turnOne;
Console.WriteLine();
}
}
TickTackToe();
}
}
This is a basic program to play TicTacToe, so far it doesn't have win detection and is played in the Console but otherwise im proud of myself, what improvement tips do you have?
(This is my first time here so if I did anything wrong making this post lmk.)
Top comments (0)