Example #1
0
        /// <summary>
        /// Loads content required by the screen, and initializes the displayed menu.
        /// </summary>
        public override void LoadContent()
        {
            safeArea = ScreenManager.SafeArea;
            // Create our menu entries.
            MenuEntry themeGameMenuEntry = new MenuEntry("Deck");
            MenuEntry returnMenuEntry = new MenuEntry("Return");

            // Hook up menu event handlers.
            themeGameMenuEntry.Selected += ThemeGameMenuEntrySelected;
            returnMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(themeGameMenuEntry);
            MenuEntries.Add(returnMenuEntry);

            themes.Add("Red", ScreenManager.Game.Content.Load<Texture2D>(
                @"Images\Cards\CardBack_Red"));
            themes.Add("Blue", ScreenManager.Game.Content.Load<Texture2D>(
                @"Images\Cards\CardBack_Blue"));
            background = ScreenManager.Game.Content.Load<Texture2D>(
                @"Images\UI\table");

            card = new AnimatedGameComponent(ScreenManager.Game,
                themes[MainMenuScreen.Theme])
            {
                CurrentPosition = new Vector2(safeArea.Center().X, safeArea.Center().Y - 50)
            };

            ScreenManager.Game.Components.Add(card);

            base.LoadContent();
        }
        /// <summary>
        /// Animates the placement of an insurance chip on the table.
        /// </summary>
        /// <param name="amount">The amount which should appear on the chip.</param>
        private void AddInsuranceChipAnimation(float amount)
        {
            // Add chip component
            AnimatedGameComponent chipComponent = new AnimatedGameComponent(cardGame, blankChip)
            {
                TextColor = Color.Black,
                Enabled = true,
                Visible = false
            };

            Game.Components.Add(chipComponent);

            // Add transition animation
            chipComponent.AddAnimation(new TransitionGameComponentAnimation(positions[0],
                new Vector2(GraphicsDevice.Viewport.Width / 2, insuranceYPosition))
            {
                PerformBeforeStart = ShowComponent,
                PerformBeforSartArgs = chipComponent,
                PerformWhenDone = ShowChipAmountAndPlayBetSound,
                PerformWhenDoneArgs = new object[] { chipComponent, amount },
                Duration = TimeSpan.FromSeconds(1),
                StartTime = DateTime.Now
            });

            // Add flip animation
            chipComponent.AddAnimation(new FlipGameComponentAnimation()
            {
                Duration = TimeSpan.FromSeconds(1f),
                AnimationCycles = 3,
            });
        }
        /// <summary>
        /// Adds the chip to one of the player betting zones.
        /// </summary>
        /// <param name="playerIndex">Index of the player for whom to add 
        /// a chip.</param>
        /// <param name="chipValue">The value on the chip to add.</param>
        /// <param name="secondHand">True if this chip is added to the chip pile
        /// belonging to the player's second hand.</param>
        public void AddChip(int playerIndex, int chipValue, bool secondHand)
        {
            // Only add the chip if the bet is successfully performed
            if (((BlackjackPlayer)players[playerIndex]).Bet(chipValue))
            {
                currentBet += chipValue;
                // Add chip component
                AnimatedGameComponent chipComponent = new AnimatedGameComponent(cardGame,
                    chipsAssets[chipValue])
                {
                    Visible = false
                };

                Game.Components.Add(chipComponent);

                // Calculate the position for the new chip
                Vector2 position;
                // Get the proper offset according to the platform (pc, phone, xbox)
                Vector2 offset = GetChipOffset(playerIndex, secondHand);

                position = cardGame.GameTable[playerIndex] + offset +
                    new Vector2(-currentChipComponent.Count * 2, currentChipComponent.Count * 1);


                // Find the index of the chip
                int currentChipIndex = 0;
                for (int chipIndex = 0; chipIndex < chipsAssets.Count; chipIndex++)
                {
                    if (assetNames[chipIndex] == chipValue)
                    {
                        currentChipIndex = chipIndex;
                        break;
                    }
                }

                // Add transition animation
                chipComponent.AddAnimation(new TransitionGameComponentAnimation(
                    positions[currentChipIndex], position)
                {
                    Duration = TimeSpan.FromSeconds(1f),
                    PerformBeforeStart = ShowComponent,
                    PerformBeforSartArgs = chipComponent,
                    PerformWhenDone = PlayBetSound
                });

                // Add flip animation
                chipComponent.AddAnimation(new FlipGameComponentAnimation()
                {
                    Duration = TimeSpan.FromSeconds(1f),
                    AnimationCycles = 3,
                });

                currentChipComponent.Add(chipComponent);
            }
        }