Exemplo n.º 1
0
    public static Player GameMode2(ListOfQuestions questions,
                                   Square[] squareArray, int actualPosition, Player actualPlayer, Board board,
                                   List <Player> playersList, ref bool exit)
    {
        // 5 questions max for a player who choose correct answer
        string category     = squareArray[actualPosition].category;
        bool   correct      = false;
        ushort count        = 0;
        ushort maxQuestions = 5;

        do
        {
            DrawAll(playersList, board, squareArray);
            Question questionAux = questions.GetFromCategoryNR(
                category);
            if (questionAux == null)
            {
                Console.WriteLine("No question avaliable");
                exit = true;
            }
            else
            {
                correct = QuestionShow(questionAux);
                actualPlayer.AttemptedQuestions[category] =
                    actualPlayer.AttemptedQuestions[category] + 1;

                if (correct)
                {
                    actualPlayer.AcceptedQuestions[category] =
                        actualPlayer.AcceptedQuestions[category] + 1;
                    Console.SetCursorPosition(0, 26);
                    int dice = Dice();
                    Console.WriteLine("Dice: {0}", dice);
                    // SelectNewPosition,set the console cursor at the top position 28
                    SelectNewPosition(ref actualPosition, dice,
                                      squareArray);
                }
            }
            actualPlayer.Position = actualPosition;
            count++;
        } while (correct && count < maxQuestions);

        return(actualPlayer);
    }
Exemplo n.º 2
0
        public List <Questions> GetQuestions()
        {
            connection.Open();
            MySqlCommand cmd    = new MySqlCommand("SELECT * FROM `Questions`", connection);
            var          reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ListOfQuestions.Add(new Questions()
                {
                    Id     = Convert.ToInt32(reader["Id"]),
                    Header = reader["Header"].ToString(),
                    Text   = reader["Text"].ToString(),
                    IsPast = Convert.ToBoolean(reader["IsPast"])
                });
            }
            connection.Close();
            return(ListOfQuestions);
        }
Exemplo n.º 3
0
    public static Player GameMode3(ListOfQuestions questions,
                                   Square[] squareArray, int actualPosition, Player actualPlayer, ref bool exit)
    {
        // only one question
        string category = squareArray[actualPosition].category;
        bool   correct  = false;

        Question questionAux = questions.GetFromCategoryNR(
            category);

        if (questionAux == null)
        {
            Console.WriteLine("No question avaliable");
            exit = true;
        }
        else
        {
            correct = QuestionShow(questionAux);
            actualPlayer.AttemptedQuestions[category] =
                actualPlayer.AttemptedQuestions[category] + 1;

            if (correct)
            {
                actualPlayer.AcceptedQuestions[category] =
                    actualPlayer.AcceptedQuestions[category] + 1;
                Console.SetCursorPosition(0, 26);
                int dice = Dice();
                Console.WriteLine("Dice: {0}", dice);
                // SelectNewPosition,set the console cursor at the top position 28
                SelectNewPosition(ref actualPosition, dice,
                                  squareArray);
            }
        }
        actualPlayer.Position = actualPosition;

        return(actualPlayer);
    }
Exemplo n.º 4
0
    public void Run()
    {
        Board           board       = new Board();
        ListOfQuestions questions   = new ListOfQuestions();
        List <Player>   playersList = new List <Player>();

        bool   exit           = false;
        ushort totalPlayers   = 0;
        ushort actualPlayer   = 0;
        ushort gameMode       = 0;
        int    actualPosition = 0;

        Square[] squareArray = CreateBoard();

        // players select
        PlayersSelect(ref totalPlayers, playersList);

        // Game mode select
        GameModeSelect(ref gameMode);

        // Game Loop
        while (!exit)
        {
            //clear and draw the board
            DrawAll(playersList, board, squareArray);

            Console.SetCursorPosition(11, 10);
            Console.WriteLine("{0} playing... ",
                              playersList[actualPlayer].Name);

            // Enter for roll the dice and exit the game
            Console.SetCursorPosition(0, 27);
            Console.WriteLine("Press Enter for roll the dice");

            if (Console.ReadKey().Key == ConsoleKey.Escape)
            {
                exit = ExitGame();
            }

            if (!exit)
            {
                Console.SetCursorPosition(0, 26);
                int dice = Dice();
                Console.WriteLine("Dice: {0}", dice);
                // SelectNewPosition,set the console cursor at the top position 28
                SelectNewPosition(ref actualPosition, dice,
                                  squareArray);
            }

            // Game mode
            if (!exit)
            {
                Player auxPlayer = playersList[actualPlayer];
                switch (gameMode)
                {
                case 1:
                    auxPlayer = GameMode1(questions, squareArray,
                                          actualPosition, playersList[actualPlayer],
                                          board, playersList, ref exit);
                    break;

                case 2:
                    auxPlayer = GameMode2(questions, squareArray,
                                          actualPosition, playersList[actualPlayer],
                                          board, playersList, ref exit);
                    break;

                case 3:
                    auxPlayer = GameMode3(questions, squareArray,
                                          actualPosition, playersList[actualPlayer],
                                          ref exit);
                    break;
                }

                playersList[actualPlayer] = auxPlayer;
            }

            // Check if the game end
            const int pointsToWin = 20;
            foreach (Player p in playersList)
            {
                int totalPoints = 0;
                foreach (KeyValuePair <string, int> k in p.AcceptedQuestions)
                {
                    totalPoints = k.Value;
                }

                if (totalPoints >= pointsToWin)
                {
                    exit = true;
                    Console.WriteLine("{0} win!, press Enter for exit",
                                      p.Name);
                    Console.ReadLine();
                }
            }

            // Next Player turn
            if (!exit)
            {
                actualPlayer++;
                if (actualPlayer == totalPlayers)
                {
                    actualPlayer = 0;
                }
            }
        }
    }