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

            if (cell.IsEmpty())
            {
                return(' ');
            }
            return(cell.IsPlayer1() ? 'x' : 'o');
        }
示例#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" +
         " └─────┘");
 }
示例#3
0
        static void Main(string[] args)
        {
            var boardModel = new BoardModel();

            while (true)
            {
                BoardView.Show(boardModel);
                Console.Write("Skriv inn hvor du vil sette kryss (f.eks. \"a2\"): ");
                var position = Console.ReadLine();
                var col      = position[0] - 'a';
                var row      = position[1] - '1';
                var index    = row * 3 + col;
                boardModel.SetPlayer1(index);
                BoardView.Show(boardModel);
                Thread.Sleep(700);
                var success = boardModel.SetRandomPlayer2();
                if (!success)
                {
                    return;
                }
            }
        }
示例#4
0
        public static void Show(BoardModel boardModel)
        {
            Console.Clear();
            var checkWinner = boardModel.IsWinning();
            var content     = boardModel.Content;

            Console.WriteLine("  a b c");
            Console.WriteLine(" ┌─────┐");

            ShowOneLine(0, content);
            ShowOneLine(3, content);
            ShowOneLine(6, content);

            Console.WriteLine(" └─────┘");

            if (checkWinner != CellContent.None)
            {
                var winner = checkWinner == CellContent.Circle ? "Datamaskinen" : "Du";
                Console.WriteLine("\n" + winner + " har vunnet!");
                Environment.Exit(0);
            }
            ;
        }