Example #1
0
    public void startGame()
    {
        CheckPosition check_p = new CheckPosition();
        Dictionary <string, string> winner = new Dictionary <string, string>();
        string pos;

        int[] idx;
        int   turn = 0;

        while (true)
        {
            Console.Write($"{this.users[turn]["name"]} enter position: ");
            pos = Console.ReadLine();
            Console.WriteLine();
            idx = check_p.findIndex(board, pos);
            if (idx[0] != -1)
            {
                if (turn == 0)
                {
                    board[idx[0], idx[1]] = "X";
                    turn = 1;
                }
                else
                {
                    board[idx[0], idx[1]] = "O";
                    turn = 0;
                }
            }
            else
            {
                Console.WriteLine("Position is no longer available ");
            }
            this.displayBoard();
            winner = check_p.findWinner(this.board, this.users);
            if (winner["type"] == "winner")
            {
                Console.WriteLine($"{winner["message"]} is the winner !!!");
                Console.WriteLine();
                break;
            }
            else if (winner["type"] == "no")
            {
                Console.WriteLine(winner["message"]);
                Console.WriteLine();
                break;
            }
        }
    }