Пример #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);
            }
        }
Пример #2
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;
                }
            }
        }