Beispiel #1
0
 /// <summary>
 /// Helper method for playing a card represented by a double clicked CardSprite
 /// </summary>
 private void PlayCard()
 {
     Contract.Requires(cardToPlay.Card != null && cardToPlay != null && cards.Contains(cardToPlay) && client.HasCard(cardToPlay.Card));
     Contract.Ensures(!client.HasCard(Contract.OldValue(cardToPlay.Card)));
     Contract.Ensures(!cards.Contains(cardToPlay));
     Contract.Ensures(cardToPlay == null);
     cardRequested = false;
     client.PlayCard(cardToPlay.Card);
     cards.Remove(cardToPlay);
     cardToPlay = null;
 }
Beispiel #2
0
        /// <summary>
        /// Update this tablesprite
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime)
        {
            if(playingGame.Started && playingGame.Round.BoardCards.Pile.Count > 0) {
                var cards = CardPlacements[playingGame.Players.Count];
                cardsOnTable.Clear();
                foreach(var p in playingGame.Round.BoardCards.Pile.Keys) {
                    var curIndex = playingGame.PlayerIndex(p);
                    var tmpIndex = curIndex - ourIndex;
                    var realIndex = (playingGame.Players.Count + tmpIndex) % playingGame.Players.Count;

                    var c = playingGame.Round.BoardCards.Pile[p];
                    var cs = new CardSprite(c, new Rectangle((int)cards[realIndex].X, (int)cards[realIndex].Y, 50, 60));
                    cs.LoadContent(game.Content);
                    cardsOnTable.Add(cs);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update this ingame screen
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime)
        {
            if(finished) {
                leaveGame.Rectangle = new Rectangle(game.Window.ClientBounds.Width / 2 - Button.Width / 2, game.Window.ClientBounds.Height - Button.Height, Button.Width, Button.Height);
                if(leaveGame.Update(gameTime)) {
                    this.ButtonAction(leaveGame);
                }
                return;
            }
            if(!playing) {
                if(hosting) {
                    if(startGame.Update(gameTime)) {
                        this.ButtonAction(startGame);
                    }
                }
                players = client.Game.Players.Count;
                if(leaveGame.Update(gameTime)) {
                    this.ButtonAction(leaveGame);
                }

            } else {
                if(playingGround == null) {
                    playingGround = new TableSprite(game, client.Game, new Rectangle(0,0,1024,615));
                    playingGround.LoadContent(game.Content);
                }
                currentKeyboardState = Keyboard.GetState();
                if(this.CheckEscape()) {
                    this.showMenu = !this.showMenu;
                }
                lastKeyboardState = currentKeyboardState;
                if(showMenu) {
                    foreach(var b in this.menuButtons.Where(b => b.Update(gameTime))) {
                        this.ButtonAction(b);
                    }
                }
                if(currentKeyboardState.IsKeyDown(Keys.Tab)) {
                    this.showScoreboard = true;
                } else if(currentKeyboardState.IsKeyUp(Keys.Tab)) {
                    this.showScoreboard = false;
                }
                if(bet.Update(gameTime)) {
                    this.ButtonAction(bet);
                }
                betBox.Update(gameTime);
                if(cards.Count > 0 && cardRequested) {
                    foreach(var c in this.cards) {
                        c.Update(gameTime);
                        if(c.DoubleClick) {
                            this.cardToPlay = c;
                            break;
                        }
                    }
                    if(cardToPlay != null && client.CardPlayable(cardToPlay.Card, client.Game.Round.BoardCards.FirstCard) && client.HasCard(cardToPlay.Card)) {
                        this.PlayCard();
                    }
                } else if(client.Hand.Count == client.Game.CardsToDeal && cards.Count == 0) {
                    betBox.Limit = client.Hand.Count;
                    betBox.Number = 0;
                    betBox.Text = betBox.Number.ToString();
                    var tempX = cardSize.X;
                    foreach(var c in client.Hand) {
                        var cs = new CardSprite(c, new Rectangle(tempX, cardSize.Y, cardSize.Width, cardSize.Width));
                        cs.LoadContent(game.Content);
                        cards.Add(cs);
                        tempX += cardSize.Width;
                    }
                }
                playingGround.Update(gameTime);
            }
        }