Ejemplo n.º 1
0
        public static void MultiplayerGame(Player player, GameSettings gs)
        {
            QuestionDisplay qD      = new QuestionDisplay();
            MatchRequest    request = new MatchRequest(gs);

            qD.displayStart(8, "Waiting for match...");

            ClientSend.Servercall(request.IP + gs.amountOfQuestions);

            string matchID = ClientReceive.ReceiveMessage();

            while (matchID.Equals("no"))
            {
                matchID = ClientReceive.ReceiveMessage();
                Thread.Sleep(3000);
            }

            ModeSolo.SoloGame(player, gs);

            ClientSend.Servercall(request.IP + matchID + player.Score);

            int opponentScore = Int32.Parse(ClientReceive.ReceiveMessage());

            while (opponentScore == 0)
            {
                opponentScore = Int32.Parse(ClientReceive.ReceiveMessage());
                Thread.Sleep(3000);
            }

            if (opponentScore < player.Score)
            {
                qD.displayStart(8, "You won the game! " + player.Score + " to " + opponentScore);
                player.WonGames = player.WonGames + 1;
                player.UpdatePlayerStats(player);
            }
            else if (opponentScore > player.Score)
            {
                qD.displayStart(8, "Your opponent won the game, with " + opponentScore + " points");
                Thread.Sleep(2000);
            }
        }
