示例#1
0
        /// <summary>
        /// Invoked when the player's card count has changed
        /// </summary>
        /// <param name="player">The player whose card count has cahnged</param>
        /// <param name="newCardCount">The player's new card count</param>
        private void PlayerCardCountChanged(Durak.Common.Player player, int newCardCount)
        {
            if (player.PlayerId != myClient.PlayerId)
            {
                PlayerUITag tag = myPlayerUIs[player];

                tag.CardCountLabel.Text = newCardCount.ToString();
            }
        }
示例#2
0
        /// <summary>
        /// Invoked when the attacking or defending player has changed
        /// </summary>
        /// <param name="sender">The that raised the event (The GameState)</param>
        /// <param name="p">The state parameter that was updated</param>
        private void AttackingPlayersChanged(object sender, StateParameter p)
        {
            foreach (KeyValuePair <Player, PlayerUITag> pair in myPlayerUIs)
            {
                PlayerUITag tag = pair.Value;

                if (tag.Panel != null)
                {
                    tag.Panel.ShowBorder = false;
                }
            }

            Player attackingPlayer = myClient.KnownPlayers[myClient.LocalState.GetValueByte(Names.ATTACKING_PLAYER)];
            Player defendingPlayer = myClient.KnownPlayers[myClient.LocalState.GetValueByte(Names.DEFENDING_PLAYER)];

            BorderPanel myAttackingPlayerContainer = myPlayerUIs[attackingPlayer].Panel;
            BorderPanel myDefendingPlayerContainer = myPlayerUIs[defendingPlayer].Panel;

            myAttackingPlayerContainer.ShowBorder  = true;
            myAttackingPlayerContainer.BorderColor = Color.Red;

            myDefendingPlayerContainer.ShowBorder  = true;
            myDefendingPlayerContainer.BorderColor = Color.Blue;
        }
