Exemplo n.º 1
0
        public static void UpdatePlayer(Player oldPlayer, Player newPlayer)
        {
            for (int i = 0; i < players.Count; i++)
            {
                if (players.ToArray()[i].ID == oldPlayer.ID)
                {
                    players.ToArray()[i] = rejoinedPlayer;
                    break;
                }
            }

            for (int i = 0; i < leadPlayer.Count; i++)
            {
                if (leadPlayer.ToArray()[i].ID == oldPlayer.ID)
                {
                    leadPlayer.ToArray()[i] = rejoinedPlayer;
                    break;
                }
            }

            GameScheduler.Resume();
        }
Exemplo n.º 2
0
 public void PlayerNotConnected(Player player)
 {
     MainGame.Instance.GeneralMessageQueue.Enqueue("Please wait for " + player.Name + " to rejoin");
     GameScheduler.Pause();
     debugOut("[Error] Player not connected: " + player.Name + ".");
 }
Exemplo n.º 3
0
        private void SetupRejoinedPlayer(Player oldPlayer, Player newPlayer)
        {
            if (!gameStarted)
            {
                return;
            }
            restoringState = true;
            Thread.Sleep(SLEEP_TIME);
            SendStartGameMessage(newPlayer);
            Thread.Sleep(SLEEP_TIME);
            Console.WriteLine(newPlayer.IP + ":" + newPlayer.Port);

            SendTrumpCard(GameScheduler.LastTrumpCard, newPlayer);
            Thread.Sleep(SLEEP_TIME);

            foreach (RawCard card in cardsInHands)
            {
                try {
                    if (card.Player == newPlayer.ID && !roundPlayedCards.Contains(card))
                    {
                        RawCard cardToSend = new RawCard(card.Suit, card.Number, card.Player);
                        Thread.Sleep(250);
                        cardToSend.Player = -1;

                        SendCard(cardToSend, newPlayer);

                        Console.WriteLine("[Rejoin] Hand card sent");

                        Thread.Sleep(SLEEP_TIME);
                    }
                } catch (Exception e) {
                    Console.WriteLine("[Rejoin error] " + e.Message);
                }
            }

            Console.WriteLine("[Rejoin] After cardsInHands");

            foreach (RawCard card in trickPlayedCards)
            {
                SendCard(card, newPlayer);
                Thread.Sleep(SLEEP_TIME);
                Console.WriteLine("[Rejoin] Played card sent");
            }

            Console.WriteLine("[Rejoin] After playedCards");

            foreach (Bid bid in bidsInRound)
            {
                SendBid(bid, newPlayer);
                Thread.Sleep(SLEEP_TIME);
                Console.WriteLine("[Rejoin] Bid sent");
            }

            Console.WriteLine("[Rejoin] After bidsInRound");

            if (lastRequestPlayer.ID == newPlayer.ID && lastBidRequest != null)
            {
                RequestBid(newPlayer, lastBidRequest.MaxBid);
            }
            else if (lastRequestPlayer.ID == newPlayer.ID && lastCardRequest != null)
            {
                RequestCard(newPlayer);
            }

            Thread.Sleep(SLEEP_TIME);

            Console.WriteLine("[Rejoin] After request sending");

            foreach (Score score in scores.GetAllScores())
            {
                try {
                    NetworkComms.SendObject("Score", newPlayer.IP, newPlayer.Port, score);
                    Thread.Sleep(SLEEP_TIME);
                } catch (Exception e) {
                    Console.WriteLine("[SetupRejoinedPlayer] Exception " + e.Message);
                }
            }

            Console.WriteLine("[Rejoin] After score sending");

            restoringState = false;
            GameScheduler.UpdatePlayer(oldPlayer, newPlayer);
        }
Exemplo n.º 4
0
        public PageHostGame(MainGame mainGame) : base(mainGame)
        {
            Arranger arranger = new Arranger(true, 2, 'C', ScaleManager.InterfaceScale * 2);

            spacer = new Arranger.ArrangerSpacer(100 * ScaleManager.InterfaceScale, false);
            addMovable(spacer);
            arranger.addObject(spacer, 0);

            ipField = new PatchField(2, 13, Vector2.Zero, ScaleManager.InterfaceScale, "IP", "Starting...", null, false);
            addField(ipField);
            arranger.addObject(ipField, 0);

            backButton = new PatchButton(5, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Back", () => {
                AudioHelper.play(ContentStore.soundPop);
                mainGame.menuController.changeActivePage(mainGame.preHostGame);
                UltraServer.Instance.network.CloseServer();
                UltraClient.Instance.network.CloseClient();
                for (int i = 1; i <= 6; i++)
                {
                    NineGridRow row              = joinedGrid.getRow(i.ToString());
                    row.getCell("player").Text   = "...";
                    row.getCell("player").Colour = Color.White;
                }
                ClientDataStore.Instance.resetPlayers();
            });
            addButton(backButton);
            arranger.addObject(backButton, 0);

            joinedGrid = new NineGrid(Vector2.Zero, ScaleManager.InterfaceScale, ScaleManager.LargeFont, new string[] { "player" }, new int[] { 13 });
            NineGridRow header = joinedGrid.addRow("header");

            header.getCell("player").Text      = "Players";
            header.getCell("player").Alignment = 'C';
            for (int i = 1; i <= 6; i++)
            {
                NineGridRow playerRow = joinedGrid.addRow(i.ToString());
                playerRow.getCell("player").Text      = ("...");
                playerRow.getCell("player").Alignment = 'C';
            }
            addMovable(joinedGrid);
            arranger.addObject(joinedGrid, 1);

            beginButton = new PatchButton(13, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Begin!", () => {
                AudioHelper.play(ContentStore.soundPop);

                int playerCount = UltraServer.Instance.network.Players.GetPlayers().Count;
                if ((playerCount < 3 && SettingsHelper.Instance.PlayerCountCheck) || (!SettingsHelper.Instance.PlayerCountCheck && playerCount == 0))
                {
                    if (!SettingsHelper.Instance.PlayerCountCheck)
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least 1 more player must join!");
                        return;
                    }

                    if (3 - playerCount > 1)
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least " + (3 - playerCount) + " more players must join!");
                    }
                    else
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least " + (3 - playerCount) + " more player must join!");
                    }

                    return;
                }

                if (mainGame.HostOnly)
                {
                    mainGame.gameIsRunning = true;
                    UltraServer.Instance.network.SendStartGameMessage();
                    GameScheduler.initialise(UltraServer.Instance.network.Players.GetPlayers(), UltraServer.Instance.network, UltraServer.Instance);
                    UltraServer.Instance.HostStarted();
                }
                else
                {
                    UltraServer.Instance.network.SendStartGameMessage();
                    GameScheduler.initialise(UltraServer.Instance.network.Players.GetPlayers(), UltraServer.Instance.network, UltraServer.Instance);
                }

                Thread schedulerThread = new Thread(new ThreadStart(GameScheduler.schedulerThread));
                schedulerThread.Start();
            });
            addButton(beginButton);
            arranger.addObject(beginButton, 1);

            arranger.performArrangements();
        }