Пример #1
0
 private bool tileBeenAdded(Tile tileToCheck, List<Tile> newTiles)
 {
     foreach (Tile match in _inRangeTiles)
     {
         if (match == tileToCheck)
         {
             return true;
         }
     }
     foreach (Tile match in newTiles)
     {
         if (match == tileToCheck)
         {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 public void AddTilesAndTileObjects(int[,] tileTextureMap, int[,] tileObjectTextureMap)
 {
     for (int x = 0; x < MapWidth; x++)
     {
         for (int y = 0; y < MapHeight; y++)
         {
             int tileTextureIndex = tileTextureMap[y, x];
             if (tileTextureIndex != -1) _tiles[y, x] = new Tile(new Point(x, y), Texture.tileTextures[tileTextureIndex]);
             if (tileTextureIndex == 1) _tiles[y, x]._active = true;
             //For tiles that are stone, mark them as active, this will need better implementation to allow for different active textures
             int tileObjectTextureIndex = tileObjectTextureMap[y, x];
             if (tileObjectTextureIndex != -1)
             {
                 //these two conditionals probably shouldnt be here
                 if (tileObjectTextureIndex == 4)
                 {
                     _tiles[y, x]._tileObject = _players[0];
                     _observers.Add(_players[0]);
                 }
                 //make tile inactive if the tile object is an enemy
                 else if (tileObjectTextureIndex == 5)
                 {
                     Enemy enemy = new Enemy(new Point(x, y), Texture.tileObjectTextures[tileObjectTextureIndex], 100, 100, 100, false);
                     _tiles[y, x]._tileObject = enemy;
                     _tiles[y, x]._active = false;
                     _observers.Add(enemy);
                 }
                 else
                 {
                     TileObject to = new TileObject(new Point(x, y), Texture.tileObjectTextures[tileObjectTextureIndex]);
                     _tiles[y, x]._tileObject = to;
                     _observers.Add(to);
                 }
             }
         }
     }
     for (int x = 0; x < MapWidth; x++)
     {
         for (int y = 0; y < MapHeight; y++)
         {
             if (y - 1 >= 0)
                 _tiles[y, x]._top = _tiles[y - 1, x];
             if (y + 1 < MapHeight)
                 _tiles[y, x]._bottom = _tiles[y + 1, x];
             if (x - 1 >= 0)
                 _tiles[y, x]._left = _tiles[y, x - 1];
             if (x + 1 < MapWidth)
                 _tiles[y, x]._right = _tiles[y, x + 1];
         }
     }
 }
Пример #3
0
        public bool IsBattleTile(Tile tile)
        {
            if (FindAdjacentEnemies(tile) != null)
                return true;

            return false;
        }
Пример #4
0
        public Enemy FindAdjacentEnemies(Tile tile)
        {
            if (tile._left != null && tile._left._tileObject is Enemy)
                return tile._left._tileObject as Enemy;
            if (tile._right != null && tile._right._tileObject is Enemy)
                return tile._right._tileObject as Enemy;
            if (tile._top != null && tile._top._tileObject is Enemy)
                return tile._top._tileObject as Enemy;
            if (tile._bottom != null && tile._bottom._tileObject is Enemy)
                return tile._bottom._tileObject as Enemy;

            return null;
        }
Пример #5
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);
        }
Пример #6
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Texture.AddTileTexture(Content.Load<Texture2D>("Tiles\\Grass Block"));
            Texture.AddTileTexture(Content.Load<Texture2D>("Tiles\\Stone Block"));
            Texture.AddTileTexture(Content.Load<Texture2D>("Tiles\\Dirt Block"));
            Texture.AddTileTexture(Content.Load<Texture2D>("Tiles\\Water Block"));

            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Tree Tall"));
            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Rock"));
            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Open Door"));
            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Closed Door"));
            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Player"));
            Texture.AddTileObjectTexture(Content.Load<Texture2D>("TileObjects\\Enemy"));

            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_one"));
            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_two"));
            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_three"));
            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_four"));
            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_five"));
            Texture.AddDiceTexture(Content.Load<Texture2D>("Dice\\dice_six"));

            tileMap.AddPlayer();
            tileMap.LoadTiles();
            current = tileMap.GetTile(tileMap._startLocation);
        }
Пример #7
0
 public void Initialize()
 {
     _active = false;
     _top = null;
     _bottom = null;
     _left = null;
     _right = null;
 }