Ejemplo n.º 2
0
        public static void SoloGame(Player player, GameSettings gS)
        {
            Boolean waitingForInput = false;
            Boolean insideQuestion  = false;

            String[] questionAnswersBoolean = { "True", "False" };

            QuestionSeperater qS          = new QuestionSeperater();
            QuestionDisplay   qD          = new QuestionDisplay();
            ProfileUpdater    updater     = new ProfileUpdater();
            PointCalculater   pCalculater = new PointCalculater();
            ModeGameSettings  mgs         = new ModeGameSettings();

            //Fetches the question string from the website (edit the last number to how many questions you want.
            WebClient client = new WebClient();
            string    sb     = WebUtility.HtmlDecode(client.DownloadString(mgs.GameSettingURL(gS)));

            //Places the questions into an array of questions
            Questions[] questions = qS.QSeperate(sb);

            qD.displayStart(15, "Press Enter To Start The Game");

            waitingForInput = true;
            while (waitingForInput)
            {
                if (string.IsNullOrEmpty(Console.ReadLine()))
                {
                    Thread.Sleep(1000);
                    qD.displayStart(8, "Use the A,B,C,D keys to indicate your answer");
                    Thread.Sleep(2000);
                    qD.displayStart(8, "You have 15 secounds to answer each question");
                    Thread.Sleep(2000);
                    waitingForInput = false;
                }
                else
                {
                    qD.displayStart(15, "Invalid input, please press enter");
                }
            }

            for (int i = 0; i < questions.Length - 2; i++)
            {
                if (questions[i].Type.Equals("multiple"))
                {
                    String[] questionAnswersMultiple = MixerBag.OptionMixer(questions[i].CorrectAnswer, questions[i].IncorrectAnswer);

                    //Displays the question, with the options.
                    qD.gameDisplayMultiple(player.Name, player.Score, questions[i].Question,
                                           questionAnswersMultiple[0], questionAnswersMultiple[1], questionAnswersMultiple[2], questionAnswersMultiple[3]);

                    waitingForInput = true;
                    insideQuestion  = true;

                    while (insideQuestion)
                    {
                        Thread t = new Thread(pCalculater.Count);
                        t.Start();

                        while (waitingForInput)
                        {
                            //await answer input
                            char answer = Answer();

                            if (qS.IsValidAnswerMultiple(answer))
                            {
                                if (qS.IsCorrectAnswerMultiple(answer, questionAnswersMultiple, questions[i]))
                                {
                                    qD.displayStart(15, "That's correct! ");
                                    updater.UpdateProfileCorrectAnswer(player, pCalculater.GetPoints());

                                    Thread.Sleep(1000);
                                    pCalculater.ResetPointCounter();
                                    waitingForInput = false;
                                }
                                else
                                {
                                    qD.displayStart(15, "The correct answer was: " + questions[i].CorrectAnswer);
                                    updater.UpdateProfileIncorrectAnswer(player);

                                    Thread.Sleep(2000);
                                    waitingForInput = false;
                                }
                            }
                            else
                            {
                                qD.displayStart(8, "Invalid input, please use A, B, C or D.");
                                Thread.Sleep(2000);
                                qD.gameDisplayMultiple(player.Name, player.Score, questions[i].Question,
                                                       questionAnswersMultiple[0], questionAnswersMultiple[1], questionAnswersMultiple[2], questionAnswersMultiple[3]);
                            }
                        }
                        insideQuestion = false;
                    }
                }

                else if (questions[i].Type.Equals("boolean"))
                {
                    //Displays the question with True or False.
                    qD.gameDisplayBoolean(player.Name, player.Score, questions[i].Question);

                    waitingForInput = true;
                    insideQuestion  = true;

                    while (insideQuestion)
                    {
                        Thread t = new Thread(pCalculater.Count);
                        t.Start();

                        while (waitingForInput)
                        {
                            //await answer input
                            char answer = Answer();

                            if (qS.IsValidAnswerBool(answer))
                            {
                                if (qS.IsCorrectAnswerBoolean(answer, questionAnswersBoolean, questions[i]))
                                {
                                    qD.displayStart(15, "That's correct! ");
                                    updater.UpdateProfileCorrectAnswer(player, pCalculater.GetPoints());

                                    Thread.Sleep(1000);
                                    pCalculater.ResetPointCounter();
                                    waitingForInput = false;
                                }
                                else
                                {
                                    qD.displayStart(15, "The correct answer was: " + questions[i].CorrectAnswer);
                                    updater.UpdateProfileIncorrectAnswer(player);

                                    Thread.Sleep(2000);
                                    waitingForInput = false;
                                }
                            }
                            else
                            {
                                qD.displayStart(8, "Invalid input, please use A, B.");
                                Thread.Sleep(2000);
                                qD.gameDisplayBoolean(player.Name, player.Score, questions[i].Question);
                            }
                        }
                        insideQuestion = false;
                    }
                }
            }

            if (player.Score == 0)
            {
                player.Score = -1;
            }

            if (player.Score > player.Gethighscore(player.Name))
            {
                player.Highscore = player.Score;
            }

            player.UpdatePlayerStats(player);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            QuestionSeperater qS     = new QuestionSeperater();
            QuestionDisplay   qD     = new QuestionDisplay();
            ModeProfile       profil = new ModeProfile();
            ModeGameSettings  mgs    = new ModeGameSettings();

            Boolean menuMode = true;
            Boolean gameOn   = false;
            char    answer;

            qD.displayStart(15, "Please enter you name.");
            String username = Console.ReadLine();

            //Creates a player object
            Player player = new Player
            {
                Name = username
            };

            //creates a player in the database with username
            Player.GetPlayerStats(player);

            //Creates the default game settings
            GameSettings gS = new GameSettings(10, "any", "any");


            qD.displayStart(8, "Welcome");
            Thread.Sleep(1500);

            while (menuMode)
            {
                qD.GameDisplayMode(player.Name, "What do you want to do?", "Play solo.", "Find match", "Go to Profile", "Edit game settings", "Press X to exit");

                //await answer input
                answer = char.ToLower(Console.ReadKey().KeyChar);

                if (qS.IsValidAnswerMultiple(answer))
                {
                    switch (answer)
                    {
                    case 'a':
                        ModeSolo.SoloGame(player, gS);
                        qD.gameDisplayMultiple(player.Name, player.Score, "Thanks for playing! Here are your stats:",
                                               "Correct answers: " + player.CorrectAnswers,
                                               "Total answered questions: " + player.AnsweredQuestions,
                                               "Highscore: " + player.Highscore,
                                               ""
                                               );
                        Thread.Sleep(2000);
                        player.Score = 0;
                        break;

                    case 'b':
                        ModeMulti.MultiplayerGame(player, gS);
                        qD.gameDisplayMultiple(player.Name, player.Score, "Thanks for playing! Here are your stats:",
                                               "Correct answers: " + player.CorrectAnswers,
                                               "Total answered questions: " + player.AnsweredQuestions,
                                               "Highscore: " + player.Highscore,
                                               "Won Games: " + player.WonGames
                                               );
                        Thread.Sleep(2000);
                        player.Score = 0;
                        break;

                    case 'c':
                        profil.ProfilePage(player);
                        break;

                    case 'd':
                        mgs.GameSettings(player, gS);
                        break;

                    case 'x':
                        menuMode = false;
                        break;
                    }
                }

                while (gameOn)
                {
                    gameOn = false;
                }
            }
        }