示例#1
0
        public override int GetHashCode()
        {
            var id = Tiles.Cast <Tile>()
                     .Aggregate("", (current, tile) => current + (tile.State ? 1 : 0));

            return(id.GetHashCode());
        }
示例#2
0
文件: Map.cs 项目: ekolis/TriQuest
 private void PlaceMonsters()
 {
     for (var i = 0; i < Width * Height / MonsterRarity; i++)
     {
         var tile = Tiles.Cast <Tile>().Where(t => t.Formation == null && t.DangerLevel > 0).Pick();
         tile.Formation = Formation.SpawnMonsters(tile.DangerLevel);
     }
 }
示例#3
0
        public MapTile GetRandomTileSpace()
        {
            Random randgen = new Random();

            var blanks = (from t in Tiles.Cast <MapTile>() where t.GetType() == typeof(MapTileSpace) select t).ToArray();
            var blank  = blanks[randgen.Next(blanks.Length)];

            return(blank);
        }
示例#4
0
文件: Map.cs 项目: ekolis/TriQuest
        private void PlaceHeroes()
        {
            Heroes = new Formation();
            Heroes.CreaturePositions[RelativePosition.Front]     = Creature.Warrior;
            Heroes.CreaturePositions[RelativePosition.RearLeft]  = Creature.Mage;
            Heroes.CreaturePositions[RelativePosition.RearRight] = Creature.Priest;

            var lowDanger = Tiles.Cast <Tile>().Where(t => t.DangerLevel == 1);

            lowDanger.Pick().Formation = Heroes;
            bool foundHeroes           = false;

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    if (Tiles[x, y].Formation == Heroes)
                    {
                        HeroX       = x;
                        HeroY       = y;
                        foundHeroes = true;
                        break;
                    }
                }
                if (foundHeroes)
                {
                    break;
                }
            }

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    if (TestLineOfSight(HeroX, HeroY, x, y))
                    {
                        Tiles[x, y].HasBeenSeen = true;
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Returns an IEnumerable of all tiles that are visible to your bot.
 /// </summary>
 /// <returns>All visible tiles.</returns>
 internal IEnumerable <Tile> GetVisibleTiles()
 {
     return(Tiles.Cast <Tile>());
 }
示例#6
0
 bool AnyTilesNotReachable()
 {
     return(Tiles.Cast <Tile>().Any <Tile>(tile => tile.VisitedByPathfinding == false));
 }
示例#7
0
文件: Map.cs 项目: ekolis/TriQuest
        public void LetMonstersAct()
        {
            // let time pass
            var time = Heroes.Delay;

            foreach (var t in Tiles)
            {
                if (t.Formation != null)
                {
                    t.Formation.ElapseTime(time);
                }
            }

            // let monsters act
            IEnumerable <Formation> actors;

            do
            {
                actors = Tiles.Cast <Tile>().Select(t => t.Formation).Where(f => f != null && f.Delay <= 0 && f != Heroes).OrderBy(f => f.Delay);
                foreach (var f in actors)
                {
                    int fx = -99, fy = -99;

                    // find location
                    for (var x = 0; x < Width; x++)
                    {
                        for (var y = 0; y < Height; y++)
                        {
                            if (Tiles[x, y].Formation == f)
                            {
                                fx = x;
                                fy = y;
                                break;
                            }
                        }
                        if (fx >= 0 && fy >= 0)
                        {
                            break;
                        }
                    }

                    // test LoS to heroes
                    if (TestLineOfSight(fx, fy, HeroX, HeroY))
                    {
                        // pursue heroes
                        var dx = HeroX - fx;
                        var dy = HeroY - fy;
                        if (Math.Abs(dx) > Math.Abs(dy))
                        {
                            if (dx > 0)
                            {
                                MoveOrTurn(f, Direction.East);
                            }
                            else
                            {
                                MoveOrTurn(f, Direction.West);
                            }
                        }
                        else if (Math.Abs(dx) < Math.Abs(dy))
                        {
                            if (dy > 0)
                            {
                                MoveOrTurn(f, Direction.South);
                            }
                            else
                            {
                                MoveOrTurn(f, Direction.North);
                            }
                        }
                        else
                        {
                            if (Dice.Range(0, 1) == 0)
                            {
                                if (dx > 0)
                                {
                                    MoveOrTurn(f, Direction.East);
                                }
                                else if (dx < 0)
                                {
                                    MoveOrTurn(f, Direction.West);
                                }
                            }
                            else
                            {
                                if (dy > 0)
                                {
                                    MoveOrTurn(f, Direction.South);
                                }
                                else if (dy < 0)
                                {
                                    MoveOrTurn(f, Direction.North);
                                }
                            }
                        }
                    }
                    else
                    {
                        f.Pass();
                    }
                }
            } while (actors.Count() > 0);

            // see if heroes are still alive
            bool found = false;

            HeroX = -99;
            HeroY = -99;
            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    if (Tiles[x, y].Formation == Heroes)
                    {
                        HeroX = x;
                        HeroY = y;
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
        }
示例#8
0
        public override void Click()
        {
            base.Click();

            Tiles.Cast <Tile>().ToList().ForEach(x => x.Fix());
        }
示例#9
0
        public void Update(GameTime gt)
        {
            KeyboardState kState = Keyboard.GetState();
            MouseState    mState = Mouse.GetState();

            if (kState.IsKeyDown(Keys.R) && Mouse.CanPress)
            {
                GenerateMap(Save.Teams);
            }

            if (!Typing && kState.GetPressedKeys().Length > 0 && CanPress)
            {
                CanPress = false;
            }
            else if (!Typing && kState.GetPressedKeys().Length == 0)
            {
                CanPress = true;
            }

            if (Mouse.RightMouseDown && !Scrolling)
            {
                Scrolling = true;

                OriginalClick = Mouse.Position;
            }
            else if (Mouse.LeftMouseDown && !Scrolling)
            {
                OriginalClick = Mouse.Position;

                int x = (int)(OriginalClick.X - OriginalClick.X % TileWidth) / TileWidth,
                    y = (int)(OriginalClick.Y - OriginalClick.Y % TileWidth) / TileWidth;

                try {
                    Tiles.Cast <Tile>().ToList().ForEach(z => z.Highlight = false);
                    Tiles[x, y].Highlight = true;
                } catch (Exception) { }
            }

            if (Scrolling)
            {
                Camera.Position = new Vector2(Camera.Position.X + (OriginalClick.X - Mouse.Position.X), Camera.Position.Y + (OriginalClick.Y - Mouse.Position.Y));

                //Camera.Position = new Vector2(Camera.Position.X < 0 - Padding ? 0 - Padding : Camera.Position.X, Camera.Position.Y > Size.Y - Graphics.PreferredBackBufferHeight + Padding ? Size.Y - Graphics.PreferredBackBufferHeight + Padding : Camera.Position.Y);
                //Camera.Position = new Vector2(Camera.Position.X > Size.X - Graphics.PreferredBackBufferWidth + Padding ? Size.X + Padding - Graphics.PreferredBackBufferWidth : Camera.Position.X, Camera.Position.Y < 0 - Padding ? 0 - Padding : Camera.Position.Y);

                Mouse.CanPress = false;
            }

            Scrolling = Mouse.CanPress ? false : Mouse.RightMouseDown;

            //Tiles.OfType<Tile>().ToList().ForEach(x => x.Update(gt));
            Blocks.ForEach(x => x.Update(gt));
            Buildings.ForEach(x => x.Update(gt));
            //Units.ForEach(x => x.Update(gt));

            for (int i = 0; i < Units.Count; i++)
            {
                Units[i].Update(gt);

                if (Units[i].Dead)
                {
                    //Units.RemoveAt(i);

                    //i--;
                }
            }
        }
示例#10
0
        public void GenerateBlocks()
        {
            for (int i = 0; i < Tiles.GetLength(0); i++)
            {
                for (int j = 0; j < Tiles.GetLength(1); j++)
                {
                    if (Tiles[i, j].GetType() == typeof(GrassTile))
                    {
                        if (Tiles[i - 1, j - 1].GetType() != typeof(WaterTile) && Tiles[i, j - 1].GetType() != typeof(WaterTile) && Tiles[i + 1, j - 1].GetType() != typeof(WaterTile) &&
                            Tiles[i - 1, j].GetType() != typeof(WaterTile) && Tiles[i + 1, j].GetType() != typeof(WaterTile) &&
                            Tiles[i - 1, j + 1].GetType() != typeof(WaterTile) && Tiles[i, j + 1].GetType() != typeof(WaterTile) && Tiles[i + 1, j + 1].GetType() != typeof(WaterTile))
                        {
                            int b = Utilities.Next(0, 30);

                            if (b < 2)
                            {
                                int c = Utilities.Next(0, 20);

                                if (c > 3)
                                {
                                    Blocks.Add(new Tree(new Point(i, j)));
                                }
                                else
                                {
                                    Blocks.Add(new Bush(new Point(i, j)));
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < Tiles.GetLength(0); i++)
            {
                for (int j = 0; j < Tiles.GetLength(1); j++)
                {
                    if (Tiles[i, j].GetType() == typeof(GrassTile))
                    {
                        bool cont = true;

                        foreach (Tile t in Tiles.Cast <Tile>().ToList())
                        {
                            if (Utilities.Distance(Tiles[i, j].Coordinates, t.Coordinates) < 3)
                            {
                                if (t.GetType() == typeof(WaterTile))
                                {
                                    cont = false;
                                    break;
                                }
                            }
                            if (Utilities.Distance(Tiles[i, j].Coordinates, t.Coordinates) < 2)
                            {
                                if (IsTileAvailable(t.Coordinates))
                                {
                                    /*if (GetBlock(t.Coordinates).GetType() != typeof(Boulder)) {
                                     *  cont = false;
                                     *  break;
                                     * }*/
                                }
                            }
                        }

                        if (cont && Utilities.Next(0, 10) < 2)
                        {
                            Tiles[i, j] = new DirtTile(new Vector2(i * TileWidth, j * TileWidth), Tiles);

                            Tiles[i - 1, j - 1] = new DirtTile(new Vector2((i - 1) * TileWidth, (j - 1) * TileWidth), Tiles);
                            Tiles[i, j - 1]     = new DirtTile(new Vector2(i * TileWidth, (j - 1) * TileWidth), Tiles);
                            Tiles[i + 1, j - 1] = new DirtTile(new Vector2((i + 1) * TileWidth, (j - 1) * TileWidth), Tiles);
                            Tiles[i - 1, j]     = new DirtTile(new Vector2((i - 1) * TileWidth, j * TileWidth), Tiles);
                            Tiles[i + 1, j]     = new DirtTile(new Vector2((i + 1) * TileWidth, j * TileWidth), Tiles);
                            Tiles[i - 1, j + 1] = new DirtTile(new Vector2((i - 1) * TileWidth, (j + 1) * TileWidth), Tiles);
                            Tiles[i, j + 1]     = new DirtTile(new Vector2(i * TileWidth, (j + 1) * TileWidth), Tiles);
                            Tiles[i + 1, j + 1] = new DirtTile(new Vector2((i + 1) * TileWidth, (j + 1) * TileWidth), Tiles);
                        }
                    }
                }
            }

            for (int i = 0; i < Tiles.GetLength(0); i++)
            {
                for (int j = 0; j < Tiles.GetLength(1); j++)
                {
                    if (Tiles[i, j].GetType() == typeof(DirtTile) && Utilities.Next(0, 20) < 3 && IsTileAvailable(i, j))
                    {
                        Blocks.Add(new Boulder(new Point(i, j)));
                    }
                }
            }
        }