Skip to content

Instantly share code, notes, and snippets.

@hamoungh
Created November 19, 2014 20:35
Show Gist options
  • Save hamoungh/3baacabfb57c563cd6be to your computer and use it in GitHub Desktop.
Save hamoungh/3baacabfb57c563cd6be to your computer and use it in GitHub Desktop.
using System;
namespace tic_tac_toe
{
class Program
{
public static int EMPTY = 0;
public static int Xchar=1;
public static int Ochar = 2;
int[,] matrix = new int[3, 3];
char[] sym = {' ','X','O' };
void initialize_game()
{
for (int i = 0; i < matrix.GetLength(0); i++)
for (int j = 0; j < matrix.GetLength(1); j++)
matrix[i, j] = EMPTY;
}
void draw()
{
for (int i = 0; i < matrix.GetLength(0); i++){
Console.WriteLine("{0}|{1}|{2}",
sym[matrix[i, 0]],
sym[matrix[i, 1]],
sym[matrix[i, 2]]);
if (i!=2) Console.WriteLine("-|-|-");
}
}
public void get_player_move()
{
Console.WriteLine("Enter X,Y coordinates for your move: ");
int i = int.Parse(Console.ReadLine());
int j = int.Parse(Console.ReadLine());
i--; j--;
matrix[i, j] = Xchar;
}
static void Main(string[] args)
{
Program p = new Program();
p.initialize_game();
p.draw();
p.get_player_move();
p.draw();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment