Ejemplo n.º 1
0
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     TouchPanel.EnabledGestures = GestureType.FreeDrag | GestureType.Tap;
     gameState        = Constants.GAME_STATE.Roll;
     movesLeft        = 0;
     playerDieTexture = null;
     enemyDieTexture  = null;
     base.Initialize();
 }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            if (lastRollDisplayed > 0 && gameTime.TotalGameTime.TotalSeconds - lastRollDisplayed > 2)
            {
                lastRollDisplayed = 0;
                playerDieTexture = null;
                enemyDieTexture = null;
            }
            switch (gameState)
            {
                case Constants.GAME_STATE.Roll:
                    if (tileMap.IsBattleTile(current))
                    {
                        gameState = Constants.GAME_STATE.SecondAction;
                        break;
                    }

                    if (TouchPanel.IsGestureAvailable)
                    {
                        GestureSample gesture = TouchPanel.ReadGesture();

                        if (gesture.GestureType == GestureType.Tap)
                        {
                            lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                            movesLeft = Die.getInstance().roll();
                            playerDieTexture = Texture.diceTextures.ElementAt<Texture2D>(movesLeft - 1);
                            //Calculate moveable squares
                            Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location);
                            tileMap.FindMoveableTiles(message);
                            gameState = Constants.GAME_STATE.Move;
                        }
                    }
                    break;

                case Constants.GAME_STATE.FirstAction:
                    if (TouchPanel.IsGestureAvailable)
                    {
                        GestureSample gesture = TouchPanel.ReadGesture();

                        if (gesture.GestureType == GestureType.Tap)
                        {
                            lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                            gameState = Constants.GAME_STATE.SecondAction;

                        }
                    }
                    break;

                case Constants.GAME_STATE.Move:
                    engagedEnemy = tileMap.FindAdjacentEnemies(current);
                    if (engagedEnemy != null)
                    {
                        gameState = Constants.GAME_STATE.SecondAction;
                        break;
                    }

                    if (movesLeft == 0)
                        gameState = Constants.GAME_STATE.Roll;

                    if (TouchPanel.IsGestureAvailable)
                    {
                        GestureSample gesture = TouchPanel.ReadGesture();

                        if (gesture.GestureType == GestureType.FreeDrag)
                            tileMap._camera.MoveCamera(-gesture.Delta);

                        if (gesture.GestureType == GestureType.Tap)
                        {
                            int x = (int)tileMap._camera._cameraPosition.X + (int)gesture.Position.X - Constants.MARGIN_LEFT;
                            int y = (int)tileMap._camera._cameraPosition.Y + (int)gesture.Position.Y - Constants.MARGIN_TOP;
                            TileObject to = current._tileObject;
                            Tile t = tileMap.GetTile(new Point(x / Constants.TILE_WIDTH, y / (Constants.TILE_HEIGHT - Constants.TILE_OFFSET)));

                            if (tileMap.MoveTileObject(to, new Point(t._location.X, t._location.Y)))
                            {
                                movesLeft -= (Math.Abs(current._location.X - t._location.X) + Math.Abs(current._location.Y - t._location.Y));
                                current = t;
                                Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location);
                                tileMap.FindMoveableTiles(message);

                                if (tileMap.IsBattleTile(current))
                                    break;

                                if (movesLeft == 0)
                                    gameState = Constants.GAME_STATE.Roll;

                            }
                        }
                    }
                    break;

                case Constants.GAME_STATE.SecondAction:
                    if (TouchPanel.IsGestureAvailable)
                    {
                        GestureSample gesture = TouchPanel.ReadGesture();

                        if (gesture.GestureType == GestureType.Tap)
                        {
                            Player player = (Player) current._tileObject;
                            lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                            playerRoll = Die.getInstance().roll();
                            playerDieTexture = Texture.diceTextures.ElementAt<Texture2D>(playerRoll - 1);
                            enemyRoll = Die.getInstance().roll();
                            enemyDieTexture = Texture.diceTextures.ElementAt<Texture2D>(enemyRoll - 1);
                            if (playerRoll > enemyRoll)
                            {
                                engagedEnemy._health -= 1;
                                if (engagedEnemy._health == 0)
                                {
                                    tileMap.RemoveTileObject(engagedEnemy);
                                    Tuple<TileObject, TileObject> bundle = new Tuple<TileObject, TileObject>(player, engagedEnemy);
                                    tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle);
                                }
                                if (movesLeft == 0)
                                    gameState = Constants.GAME_STATE.Roll;
                            }
                            else if (playerRoll == enemyRoll)
                            {
                                engagedEnemy._health -= 1;
                                if (engagedEnemy._health == 0)
                                {
                                    tileMap.RemoveTileObject(engagedEnemy);
                                    Tuple<TileObject, TileObject> bundle = new Tuple<TileObject, TileObject>(player, engagedEnemy);
                                    tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle);
                                }
                                player._health -= 1;
                                //GAME OVER!
                                if (player._health == 0)
                                    tileMap.RemoveTileObject(player);
                                if (movesLeft == 0)
                                    gameState = Constants.GAME_STATE.Roll;
                            }
                            else
                            {
                                player._health -= 1;
                                //GAME OVER!
                                if (player._health == 0)
                                    tileMap.RemoveTileObject(player);
                                if (movesLeft == 0)
                                    gameState = Constants.GAME_STATE.Roll;
                            }

                            Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location);
                            tileMap.FindMoveableTiles(message);
                            gameState = Constants.GAME_STATE.Move;
                        }
                    }
                    break;

                case Constants.GAME_STATE.End:
                    break;
            }
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }
Ejemplo n.º 3
0
        protected override void Update(GameTime gameTime)
        {
            if (lastRollDisplayed > 0 && gameTime.TotalGameTime.TotalSeconds - lastRollDisplayed > 2)
            {
                lastRollDisplayed = 0;
                playerDieTexture  = null;
                enemyDieTexture   = null;
            }
            switch (gameState)
            {
            case Constants.GAME_STATE.Roll:
                if (tileMap.IsBattleTile(current))
                {
                    gameState = Constants.GAME_STATE.SecondAction;
                    break;
                }

                if (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();

                    if (gesture.GestureType == GestureType.Tap)
                    {
                        lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                        movesLeft         = Die.getInstance().roll();
                        playerDieTexture  = Texture.diceTextures.ElementAt <Texture2D>(movesLeft - 1);
                        //Calculate moveable squares
                        Tuple <int, Point> message = new Tuple <int, Point>(movesLeft, current._location);
                        tileMap.FindMoveableTiles(message);
                        gameState = Constants.GAME_STATE.Move;
                    }
                }
                break;

            case Constants.GAME_STATE.FirstAction:
                if (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();

                    if (gesture.GestureType == GestureType.Tap)
                    {
                        lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                        gameState         = Constants.GAME_STATE.SecondAction;
                    }
                }
                break;

            case Constants.GAME_STATE.Move:
                engagedEnemy = tileMap.FindAdjacentEnemies(current);
                if (engagedEnemy != null)
                {
                    gameState = Constants.GAME_STATE.SecondAction;
                    break;
                }

                if (movesLeft == 0)
                {
                    gameState = Constants.GAME_STATE.Roll;
                }

                if (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();

                    if (gesture.GestureType == GestureType.FreeDrag)
                    {
                        tileMap._camera.MoveCamera(-gesture.Delta);
                    }

                    if (gesture.GestureType == GestureType.Tap)
                    {
                        int        x  = (int)tileMap._camera._cameraPosition.X + (int)gesture.Position.X - Constants.MARGIN_LEFT;
                        int        y  = (int)tileMap._camera._cameraPosition.Y + (int)gesture.Position.Y - Constants.MARGIN_TOP;
                        TileObject to = current._tileObject;
                        Tile       t  = tileMap.GetTile(new Point(x / Constants.TILE_WIDTH, y / (Constants.TILE_HEIGHT - Constants.TILE_OFFSET)));

                        if (tileMap.MoveTileObject(to, new Point(t._location.X, t._location.Y)))
                        {
                            movesLeft -= (Math.Abs(current._location.X - t._location.X) + Math.Abs(current._location.Y - t._location.Y));
                            current    = t;
                            Tuple <int, Point> message = new Tuple <int, Point>(movesLeft, current._location);
                            tileMap.FindMoveableTiles(message);

                            if (tileMap.IsBattleTile(current))
                            {
                                break;
                            }

                            if (movesLeft == 0)
                            {
                                gameState = Constants.GAME_STATE.Roll;
                            }
                        }
                    }
                }
                break;

            case Constants.GAME_STATE.SecondAction:
                if (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();

                    if (gesture.GestureType == GestureType.Tap)
                    {
                        Player player = (Player)current._tileObject;
                        lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds;
                        playerRoll        = Die.getInstance().roll();
                        playerDieTexture  = Texture.diceTextures.ElementAt <Texture2D>(playerRoll - 1);
                        enemyRoll         = Die.getInstance().roll();
                        enemyDieTexture   = Texture.diceTextures.ElementAt <Texture2D>(enemyRoll - 1);
                        if (playerRoll > enemyRoll)
                        {
                            engagedEnemy._health -= 1;
                            if (engagedEnemy._health == 0)
                            {
                                tileMap.RemoveTileObject(engagedEnemy);
                                Tuple <TileObject, TileObject> bundle = new Tuple <TileObject, TileObject>(player, engagedEnemy);
                                tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle);
                            }
                            if (movesLeft == 0)
                            {
                                gameState = Constants.GAME_STATE.Roll;
                            }
                        }
                        else if (playerRoll == enemyRoll)
                        {
                            engagedEnemy._health -= 1;
                            if (engagedEnemy._health == 0)
                            {
                                tileMap.RemoveTileObject(engagedEnemy);
                                Tuple <TileObject, TileObject> bundle = new Tuple <TileObject, TileObject>(player, engagedEnemy);
                                tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle);
                            }
                            player._health -= 1;
                            //GAME OVER!
                            if (player._health == 0)
                            {
                                tileMap.RemoveTileObject(player);
                            }
                            if (movesLeft == 0)
                            {
                                gameState = Constants.GAME_STATE.Roll;
                            }
                        }
                        else
                        {
                            player._health -= 1;
                            //GAME OVER!
                            if (player._health == 0)
                            {
                                tileMap.RemoveTileObject(player);
                            }
                            if (movesLeft == 0)
                            {
                                gameState = Constants.GAME_STATE.Roll;
                            }
                        }

                        Tuple <int, Point> message = new Tuple <int, Point>(movesLeft, current._location);
                        tileMap.FindMoveableTiles(message);
                        gameState = Constants.GAME_STATE.Move;
                    }
                }
                break;

            case Constants.GAME_STATE.End:
                break;
            }
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            base.Update(gameTime);
        }
Ejemplo n.º 4
0
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     TouchPanel.EnabledGestures = GestureType.FreeDrag | GestureType.Tap;
     gameState = Constants.GAME_STATE.Roll;
     movesLeft = 0;
     playerDieTexture = null;
     enemyDieTexture = null;
     base.Initialize();
 }