Esempio n. 1
0
        //Update the black cards whenever the UI is edited.
        public void UpdateBlackDeck()
        {
            foreach (DataGridViewRow row in dataGridView2.Rows)
            {
                if (!row.IsNewRow)
                {
                    try
                    {
                        string content = row.Cells[0].Value.ToString();
                        int    blanks  = Convert.ToInt32(row.Cells[1].Value);

                        //Enforce a minimum of 1 blank
                        if (blanks < 1)
                        {
                            blanks             = 1;
                            row.Cells[1].Value = blanks;
                        }

                        BlackCard newCard = new BlackCard(content, blanks);
                        currentDeck.Add(newCard);
                    }
                    catch { }
                }
            }

            textBoxNumBlack.Text = Convert.ToString(currentDeck.BlackCards.Count);
        }
        public async void RecordBlackCardSkip(BlackCard card)
        {
            if (!IsActive)
            {
                return;
            }
            await Task.Run(() =>
            {
                lock (_dbLock)
                {
                    try
                    {
                        var table  = _db.GetCollection <CardFrequencyRecord>(SkippedBlackCardsTableName);
                        var record = table.FindById(card.Id);
                        if (record == null)
                        {
                            record = new CardFrequencyRecord
                            {
                                CardId = card.Id,
                                Count  = 0
                            };
                            table.Insert(record);
                        }
                        record.Count++;
                        table.Update(record);

                        table.EnsureIndex(r => r.CardId);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed to record skipped black card in DB: {ex.Message}");
                    }
                }
            });
        }
Esempio n. 3
0
    public Card createCard(int cardId)
    {
        Card card = null;

        switch (cardId)
        {
        case 1001:
            card = new PortalCard();
            break;

        case 1002:
            card = new StrengtheningTowerCard();
            break;

        case 1003:
            card = new StrengtheningAllTowerCard();
            break;

        case 1004:
            card = new OilCard();
            break;

        case 1005:
            card = new SnowstormCard();
            break;

        case 1006:
            card = new BarrierCard();
            break;

        case 1007:
            card = new HornCard();
            break;

        case 1008:
            card = new CrazyCard();
            break;

        case 1009:
            card = new HardeningCard();
            break;

        case 1010:
            card = new UpgradeCard();
            break;

        case 1011:
            card = new BlackCard();
            break;

        case 1012:
            card = new WhiteCard();
            break;
        }
        return(card);
    }
Esempio n. 4
0
        public void TestMethod1()
        {
            //Arrange
            BlackCard blackCard = new BlackCard();
            //Act
            BlackCard randomBlackCard = blackCard.GetBlackCard();

            //Assert
            Assert.IsNotNull(randomBlackCard);
        }
Esempio n. 5
0
        private void OnGameRoundEnded(int round, BlackCard blackCard, Player roundJudge, Player roundWinner, bool ego, WhiteCard[] winningPlay)
        {
            var czar = Game.Judge;

            var args = new
            {
                winner = roundWinner.Name
            };

            TriggerBotTaunts(args,
                             bot => EnumerateCardTaunts(bot, czar, round, roundWinner, winningPlay),
                             bot => EnumerateEventTaunts(bot, "lost_round", b => b != roundWinner && b != czar));
        }
