static public void Main(string[] args)
static public string[,] CreateField()
string[,] field = new string[3, 3];
for (var i = 0; i < field.GetLength(0); i++)
for (var j = 0; j < field.GetLength(1); j++)
static public void ShowField(string[,] field)
for(var i = 0; i < field.GetLength(0); i++)
for(var j = 0; j < field.GetLength(1); j++)
Console.Write(" {0} ", field[i, j]);
static public int[] AskCoordinates()
Console.WriteLine("In which row you want to mark?");
marks[0] = Int32.Parse(Console.ReadLine()) - 1;
Console.WriteLine("In which column you want to mark?");
marks[1] = Int32.Parse(Console.ReadLine()) - 1;
static public int[] isCellEmpty(int [] marks, string[,] field)
while(!string.Equals(field[marks[0], marks[1]], "-"))
Console.WriteLine("Please, choose an empty cell");
marks = AskCoordinates();
isCellEmpty(marks, field);
static public int[] CheckRange(int[] coordinates)
while(coordinates[0] >= 3 || coordinates[1] >= 3)
Console.WriteLine("Please, enter a number between 1 and 3");
coordinates = AskCoordinates();
static public string[,] Drawing(int[] coordinates, string[,] field, bool status)
var sign = status == true ? "X" : "O";
for (var i = 0; i < field.GetLength(0); i++)
for (var j = 0; j < field.GetLength(1); j++)
field[coordinates[0], coordinates[1]] = sign;
static public bool IsFinished( bool status, string [,] field, int counter, string signToCheck)
for (var i = 0; i < field.GetLength(0); i++)
if(field[i, 0] == signToCheck)
if (field[i, 0] == field[i, 1] && field[i, 1] == field[i, 2])
var winningCell = field[i, 0];
Console.WriteLine("Player 1 is the winner");
Console.WriteLine("Player 2 is the winner");
for (var i = 0; i < field.GetLength(1); i++)
if (field[0, i] == signToCheck)
if (field[0, i] == field[1, i] && field[1, i] == field[2, i])
var winningCell = field[0, i];
Console.WriteLine("Player 1 is the winner");
Console.WriteLine("Player 2 is the winner");
if(signToCheck == field[0, 0] || signToCheck == field[2, 0])
if(field[0, 0] == field[1, 1] && field[1, 1] == field[2, 2])
var winningCell = field[0, 0];
Console.WriteLine("Player 1 is the winner");
Console.WriteLine("Player 2 is the winner");
if (field[2, 0] == field[1, 1] && field[1, 1] == field[0, 2])
var winningCell = field[0, 0];
Console.WriteLine("Player 1 is the winner");
Console.WriteLine("Player 2 is the winner");
static public void Play()
var field = CreateField();
Player player1 = new Player();
player1.Name = "player1";
Player player2 = new Player();
player2.Name = "player2";
if (player1.Status == true)
Console.WriteLine("Player 1 turn - you are playing with X");
var coordinates = AskCoordinates();
coordinates = CheckRange(coordinates);
coordinates = isCellEmpty(coordinates, field);
field = Drawing(coordinates, field, true);
player1.Status = !player1.Status;
gameStatus = IsFinished(gameStatus, field, counter, "X");
Console.WriteLine("Player 2 turn - you are playing with O");
var coordinates = AskCoordinates();
coordinates = CheckRange(coordinates);
coordinates = isCellEmpty(coordinates, field);
field = Drawing(coordinates, field, false);
player1.Status = !player1.Status;
gameStatus = IsFinished(gameStatus, field, counter, "O");