示例#3
0
        /// <summary>
        /// Sets the Game client for this game
        /// </summary>
        /// <param name="client">The client to represent</param>
        public void SetClient(GameClient client)
        {
            myClient = client;

            myClient.LocalState.AddStateChangedEvent("attacking_card", 0, (X, Y) => { cbxPlayerAttack1.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("attacking_card", 1, (X, Y) => { cbxPlayerAttack2.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("attacking_card", 2, (X, Y) => { cbxPlayerAttack3.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("attacking_card", 3, (X, Y) => { cbxPlayerAttack4.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("attacking_card", 4, (X, Y) => { cbxPlayerAttack5.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("attacking_card", 5, (X, Y) => { cbxPlayerAttack6.Card = Y.GetValuePlayingCard(); });

            myClient.LocalState.AddStateChangedEvent("defending_card", 0, (X, Y) => { cbxDefence1.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("defending_card", 1, (X, Y) => { cbxDefence2.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("defending_card", 2, (X, Y) => { cbxDefence3.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("defending_card", 3, (X, Y) => { cbxDefence4.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("defending_card", 4, (X, Y) => { cbxDefence5.Card = Y.GetValuePlayingCard(); });
            myClient.LocalState.AddStateChangedEvent("defending_card", 5, (X, Y) => { cbxDefence6.Card = Y.GetValuePlayingCard(); });

            myClient.OnInvalidMove += (X, Y, Z) => { MessageBox.Show(Z, "Cannot play card"); };

            myClient.LocalState.AddStateChangedEvent(Names.TRUMP_CARD, (X, Y) => { cbxTrump.Card = Y.GetValuePlayingCard(); });


            myClient.LocalState.AddStateChangedEvent(Names.TRUMP_CARD_USED, TrumpPickedUp);


            myClient.LocalState.AddStateChangedEvent(Names.DISCARD, (X, Y) => { dscDiscard.Clear(); foreach (PlayingCard card in Y.GetValueCardCollection())
                                                                                {
                                                                                    dscDiscard.AddCard(card);
                                                                                }
                                                     });

            myClient.LocalState.AddStateChangedEvent(Names.DECK_COUNT, (X, Y) => { lblCardsLeft.Text = "" + Y.GetValueInt(); if (Y.GetValueInt() == 0)
                                                                                   {
                                                                                       cbxDeck.Card = null;
                                                                                   }
                                                     });

            myClient.LocalState.AddStateChangedEvent(Names.GAME_OVER, GameOver);

            myClient.OnServerStateUpdated += (X, Y) => { if (Y == ServerState.InLobby)
                                                         {
                                                             isHardClose = false; this.Close();
                                                         }
            };

            myClient.LocalState.AddStateChangedEvent(Names.REQUEST_HELP, (X, Y) =>
            {
                btnReqHelp.BackColor    = Y.GetValueBool() ? Color.Yellow : Color.DarkGreen;
                lblAttackerReqHelp.Text = Y.GetValueBool() ? "Attacker Requesting Help" : "";
            });

            myClient.OnPlayerChat += ReceivedChat;
            myClient.OnPlayerLeft += PlayerLeft;

            myClient.LocalState.AddStateChangedEvent(Names.ATTACKING_PLAYER, AttackingPlayersChanged);
            myClient.LocalState.AddStateChangedEvent(Names.DEFENDING_PLAYER, AttackingPlayersChanged);

            //DebugClientView view = new DebugClientView();
            //view.SetGameState(myClient.LocalState);
            //view.Show();

            myClient.OnDisconnected += ClientDisconnected;

            myClient.OnConnected += ClientConnected;

            if (!myClient.IsHost)
            {
                grpKickPlayers.Visible = false;
            }

            int localIndex = 0;

            for (byte index = 0; index < myClient.KnownPlayers.Count; index++)
            {
                Player player = myClient.KnownPlayers[index];
                if (player != null && player.PlayerId != myClient.PlayerId)
                {
                    PlayerUITag tag = new PlayerUITag();

                    switch (localIndex)
                    {
                    case 0:
                        tag.Panel          = pnlPlayer1;
                        tag.NameLabel      = lblPlayer1;
                        tag.CardCountLabel = lblPlayer1CardsLeft;
                        tag.CardBox        = cbxPlayer1;
                        break;

                    case 1:
                        tag.Panel          = pnlPlayer2;
                        tag.NameLabel      = lblPlayer2;
                        tag.CardCountLabel = lblPlayer2CardsLeft;
                        tag.CardBox        = cbxPlayer2;
                        break;

                    case 2:
                        tag.Panel          = pnlPlayer3;
                        tag.NameLabel      = lblPlayer3;
                        tag.CardCountLabel = lblPlayer3CardsLeft;
                        tag.CardBox        = cbxPlayer3;
                        break;

                    case 3:
                        tag.Panel          = pnlPlayer4;
                        tag.NameLabel      = lblPlayer4;
                        tag.CardCountLabel = lblPlayer4CardsLeft;
                        tag.CardBox        = cbxPlayer4;
                        break;

                    case 4:
                        tag.Panel          = pnlPlayer5;
                        tag.NameLabel      = lblPlayer5;
                        tag.CardCountLabel = lblPlayer5CardsLeft;
                        tag.CardBox        = cbxPlayer5;
                        break;
                    }

                    myPlayerUIs.Add(player, tag);

                    tag.Panel.Visible = true;

                    localIndex++;
                }
            }

            myPlayerUIs.Add(myClient.KnownPlayers[myClient.PlayerId], new PlayerUITag()
            {
                Panel = pnlMyView
            });

            foreach (KeyValuePair <Player, PlayerUITag> pair in myPlayerUIs)
            {
                PlayerUITag tag = pair.Value;

                if (tag.NameLabel != null)
                {
                    tag.NameLabel.Text = pair.Key.Name;
                }

                if (tag.CardCountLabel != null)
                {
                    tag.CardCountLabel.Text = pair.Key.NumCards.ToString();
                }
            }

            myClient.OnPlayerCardCountChanged += PlayerCardCountChanged;

            cplPlayersHand.Cards = myClient.Hand;

            DetermineKickButtons();
        }
示例#4
0
        public void SetClient(CoreDurakGame coreGame)
        {
            core = coreGame;
            AddEvents();

            foreach (var player in core.ConnectedServer.Players.Values)
            {
                if (player != null && player.ID != core.Player.ID)
                {
                    var id  = player.ID == 0 ? core.Player.ID : player.ID;
                    var tag = new PlayerUITag();

                    switch (id)
                    {
                    case 1:
                        tag.Panel          = pnlPlayer1;
                        tag.Name           = lblPlayer1;
                        tag.Name.Text      = player.Name;
                        tag.PlayerID       = lblIDPlayer1;
                        tag.PlayerID.Text  = player.ID.ToString();
                        tag.CardCount      = lblCardsLeftPlayer1;
                        tag.CardCount.Text = player.Hand.Count.ToString();
                        tag.Card           = pbxPlayer1;
                        tag.Kick           = btnKickPlayer1;
                        tag.BotGame        = pbxBotGamePlayer1;
                        tag.Digress        = pbxDigressedPlayer1;
                        tag.Leave          = pbxLeavedPlayer1;
                        tag.Win            = lblWinPlayer1;
                        tag.MutedPlayer    = pbxMutedPlayer1;
                        tag.RadioButton    = rbnPlayer1;
                        break;

                        #region DRY case 2-5
                    case 2:
                        tag.Panel          = pnlPlayer2;
                        tag.Name           = lblPlayer2;
                        tag.Name.Text      = player.Name;
                        tag.PlayerID       = lblIDPlayer2;
                        tag.PlayerID.Text  = player.ID.ToString();
                        tag.CardCount      = lblCardsLeftPlayer2;
                        tag.CardCount.Text = player.Hand.Count.ToString();
                        tag.Card           = pbxPlayer2;
                        tag.Kick           = btnKickPlayer2;
                        tag.BotGame        = pbxBotGamePlayer2;
                        tag.Digress        = pbxDigressedPlayer2;
                        tag.Leave          = pbxLeavedPlayer2;
                        tag.Win            = lblWinPlayer2;
                        tag.MutedPlayer    = pbxMutedPlayer2;
                        tag.RadioButton    = rbnPlayer2;
                        break;

                    case 3:
                        tag.Panel          = pnlPlayer3;
                        tag.Name           = lblPlayer3;
                        tag.Name.Text      = player.Name;
                        tag.PlayerID       = lblIDPlayer3;
                        tag.PlayerID.Text  = player.ID.ToString();
                        tag.CardCount      = lblCardsLeftPlayer3;
                        tag.CardCount.Text = player.Hand.Count.ToString();
                        tag.Card           = pbxPlayer3;
                        tag.Kick           = btnKickPlayer3;
                        tag.BotGame        = pbxBotGamePlayer3;
                        tag.Digress        = pbxDigressedPlayer3;
                        tag.Leave          = pbxLeavedPlayer3;
                        tag.Win            = lblWinPlayer3;
                        tag.MutedPlayer    = pbxMutedPlayer3;
                        tag.RadioButton    = rbnPlayer3;
                        break;

                    case 4:
                        tag.Panel          = pnlPlayer4;
                        tag.Name           = lblPlayer4;
                        tag.Name.Text      = player.Name;
                        tag.PlayerID       = lblIDPlayer4;
                        tag.PlayerID.Text  = player.ID.ToString();
                        tag.CardCount      = lblCardsLeftPlayer4;
                        tag.CardCount.Text = player.Hand.Count.ToString();
                        tag.Card           = pbxPlayer4;
                        tag.Kick           = btnKickPlayer4;
                        tag.BotGame        = pbxBotGamePlayer4;
                        tag.Digress        = pbxDigressedPlayer4;
                        tag.Leave          = pbxLeavedPlayer4;
                        tag.Win            = lblWinPlayer4;
                        tag.MutedPlayer    = pbxMutedPlayer4;
                        tag.RadioButton    = rbnPlayer4;
                        break;

                    case 5:
                        tag.Panel          = pnlPlayer5;
                        tag.Name           = lblPlayer5;
                        tag.Name.Text      = player.Name;
                        tag.PlayerID       = lblIDPlayer5;
                        tag.PlayerID.Text  = player.ID.ToString();
                        tag.CardCount      = lblCardsLeftPlayer5;
                        tag.CardCount.Text = player.Hand.Count.ToString();
                        tag.Card           = pbxPlayer5;
                        tag.Kick           = btnKickPlayer5;
                        tag.BotGame        = pbxBotGamePlayer5;
                        tag.Digress        = pbxDigressedPlayer5;
                        tag.Leave          = pbxLeavedPlayer5;
                        tag.Win            = lblWinPlayer5;
                        tag.MutedPlayer    = pbxMutedPlayer5;
                        tag.RadioButton    = rbnPlayer5;
                        break;
                        #endregion
                    }

                    playerUIs.Add(player, tag);
                    tag.Panel.Visible = true;
                }
            }

            var myTag = new PlayerUITag()
            {
                PlayerID          = lblIDPlayer,
                Panel             = pnlMyView,
                SwordShieldDagger = pbxSwordShieldDagger,
                BotGame           = pbxBotGame,
                Digress           = pbxDigressed,
                Win = lblWinPlayer
            };
            myTag.PlayerID.Text = core.Player.ID.ToString();
            playerUIs.Add(core.Player, myTag);

            cplPlayersHand.Player = core.Player;
            cplPlayersHand.UpdatePlayer();
            DetermineKickButtons();
            core.ConnectedServer.Players
            .Where(p => p.Value.IsBot && p.Value.IsDigress)
            .ToList()
            ?.ForEach(p => PlayerDigressed(p.Key, p.Value.IsBot, p.Value.IsDigress));
        }