Esempio n. 6
0
        public static Deck[] Parse(string json)
        {
            JToken raw           = JsonConvert.DeserializeObject(json) as JToken;
            JArray allBlackCards = raw["blackCards"] as JArray;

            string[] allWhiteCards = raw["whiteCards"].ToObject <string[]>();
            string[] order         = raw["order"].ToObject <string[]>();

            Deck[] decks = new Deck[order.Length];
            for (int i = 0; i < order.Length; i++)
            {
                JToken jsonDeck         = raw[order[i]];
                string deckName         = jsonDeck["name"].ToObject <string>();
                int[]  whiteCardIndexes = jsonDeck["white"].ToObject <int[]>();
                int[]  blackCardIndexes = jsonDeck["black"].ToObject <int[]>();

                string[] whiteCards = new string[whiteCardIndexes.Length];
                if (whiteCardIndexes.Length != 0)
                {
                    int startIndex = whiteCardIndexes[0];
                    for (int j = 0; j < whiteCards.Length; j++)
                    {
                        whiteCards[j] = Format(allWhiteCards[startIndex + j]);
                    }
                }

                BlackCard[] blackCards = new BlackCard[blackCardIndexes.Length];
                if (blackCardIndexes.Length != 0)
                {
                    int startIndex = blackCardIndexes[0];
                    for (int j = 0; j < blackCards.Length; j++)
                    {
                        blackCards[j] = new BlackCard()
                        {
                            Text = Format(allBlackCards[startIndex + j]["text"].ToObject <string>()),
                            Pick = allBlackCards[startIndex + j]["pick"].ToObject <int>()
                        };
                    }
                }

                decks[i] = new Deck()
                {
                    Name       = deckName,
                    WhiteCards = whiteCards,
                    BlackCards = blackCards
                };
            }

            return(decks);
        }
        public async void RecordWinningPlay(BlackCard blackCard, IEnumerable <WhiteCard> whiteCards, bool isWinnerBot, bool isJudgeBot)
        {
            if (!IsActive)
            {
                return;
            }
            await Task.Run(() =>
            {
                lock (_dbLock)
                {
                    try
                    {
                        var whiteCardListString = string.Join(";", whiteCards.Select(w => w.IsCustom ? "custom" : w.Id));
                        var table  = _db.GetCollection <WinningPlayRecord>(WinningPlaysTableName);
                        var record = table.FindOne(r =>
                                                   r.IsPlayerBot == isWinnerBot &&
                                                   r.IsJudgeBot == isJudgeBot &&
                                                   r.BlackCard == blackCard.Id &&
                                                   r.WhiteCards == whiteCardListString);

                        if (record == null)
                        {
                            record = new WinningPlayRecord
                            {
                                Id          = ObjectId.NewObjectId(),
                                IsJudgeBot  = isJudgeBot,
                                IsPlayerBot = isWinnerBot,
                                BlackCard   = blackCard.Id,
                                WhiteCards  = whiteCardListString,
                                Count       = 0
                            };
                            table.Insert(record);
                        }
                        record.Count++;
                        table.Update(record);

                        table.EnsureIndex(r => r.BlackCard);
                        table.EnsureIndex(r => r.WhiteCards);
                        table.EnsureIndex(r => r.IsJudgeBot);
                        table.EnsureIndex(r => r.IsPlayerBot);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed to record winning play in DB: {ex.Message}");
                    }
                }
            });
        }
Esempio n. 8
0
        public static void PrepareBlackCard(View view, BlackCard currentQuestion)
        {
            var text = view.FindViewById <TextView>(Resource.Id.bc_CardText);

            if (AppFont != null)
            {
                var txtlogo = view.FindViewById <TextView>(Resource.Id.bc_logo_text);
                txtlogo.SetTypeface(AppFont, TypefaceStyle.Normal);
                text.SetTypeface(AppFont, TypefaceStyle.Normal);
            }

            if (currentQuestion != null)
            {
                text.TextFormatted = Html.FromHtml(currentQuestion.Text);
                text.SetTextSize(ComplexUnitType.Dip, currentQuestion.FontSize);
            }
        }
Esempio n. 9
0
        public async Task <IEnumerable <BlackCard> > GetBlackCardsAsync()
        {
            var blackCards = new ConcurrentBag <BlackCard>();

            using (var sr = new StreamReader(BlackCardFileLocation))
            {
                while (!sr.EndOfStream)
                {
                    var line = await sr.ReadLineAsync();

                    var card = new BlackCard {
                        RawValue = line, BlackCardId = Guid.NewGuid()
                    };
                    blackCards.Add(card);
                }
            }
            return(blackCards);
        }
Esempio n. 10
0
 private void OnGameRoundEnded(int round, BlackCard blackCard, Player roundJudge, Player roundWinner, WhiteCard[] winningPlay)
 {
     RecordWinningPlay(blackCard, winningPlay, roundJudge.IsAutonomous, roundWinner.IsAutonomous);
 }
Esempio n. 11
0
 private void OnGameBlackCardSkipped(BlackCard skippedCard, BlackCard replacementCard)
 {
     RecordBlackCardSkip(skippedCard);
 }
Esempio n. 12
0
 private void OnBlackCardSkipped(BlackCard skippedCard, BlackCard replacementCard)
 {
     SendSkipNotification(skippedCard.Id, replacementCard.Id);
 }
