Пример #1
0
        // Update:
        public override void Update(GameTime gameTime, KeyboardState ks)
        {
            base.Update(gameTime, ks);

            // DEBUG: SKIP THE GAME
            if (!playGame)
            {
                foreach (Player p in players)
                {
                    resultsList.Add(p);
                }

                S_MinigameResults minigameResults = new S_MinigameResults(parentManager, 0, 0, resultsList, 1);
                parentManager.AddStateQueue(minigameResults);
                this.flagForDeletion = true;
                Console.WriteLine("Finished minigame, going to results");
            }

            // Check if exploding animation is active
            if (isExploding)
            {
                explosionSprite.Update(gameTime, ks);
                if (!explosionSprite.active)
                {
                    isExploding = false;
                    waitTime    = 0;
                }
            }
            // Wait sometime before moving onto next player
            else if (waitTime < maxWaitTime)
            {
                waitTime++;
            }
            else
            {
                // Check if only one player left
                if (players.Count == 1)
                {
                    // Add player to results list
                    resultsList.Add(players[0]);
                    S_MinigameResults minigameResults = new S_MinigameResults(parentManager, 0, 0, resultsList, 1);
                    parentManager.AddStateQueue(minigameResults);
                    this.flagForDeletion = true;
                }

                // Check if all players have gone
                else if (selectedPlungers == plungers.Count - 1)
                {
                    // Reset plungers
                    resetSelections();
                }
                // Whose Turn is it
                else
                {
                    // Computer Logic
                    if (!currentPlayer.isHuman)
                    {
                        // Set COM to move over every plunger once
                        if (!isMoving)
                        {
                            comMove     = plungers.Count - selectedPlungers;
                            isMoving    = true;
                            comLastMove = gameTime.TotalGameTime;
                        }
                        else
                        {
                            // Only move every 500ms
                            if (comLastMove + comMoveSpeed < gameTime.TotalGameTime)
                            {
                                // Move computer selection
                                if (comMove > 0)
                                {
                                    comLastMove = gameTime.TotalGameTime;
                                    // move selection by (skipping over already pressed plungers)
                                    getNextSelection();

                                    // SFX:
                                    parentManager.audioEngine.playSound(MGP_Constants.soundEffects.bombMove, 1.0f);

                                    // If currently selecting the bomb, roll a dice based on difficulty
                                    if (currSelection.isBomb)
                                    {
                                        rollChance(parentManager.gameOptions.difficulty);
                                    }

                                    comMove--;
                                }
                                // Computer has finished moving
                                else
                                {
                                    isMoving = false;

                                    handleSelection();

                                    // Move current selection to next available plunger
                                    getNextSelection();
                                }
                            }
                        }
                    }   // End of Computer Logic

                    else
                    {
                        // Move Menu Selection Left:
                        if (km.ActionPressed(KeyboardManager.action.left, currentPlayer.playerControlsIndex))
                        {
                            getNextSelection();

                            // SFX:
                            parentManager.audioEngine.playSound(MGP_Constants.soundEffects.bombMove, 1.0f);
                        }

                        // Move Menu Selection Right:
                        if (km.ActionPressed(KeyboardManager.action.right, currentPlayer.playerControlsIndex))
                        {
                            getNextSelectionRight();

                            // SFX:
                            parentManager.audioEngine.playSound(MGP_Constants.soundEffects.bombMove, 1.0f);
                        }


                        // Human Player selectes a plunger
                        if (km.ActionPressed(KeyboardManager.action.select, currentPlayer.playerControlsIndex))
                        {
                            handleSelection();

                            // Move current selection to next available plunger
                            getNextSelection();
                        }
                    }
                }
            }
        }
Пример #2
0
        // Update:
        public override void Update(GameTime gameTime, KeyboardState ks)
        {
            base.Update(gameTime, ks);

            float   move = 50;
            Vector2 playerOnePosition = currentMeeplePositions[0];

            // Check for correct key press, and move up
            if (km.ActionPressed(players[0].currMove, KeyboardManager.playerIndex.one))
            {
                currentMeeplePositions[0] = new Vector2(playerOnePosition.X, playerOnePosition.Y - move);
                playerOne.currMove        = directionKeys[random.Next(directionKeys.Length)];
                // DEBUG
                Console.WriteLine("Current move 1 = " + players[0].currMove);
                if (playerOnePosition.Y - move <= 20)
                {
                    raceOver = true;
                }
            }
            if (twoPlayers)
            {
                if (km.ActionPressed(playerTwo.currMove, KeyboardManager.playerIndex.two))
                {
                    Vector2 playerTwoPosition = currentMeeplePositions[1];
                    currentMeeplePositions[1] = new Vector2(playerTwoPosition.X, playerTwoPosition.Y - move);
                    playerTwo.currMove        = directionKeys[random.Next(directionKeys.Length)];
                    Console.WriteLine("Current move 1 = " + players[0].currMove);
                    if (playerTwoPosition.Y - move <= 20)
                    {
                        raceOver = true;
                    }
                }
            }

            // Delay computer move
            if (comLastMove + comMoveSpeed < gameTime.TotalGameTime)
            {
                comLastMove = gameTime.TotalGameTime;

                foreach (int com in comPlayers)
                {
                    if (comChanceToMove())
                    {
                        currentMeeplePositions[com] = new Vector2(currentMeeplePositions[com].X, currentMeeplePositions[com].Y - move);
                        players[com].currMove       = directionKeys[random.Next(directionKeys.Length)];
                        if (currentMeeplePositions[com].Y - move <= 20)
                        {
                            raceOver = true;
                        }
                    }
                }
            }

            // DEBUG: SKIP THE GAME
            if (!playGame)
            {
                foreach (Player p in players)
                {
                    resultsList.Add(p);
                }
                this.flagForDeletion = true;
                Console.WriteLine("Finished minigame, going to results");
                S_MinigameResults minigameResults = new S_MinigameResults(parentManager, 0, 0, resultsList, 2);
                parentManager.AddStateQueue(minigameResults);
            }

            // Check if race is over
            if (raceOver)
            {
                // Old way of sorting
                // players.Sort((x, y) => y.meeple.pos.Y.CompareTo(x.meeple.pos.Y));
                float      max         = float.MinValue;
                List <int> previousMax = new List <int>();
                int        maxIndex    = -1000;
                for (int i = 0; i < currentMeeplePositions.Count; i++)
                {
                    for (int j = 0; j < currentMeeplePositions.Count; j++)
                    {
                        if (currentMeeplePositions[j].Y > max && previousMax.Contains(j) == false)
                        {
                            max      = currentMeeplePositions[j].Y;
                            maxIndex = j;
                        }
                    }
                    // Set old max, reset max
                    previousMax.Add(maxIndex);
                    max = float.MinValue;
                    // Add to results list
                    resultsList.Add(players[maxIndex]);
                }

                S_MinigameResults minigameResults = new S_MinigameResults(parentManager, 0, 0, resultsList, 2);
                parentManager.AddStateQueue(minigameResults);
                this.flagForDeletion = true;
                Console.WriteLine("Finished minigame, going to results");
            }
        }