Esempio n. 1
0
        public void Draw(IDrawDevice device)
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            //debug for now
            if (DebugMode)
            {
                // Prepare the Canvas for rendering to the target device
                this.canvas.Begin(device);

                for (int widthIndex = 0; widthIndex < this.GameBoard.Width(); widthIndex++)
                {
                    for (int heightIndex = 0; heightIndex < this.GameBoard.Height(); heightIndex++)
                    {
                        GameTile tile = GameBoard.GetTile(widthIndex, heightIndex);

                        //TODO: modify position based on indices
                        Vector3 pos = new Vector3(
                            this.GameObj.Transform.Pos.X + widthIndex * 128,
                            this.GameObj.Transform.Pos.Y + heightIndex * 128,
                            this.GameObj.Transform.Pos.Z
                            );

                        // Draw tile debug
                        if (tile.Player() == null)
                        {
                            canvas.DrawText(new FormattedText("/cffd700FF Coins: " + tile.NumCoins()), pos.X, pos.Y, pos.Z, null, Alignment.TopLeft, true);
                        }
                        else
                        {
                            canvas.DrawText(new FormattedText("/c000000FF Player: " + tile.Player().PlayerNumber()), pos.X, pos.Y, pos.Z, null, Alignment.TopLeft, false);
                            canvas.DrawText(new FormattedText("/cFF0000FF Score: " + tile.Player().TotalCoins()), pos.X, pos.Y + 20, pos.Z, null, Alignment.TopLeft, false);
                        }
                    }
                }

                // Finalize rendering with our Canvas
                this.canvas.End();
            }
        }
Esempio n. 2
0
        public void Init()
        {
            StateMachine.SetGameState(StateMachine.GameState.GeneratingBoard);

            boardArray  = new GameTile[WIDTH, HEIGHT];
            targetTiles = new GameTile[4];

            for (int widthIndex = 0; widthIndex < WIDTH; widthIndex++)
            {
                for (int heightIndex = 0; heightIndex < HEIGHT; heightIndex++)
                {
                    //Don't generate coins on the corners where players start
                    if (widthIndex == 1 && heightIndex == 0) //top center
                    {
                        boardArray[widthIndex, heightIndex] = new GameTile(widthIndex, heightIndex, 0, playerOne);
                        continue;
                    }

                    if (widthIndex == 0 && heightIndex == 1) //left center
                    {
                        boardArray[widthIndex, heightIndex] = new GameTile(widthIndex, heightIndex, 0, playerTwo);
                        continue;
                    }

                    if (widthIndex == WIDTH - 1 && heightIndex == 1) //right center
                    {
                        boardArray[widthIndex, heightIndex] = new GameTile(widthIndex, heightIndex, 0, playerThree);
                        continue;
                    }

                    if (widthIndex == 1 && heightIndex == HEIGHT - 1) //bottom center
                    {
                        boardArray[widthIndex, heightIndex] = new GameTile(widthIndex, heightIndex, 0, playerFour);
                        continue;
                    }

                    boardArray[widthIndex, heightIndex] = new GameTile(widthIndex, heightIndex, RNG.Next(MIN_COINS, MAX_COINS + 1), null);
                }
            }

            StateMachine.SetGameState(StateMachine.GameState.WaitingPlayerInput);
        }