Esempio n. 13
0
        private static void UpdateGameState(GameState gameState)
        {
            var player = gameState.players.SingleOrDefault(p => p.id == PlayerId);

            PlayerHand  = new List <WhiteCard>();
            GameStarted = gameState.isStarted;
            GameName    = gameState.name;

            if (player != null)
            {
                foreach (var card in player.cards)
                {
                    PlayerHand.Add(new WhiteCard(card, 20));
                }
                IsCardCzar    = player.isCzar;
                IsReady       = player.isReady;
                AwesomePoints = player.awesomePoints;
                SelectedCard  = player.selectedWhiteCardId;
            }

            Players = new List <Player>();
            foreach (var p in gameState.players)
            {
                // Copy the object verbatim, but also mark ready if the round hasn't reached scoring yet, and the player has selected a card
                Players.Add(new Player()
                {
                    Id         = p.id,
                    Name       = p.name,
                    IsCardCzar = p.isCzar,
                    IsReady    = p.isReady ||
                                 (!gameState.isReadyForReview && !gameState.isReadyForScoring && (p.selectedWhiteCardId != null)),
                    AwesomePoints = p.awesomePoints
                });
            }
            MaxPlayers = gameState.maxPlayers;

            PlayedCards = new List <WhiteCard>();
            if (gameState.isReadyForScoring)
            {
                foreach (var card in gameState.players.Where(c => !string.IsNullOrEmpty(c.selectedWhiteCardId)).Select(c => c.selectedWhiteCardId))
                {
                    PlayedCards.Add(new WhiteCard(card, 20));
                }
            }
            PlayedCards = PlayedCards.OrderBy(c => rand.Next()).ToList();

            PlayersNotYetSubmitted = gameState.players.Where(c => string.IsNullOrEmpty(c.selectedWhiteCardId) && c.id != _playerId).Select(c => c.name).ToList();

            if (!string.IsNullOrWhiteSpace(gameState.currentBlackCard))
            {
                CurrentQuestion = new BlackCard(gameState.currentBlackCard, 20, 1, 0);
            }
            else
            {
                CurrentQuestion = null;
            }

            RequiredNumberOfPlayers = 3;
            ReadyToSelectWinner     = gameState.isReadyForScoring;
            ReadyForReview          = gameState.isReadyForReview;
            GameOver = gameState.isOver;

            if (ReadyForReview)
            {
                WinningCard = gameState.winningCardId;
                var winner = gameState.players.SingleOrDefault(c => c.selectedWhiteCardId == WinningCard);
                if (winner != null)
                {
                    RoundWinner = winner.name;
                }
                else
                {
                    RoundWinner = "Forgettable";
                }
            }
            else
            {
                RoundWinner = null;
                WinningCard = null;
            }

            if (gameState.winnerId != null)
            {
                var winner = gameState.players.SingleOrDefault(c => c.id == gameState.winnerId);
                if (winner != null)
                {
                    Winner = winner.name;
                }
                else
                {
                    Winner = "Nobody";
                }
            }

            Game_Update?.Invoke(null, new GameUpdateEventArgs(gameState));
        }
Esempio n. 14
0
        public static Message DeserializeMessageXML(String message, String sender)
        {
            Message result = new Message();

            try
            {
                var  stringReader = new StringReader(message);
                var  serializer   = new XmlSerializer(typeof(Card));
                Card payload      = serializer.Deserialize(stringReader) as Card;
                result.Payload     = payload;
                result.PayloadType = typeof(Card);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            try
            {
                var       stringReader = new StringReader(message);
                var       serializer   = new XmlSerializer(typeof(BlackCard));
                BlackCard payload      = serializer.Deserialize(stringReader) as BlackCard;
                result.Payload     = payload;
                result.PayloadType = typeof(BlackCard);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            try
            {
                var  stringReader = new StringReader(message);
                var  serializer   = new XmlSerializer(typeof(Deck));
                Deck payload      = serializer.Deserialize(stringReader) as Deck;
                result.Payload     = payload;
                result.PayloadType = typeof(Deck);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            try
            {
                var      stringReader = new StringReader(message);
                var      serializer   = new XmlSerializer(typeof(Response));
                Response payload      = serializer.Deserialize(stringReader) as Response;
                result.Payload     = payload;
                result.PayloadType = typeof(Response);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            try
            {
                var    stringReader = new StringReader(message);
                var    serializer   = new XmlSerializer(typeof(Player));
                Player payload      = serializer.Deserialize(stringReader) as Player;
                result.Payload     = payload;
                result.PayloadType = typeof(Player);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            try
            {
                var        stringReader = new StringReader(message);
                var        serializer   = new XmlSerializer(typeof(GameStatus));
                GameStatus payload      = serializer.Deserialize(stringReader) as GameStatus;
                result.Payload     = payload;
                result.PayloadType = typeof(GameStatus);
                result.Sender      = sender;
                return(result);
            }
            catch { }

            return(result);
        }
Esempio n. 15
0
 internal RoundPlay(Player player, IEnumerable <WhiteCard> whiteCards, BlackCard prompt)
 {
     Player      = player;
     _whiteCards = whiteCards.ToArray();
     PromptCard  = prompt;
 }
Esempio n. 16
0
 private void OnGameRoundEnded(int round, BlackCard blackCard, Player roundJudge, Player roundWinner, bool ego, WhiteCard[] winningPlay)
 {
     Console.WriteLine($"Round {round} ended: {roundWinner?.ToString() ?? "Nobody"} wins!");
 }
Esempio n. 17
0
 private void OnBlackCardSkipped(BlackCard skippedCard, BlackCard replacementCard)
 {
     Console.WriteLine($"SKIPPED BLACK CARD: {skippedCard.ID} -> {replacementCard.ID}");
 }
Esempio n. 18
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.PeekFirstState()).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;

                // TODO Unify chatlogs...
                if (Game.PeekFirstState().GetType() == typeof(Lobby))
                {
                    ((Lobby)Game.PeekFirstState()).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;
            }
        }