コード例 #1
0
        public override void Fix()
        {
            for (int i = X - 1; i < X + 1; i++)
            {
                for (int j = Y - 1; j < Y + 1; j++)
                {
                    if ((i != X && j != Y) && Tiles[i, j].GetType() == typeof(DirtTile))
                    {
                        Tiles[i, j] = new DirtTile(Tiles[i, j].Position, Tiles[i, j].Tiles);

                        DirtTile t = Tiles[i, j] as DirtTile;
                        t.Update(true);

                        Tiles[i, j] = t;
                    }
                }
            }
        }
コード例 #2
0
ファイル: World.cs プロジェクト: matttheawesome1/Battle-Reign
        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)));
                    }
                }
            }
        }