Inheritance: Entity
Esempio n. 1
0
        public WrapTest()
        {
            ClearColor = Color.White;

            foreach (CardLoader.CardDeck deck in CardLoader.Decks)
                deck.Include = true;

            CardLoader.LoadCards();

            blackDeck = new Deck(CardType.Black);

            card = null;

            Input.Key.Add(Keyboard.Key.Return,  args =>
            {
                if (!args.Pressed)
                    return true;

                if (card != null)
                    Entities.Remove(card);

                card = blackDeck.Cards.Count == 0 ? null : new Card(blackDeck.Cards.Pop());
                if (card != null)
                {
                    card.Position = new Vector2f(GameOptions.Width / 2.0f - 256.0f, GameOptions.Height / 2.0f - 256.0f);
                    Entities.Add(card);
                }

                return true;
            });
        }
        public SelectionScreen(ICollection<Tuple<ushort, List<string>>> options)
        {
            isCzar = ((InGame)Game.PeekFirstState()).LocalPlayer.Czar;

            Vector2f position = new Vector2f(GameOptions.Width / 2.0f - ((241.0f * 0.95f) * (options.Count - 1)) / 2.0f, 256.0f + 346.0f + 48.0f);
            foreach (Tuple<ushort, List<string>> option in options)
            {
                float yOffset = 0.0f;
                foreach (string cardValue in option.Item2)
                {
                    Card card = new Card(new CardInfo(CardType.White, cardValue))
                    {
                        Position = position + new Vector2f((-(241.0f * 0.95f) / 2.0f) * 1.0f, -346.0f - 128.0f + yOffset),
                        Scale = new Vector2f(0.95f, 0.95f)
                    };

                    Entities.Add(card);

                    yOffset += 96.0f;
                }

                if (isCzar)
                {
                    SelectButton dismissButton = new SelectButton(position + new Vector2f(0.0f, -346.0f + 56.0f + 32.0f + yOffset - 3.0f), "Pick");
                    dismissButton.Position = new Vector2f((float) Math.Floor(dismissButton.Position.X),
                                                          (float) Math.Floor(dismissButton.Position.Y));
                    Tuple<ushort, List<string>> option1 = option;
                    dismissButton.OnClick += () =>
                    {
                        Client.SendMessage(new DeclareWinner(option1.Item1));
                        Game.PopState();
                    };

                    Entities.Add(dismissButton);
                }

                position += new Vector2f(228.0f, 0.0f);
            }

            Assets.PlaySound("Boop.wav");
        }
Esempio n. 3
0
        private static void HandlePacket(Packet packet)
        {
            Console.WriteLine(packet.Type);

            switch (packet.Type)
            {
                case PacketType.ServerTime:
                    SecondsLeft = ((ServerTime)packet).Seconds;
                    break;

                case PacketType.SetStatus:
                    {
                        SetStatus setStatus = (SetStatus)packet;
                        players[setStatus.Id].Thinking = setStatus.TurnOver;
                        break;
                    }

                case PacketType.GameOver:
                    Game.PushState(new GameOverScreen());
                    break;

                case PacketType.InitSelectionScreen:
                    {
                        InitSelectionScreen initSelectionScreen = (InitSelectionScreen)packet;
                        Game.PushState(new SelectionScreen(initSelectionScreen.Options));
                        InMatch = false;
                        break;
                    }

                case PacketType.SelectCardCzar:
                    {
                        SelectCardCzar selectCardCzar = (SelectCardCzar)packet;
                        InGame game = (InGame)Game.PeekFirstState();

                        foreach (Player p in game.Players)
                            p.Czar = false;

                        if (players.ContainsKey(selectCardCzar.Id))
                            players[selectCardCzar.Id].Czar = true;
                        else
                            game.LocalPlayer.Czar = true;

                        foreach (Player p in game.Entities.OfType<Player>())
                            p.Thinking = !p.Czar;

                        break;
                    }

                case PacketType.WinnerPicked:
                    {
                        if (Game.PeekState().GetType() != typeof(GameOverScreen))
                        {
                            InMatch = true;
                            Game.PopState();

                            WinnerPicked winnerPicked = (WinnerPicked)packet;
                            InGame game = (InGame)Game.PeekState();

                            if (winnerPicked.Id != 0)
                            {
                                Player player = players.ContainsKey(winnerPicked.Id) ? players[winnerPicked.Id] : game.LocalPlayer;
                                ++player.Score;

                                Game.PushState(new WinnerScreen(player.Name, CurrentBlackCard.Info.Value, winnerPicked.Cards));
                            }
                            else
                                Game.PushState(new WinnerScreen("No one", CurrentBlackCard.Info.Value, new List<string>()));
                        }
                        break;
                    }

                case PacketType.WhiteCard:
                    {
                        WhiteCard whiteCards = (WhiteCard)packet;

                        foreach (CardInfo c in whiteCards.Cards)
                        {
                            Card card = new Card(c)
                            {
                                Position = new Vector2f(-1024.0f, -1024.0f),
                                Scale = new Vector2f(0.643f * 0.8f, 0.643f * 0.8f)
                            };

                            Hand.Add(card);
                            Game.PeekFirstState().Entities.Add(card);
                        }

                        if (Hand.Any(c => c.Info.Value.Contains("brain")) && !gotBrainTumorOnce)
                        {
                            Assets.PlaySound("BrainTumorCardStart.wav");
                            gotBrainTumorOnce = true;
                        }
                        else if (random.Next(100) < 5)
                            Assets.PlaySound("NoBrainTumorCardStart5.wav");

                        break;
                    }

                case PacketType.BlackCard:
                    {
                        BlackCard blackCard = (BlackCard)packet;

                        if (CurrentBlackCard != null)
                            Game.PeekFirstState().Entities.Remove(CurrentBlackCard);

                        CurrentBlackCard = new Card(blackCard.Card)
                            { Position = new Vector2f(GameOptions.Width - 256.0f + 4.0f, 48.0f + 32.0f) };
                        Game.PeekFirstState().Entities.Add(CurrentBlackCard);
                        break;
                    }

                case PacketType.LobbyBeginGame:
                    Game.SetState(new InGame(((Lobby)Game.PeekState()).Players));
                    InMatch = true;
                    break;

                case PacketType.PlayerDelete:
                    {
                        PlayerDelete playerDelete = (PlayerDelete)packet;
                        Game.PeekFirstState().Entities.Remove(players[playerDelete.Id]);
                        players.Remove(playerDelete.Id);

                        break;
                    }

                case PacketType.PlayerNew:
                    {
                        PlayerNew playerNew = (PlayerNew)packet;
                        Player player = new Player(playerNew.Name);
                        players.Add(playerNew.Id, player);

                        Game.PeekState().Entities.Add(player);
                        break;
                    }

                case PacketType.ChatMessage:
                    {
                        ChatMessage chatMessage = (ChatMessage)packet;
                        if (Game.PeekState().GetType() == typeof(Lobby))
                            ((Lobby)Game.PeekState()).ChatBacklog.Add(chatMessage.Value);
                        else
                            ((InGame)Game.PeekFirstState()).ChatBacklog.Add(chatMessage.Value);

                        GameUtility.PlayTaunt(chatMessage.Value);

                        Assets.PlaySound("Bubble.wav");
                        break;
                    }

                default:
                    Console.WriteLine("Unhandled packet!");
                    break;
            }
        }