Beispiel #1
0
        private static char GetChar(BoardModel boardModel, int index)
        {
            var cell = boardModel.Cells[index];

            if (cell.IsEmpty())
            {
                return(' ');
            }
            return(cell.IsPlayer1() ? 'x' : 'o');
        }
Beispiel #2
0
 public static void Show(BoardModel m)
 {
     Console.Clear();
     Console.WriteLine(
         "  a b c\n" +
         " ┌─────┐\n" +
         "1│" + GetChar(m, 0) + " " + GetChar(m, 1) + " " + GetChar(m, 2) + "│\n" +
         "2│" + GetChar(m, 3) + " " + GetChar(m, 4) + " " + GetChar(m, 5) + "│\n" +
         "3│" + GetChar(m, 6) + " " + GetChar(m, 7) + " " + GetChar(m, 8) + "│\n" +
         " └─────┘");
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            var boardModel = new BoardModel();

            while (true)
            {
                BoardView.Show(boardModel);
                Console.WriteLine("Skriv inn hvor du vil sette kryss (f.eks. \"a2\"): ");
                var position = Console.ReadLine();
                var col      = position[0] - 'a'; // eks a = 1    b = 2   c = 3
                var row      = position[1] - '1'; // 1
                var index    = row * 3 + col;     // 3   eks c3  2*3 +2 = 8
                boardModel.SetCross(index);
                BoardView.Show(boardModel);
                return;
            }
        }