Esempio n. 3
0
        public void OnUpdate()
        {
            if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor)
            {
                return;
            }

            //Input
            if (StateMachine.CurrentState == StateMachine.GameState.WaitingPlayerInput)
            {
                debugTextRenderer.Text = new FormattedText("Press a direction key to choose a tile.");

                if (DualityApp.Keyboard.KeyReleased(Duality.Input.Key.Left))
                {
                    if (this.GameBoard.TryMove(new Vector2(-1, 0), 1))
                    {
                        StateMachine.SetGameState(StateMachine.GameState.ShowResults);
                    }
                    else
                    {
                        gameAudioComponent.PlaySFX(GameAudioComponent.SFX.Bump);
                    }
                }
                else if (DualityApp.Keyboard.KeyReleased(Duality.Input.Key.Right))
                {
                    if (this.GameBoard.TryMove(new Vector2(1, 0), 1))
                    {
                        StateMachine.SetGameState(StateMachine.GameState.ShowResults);
                    }
                    else
                    {
                        gameAudioComponent.PlaySFX(GameAudioComponent.SFX.Bump);
                    }
                }
                else if (DualityApp.Keyboard.KeyReleased(Duality.Input.Key.Down))
                {
                    if (this.GameBoard.TryMove(new Vector2(0, 1), 1))
                    {
                        StateMachine.SetGameState(StateMachine.GameState.ShowResults);
                    }
                    else
                    {
                        gameAudioComponent.PlaySFX(GameAudioComponent.SFX.Bump);
                    }
                }
                else if (DualityApp.Keyboard.KeyReleased(Duality.Input.Key.Up))
                {
                    if (this.GameBoard.TryMove(new Vector2(0, -1), 1))
                    {
                        StateMachine.SetGameState(StateMachine.GameState.ShowResults);
                    }
                    else
                    {
                        gameAudioComponent.PlaySFX(GameAudioComponent.SFX.Bump);
                    }
                }
            }
            else if (StateMachine.CurrentState == StateMachine.GameState.ShowResults)
            {
                //Compare moves
                GameTile playerOneSelectedeTile  = this.GameBoard.GetPlayerMove(1);
                GameTile playerTwoSelectedTile   = this.GameBoard.GetPlayerMove(2);
                GameTile playerThreeSelectedTile = this.GameBoard.GetPlayerMove(3);
                GameTile playerFourSelectedTile  = this.GameBoard.GetPlayerMove(4);

                bool playerOneScores   = true;
                bool playerTwoScores   = true;
                bool playerThreeScores = true;
                bool playerFourScores  = true;

                //Check all players if they picked same tile as other players
                if (playerOneSelectedeTile.Equals(playerTwoSelectedTile))
                {
                    Debug.WriteLine("Player 1 and 2 picked same tile");
                    playerOneScores = false;
                    playerTwoScores = false;
                }

                if (playerOneSelectedeTile.Equals(playerThreeSelectedTile))
                {
                    Debug.WriteLine("Player 1 and 3 picked same tile");
                    playerOneScores   = false;
                    playerThreeScores = false;
                }

                if (playerOneSelectedeTile.Equals(playerFourSelectedTile))
                {
                    Debug.WriteLine("Player 1 and 4 picked same tile");
                    playerOneScores  = false;
                    playerFourScores = false;
                }

                if (playerTwoSelectedTile.Equals(playerThreeSelectedTile))
                {
                    Debug.WriteLine("Player 2 and 3 picked same tile");
                    playerTwoScores   = false;
                    playerThreeScores = false;
                }

                if (playerTwoSelectedTile.Equals(playerFourSelectedTile))
                {
                    Debug.WriteLine("Player 2 and 4 picked same tile");
                    playerTwoScores  = false;
                    playerFourScores = false;
                }

                if (playerThreeSelectedTile.Equals(playerFourSelectedTile))
                {
                    Debug.WriteLine("Player 3 and 4 picked same tile");
                    playerThreeScores = false;
                    playerFourScores  = false;
                }

                //Handle scoring
                if (playerOneScores)
                {
                    this.GameBoard.GetPlayer(1).AddCoins(playerOneSelectedeTile.NumCoins());
                    Debug.WriteLine("player 1 score: " + playerOneSelectedeTile.NumCoins().ToString());

                    gameAudioComponent.PlaySFX(GameAudioComponent.SFX.Coins);
                }
                else
                {
                    gameAudioComponent.PlaySFX(GameAudioComponent.SFX.NoCoins);
                }

                if (playerTwoScores)
                {
                    this.GameBoard.GetPlayer(2).AddCoins(playerTwoSelectedTile.NumCoins());
                    Debug.WriteLine("player 2 score: " + playerTwoSelectedTile.NumCoins().ToString());
                }

                if (playerThreeScores)
                {
                    this.GameBoard.GetPlayer(3).AddCoins(playerThreeSelectedTile.NumCoins());
                    Debug.WriteLine("player 3 score: " + playerThreeSelectedTile.NumCoins().ToString());
                }

                if (playerFourScores)
                {
                    this.GameBoard.GetPlayer(4).AddCoins(playerFourSelectedTile.NumCoins());
                    Debug.WriteLine("player 4 score: " + playerFourSelectedTile.NumCoins().ToString());
                }

                StateMachine.SetGameState(StateMachine.GameState.PlayAgain);
            }
            else if (StateMachine.CurrentState == StateMachine.GameState.PlayAgain)
            {
                this.debugTextRenderer.Text = new FormattedText("Do you want to play again? Press Y to try again.");

                if (DualityApp.Keyboard.KeyReleased(Duality.Input.Key.Y))
                {
                    ResetGame();
                }
            }
        }