Example #1
0
        private static GTile _readTile(byte[] arr, ref int pos)
        {
            GTile      Tile = null;
            float      x    = ReadFloat(arr, ref pos);
            float      y    = ReadFloat(arr, ref pos);
            int        type = ReadInt32(arr, ref pos);
            Directions dir  = (Directions)ReadInt32(arr, ref pos);

            if (type == TileType.GRASS)
            {
                Tile = new Grass(x, y);
            }
            if (type == TileType.GRAVEL)
            {
                Tile = new Gravel(x, y);
            }
            if (type == TileType.METAL)
            {
                Tile = new Metal(x, y);
            }
            if (type == TileType.SAND)
            {
                Tile = new Sand(x, y);
            }
            if (type == TileType.WATER)
            {
                Tile = new Water(x, y);
            }
            if (type == TileType.D_FLOWER)
            {
                Tile = new Flower(x, y);
            }
            if (type == TileType.D_GRASS_SHORE)
            {
                Tile = new GrassShore(x, y, dir);
            }
            if (type == TileType.D_GRAVEL_SHORE)
            {
                Tile = new GravelShore(x, y, dir);
            }
            if (type == TileType.D_SAND_SHORE)
            {
                Tile = new SandShore(x, y, dir);
            }
            if (type == TileType.D_SAND_TRACE)
            {
                Tile = new SandTrace(x, y, dir);
            }
            if (type == 0)
            {
                Tile = new GTile(x, y, true);
            }

            return(Tile);
        }
Example #2
0
            static void Main(string[] args)
            {
                // Create a myMtb object

                Gravel myGravel = new Gravel("Kross");
                Mtb    myMtb    = new Mtb("Merida", "ONE-TWENTY");

                // Call the Ride() method (From the Bike class) on the myMtb object
                myGravel.Ride();
                myMtb.Ride();
                // Display the value of the brand field (from the Bike class) and the value of the modelName from the Mtb class
                Console.WriteLine(myMtb.brand + " " + myMtb.ModelName);
                Console.WriteLine(myGravel.brand + " " + myGravel.modelName);
                // TODO: Exercise 1
                // Create new object of Wheel and call method from a base class.

                var derived = new Derived2();

                derived.DisplayBaseClassProps();
            }
Example #3
0
        public PlotWorldGenerator()
        {
            RoadPattern = new Pattern();
            var gravel   = new Gravel();
            var stone    = new Stone();
            var andesite = new Stone()
            {
                StoneType = "andesite"
            };
            var dirt  = new Dirt();
            var grass = new Grass();

            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 20,
                Block  = gravel
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 10,
                Block  = dirt
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 10,
                Block  = andesite
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 20,
                Block  = stone
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 40,
                Block  = grass
            });
            RoadPattern.Order();

            PlotPattern = new Pattern();
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 70,
                Block  = new Air()
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 27,
                Block  = new Tallgrass()
                {
                    TallGrassType = "tall"
                }
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1,
                Block  = new YellowFlower()
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1,
                Block  = new RedFlower()
            });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 1 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 2 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 3 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 4 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 5 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 6 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 7 });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1,
                Block  = new RedFlower()
                {
                    FlowerType = "oxeye"
                }
            });
            PlotPattern.Order();
        }
Example #4
0
        internal void _setEntity(int lx, int ly)
        {
            if (!(lx >= 0 && ly >= 0 && lx < _parent.LevelWidth && ly < _parent.LevelHeight) || _parent._isBorder(lx, ly))
            {
                return;
            }
            int     x = lx * GTile.WIDTH;
            int     y = ly * GTile.HEIGHT;
            GEntity r;

            switch (_brushIndex)
            {
            case 0:
                r = new Wall(x, y);
                _parent._setTopEntity(lx, ly, r);
                break;

            case 1:
                r = new Metal(x, y);
                _parent._setTopEntity(lx, ly, r);
                break;

            case 2:
                r = new Sand(x, y);
                _parent._setTopTile(lx, ly, r);
                break;

            case 3:
                r = new Water(x, y);
                _parent._setTopTile(lx, ly, r);
                break;

            case 4:
                r = new Gravel(x, y);
                _parent._setTopTile(lx, ly, r);
                break;

            case 5:
                r = new Grass(x, y);
                _parent._setTopTile(lx, ly, r);
                break;

            case 6:
                if (_parent._isOutsideBorder(lx, ly))
                {
                    break;
                }
                r = new Flag(x, y, Teams.Red);
                _parent._setFlag((Flag)r);
                break;

            case 7:
                if (_parent._isOutsideBorder(lx, ly))
                {
                    break;
                }
                r = new Flag(x, y, Teams.Blu);
                _parent._setFlag((Flag)r);
                break;

            case 8:
                if (_parent._isOutsideBorder(lx, ly))
                {
                    break;
                }
                r = new Spawner(x, y, Teams.Red);
                _parent._setSpawner((Spawner)r);
                break;

            case 9:
                if (_parent._isOutsideBorder(lx, ly))
                {
                    break;
                }
                r = new Spawner(x, y, Teams.Blu);
                _parent._setSpawner((Spawner)r);
                break;
            }
        }
Example #5
0
        public PlotWorldGenerator()
        {
            RoadPattern = new Pattern();
            var gravel   = new Gravel();
            var stone    = new Stone();
            var andesite = new Stone()
            {
                Metadata = 5
            };
            var dirt  = new Dirt();
            var grass = new Grass();

            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 20, Id = gravel.Id, Metadata = gravel.Metadata
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 10, Id = dirt.Id, Metadata = dirt.Metadata
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 10, Id = andesite.Id, Metadata = andesite.Metadata
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 20, Id = stone.Id, Metadata = stone.Metadata
            });
            RoadPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 40, Id = grass.Id, Metadata = grass.Metadata
            });
            RoadPattern.Order();

            PlotPattern = new Pattern();
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 70, Id = 0, Metadata = 0
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 27, Id = 31, Metadata = 1
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1, Id = 37, Metadata = 0
            });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1, Id = 38, Metadata = 0
            });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 1 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 2 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 3 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 4 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 5 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 6 });
            //PlotPattern.BlockList.Add(new Pattern.BlockDataEntry() { Weight = 5, Id = 38, Metadata = 7 });
            PlotPattern.BlockList.Add(new Pattern.BlockDataEntry()
            {
                Weight = 1, Id = 38, Metadata = 8
            });
            PlotPattern.Order();
        }
Example #6
0
        private static object[] _parseLevel(BinaryReader br)
        {
            List <GEntity> ParsedTiles    = new List <GEntity>();
            List <GEntity> ParsedEntities = new List <GEntity>();
            List <GEntity> ParsedSpawners = new List <GEntity>();
            int            TileWidth      = GTile.WIDTH;
            int            TileHeight     = GTile.HEIGHT;

            int Cx = 0;
            int Cy = 0;


            int width  = br.ReadInt32();
            int height = br.ReadInt32();

            MapEntity mp;

            GEntity tTile    = null;
            GEntity tEntity  = null;
            GEntity tSpawner = null;

            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    Cx = x * TileWidth;
                    Cy = y * TileHeight;

                    tTile    = null;
                    tEntity  = null;
                    tSpawner = null;

                    mp = (MapEntity)br.ReadByte();
                    switch (mp)
                    {
                    case MapEntity.WallOnGravel:
                        tTile   = new Gravel(Cx, Cy);
                        tEntity = new Wall(Cx, Cy);
                        break;

                    case MapEntity.WallOnWater:
                        tTile   = new Water(Cx, Cy);
                        tEntity = new Wall(Cx, Cy);
                        break;

                    case MapEntity.WallOnSand:
                        tTile   = new Sand(Cx, Cy);
                        tEntity = new Wall(Cx, Cy);
                        break;

                    case MapEntity.WallOnGrass:
                        tTile   = new Grass(Cx, Cy);
                        tEntity = new Wall(Cx, Cy);
                        break;

                    case MapEntity.Metal:
                        tTile   = new GTile(Cx, Cy, true);
                        tEntity = new Metal(Cx, Cy);
                        break;

                    case MapEntity.Water:
                        tTile = new Water(Cx, Cy);
                        break;

                    case MapEntity.Gravel:
                        tTile = new Gravel(Cx, Cy);
                        break;

                    case MapEntity.Sand:
                        tTile = new Sand(Cx, Cy);
                        break;

                    case MapEntity.Grass:
                        tTile = new Grass(Cx, Cy);
                        break;

                    case MapEntity.RedSpawnerOnGravel:
                        tTile    = new Gravel(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedSpawnerOnWater:
                        tTile    = new Water(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedSpawnerOnSand:
                        tTile    = new Sand(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedSpawnerOnGrass:
                        tTile    = new Grass(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.BluSpawnerOnGravel:
                        tTile    = new Gravel(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluSpawnerOnWater:
                        tTile    = new Water(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluSpawnerOnSand:
                        tTile    = new Sand(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluSpawnerOnGrass:
                        tTile    = new Grass(Cx, Cy);
                        tSpawner = new Spawner(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluFlagOnGravel:
                        tTile   = new Gravel(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluFlagOnWater:
                        tTile   = new Water(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluFlagOnSand:
                        tTile   = new Sand(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.BluFlagOnGrass:
                        tTile   = new Grass(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Blu);
                        break;

                    case MapEntity.RedFlagOnGravel:
                        tTile   = new Gravel(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedFlagOnWater:
                        tTile   = new Water(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedFlagOnSand:
                        tTile   = new Sand(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Red);
                        break;

                    case MapEntity.RedFlagOnGrass:
                        tTile   = new Grass(Cx, Cy);
                        tEntity = new Flag(Cx, Cy, Teams.Red);
                        break;
                    }

                    if (tTile != null)
                    {
                        ParsedTiles.Add(tTile);
                    }
                    if (tEntity != null)
                    {
                        ParsedEntities.Add(tEntity);
                    }
                    if (tSpawner != null)
                    {
                        ParsedSpawners.Add(tSpawner);
                    }
                }
            }

            return(new object[] { width, height, ParsedTiles, ParsedEntities, ParsedSpawners });
        }
Example #7
0
        public static List <GEntity> GetLevelDetails(List <GEntity> Tiles)
        {
            List <GEntity> Details = new List <GEntity>();

            int     xt, yt;
            int     NxLeft, NyLeft, NxRight, NyRight, NxUp, NyUp, NxDown, NyDown;
            GEntity LeftTile, RightTile, UpTile, DownTile;

            foreach (GEntity T in Tiles)
            {
                xt = T.iX / GTile.WIDTH;
                yt = T.iY / GTile.HEIGHT;

                NxLeft  = T.iX - GTile.WIDTH + 2;
                NyLeft  = T.iY;
                NxRight = T.iX + GTile.WIDTH - 2;
                NyRight = T.iY;
                NxUp    = T.iX;
                NyUp    = T.iY - GTile.HEIGHT + 2;
                NxDown  = T.iX;
                NyDown  = T.iY + GTile.HEIGHT - 2;

                LeftTile  = GameLevel.GetTile(xt - 1, yt);
                RightTile = GameLevel.GetTile(xt + 1, yt);
                UpTile    = GameLevel.GetTile(xt, yt - 1);
                DownTile  = GameLevel.GetTile(xt, yt + 1);

                if (T.Type == TileType.SAND)
                {
                    if (Sand.IsTraceAcceptable(LeftTile))
                    {
                        Details.Add(new SandTrace(NxLeft, NyLeft, Directions.Left));
                    }
                    if (Sand.IsTraceAcceptable(RightTile))
                    {
                        Details.Add(new SandTrace(NxRight, NyRight, Directions.Right));
                    }
                    if (Sand.IsTraceAcceptable(UpTile))
                    {
                        Details.Add(new SandTrace(NxUp, NyUp, Directions.Up));
                    }
                    if (Sand.IsTraceAcceptable(DownTile))
                    {
                        Details.Add(new SandTrace(NxDown, NyDown, Directions.Down));
                    }

                    if (Sand.IsShoreAcceptable(LeftTile))
                    {
                        Details.Add(new SandShore(NxLeft, NyLeft, Directions.Left));
                    }
                    if (Sand.IsShoreAcceptable(RightTile))
                    {
                        Details.Add(new SandShore(NxRight, NyRight, Directions.Right));
                    }
                    if (Sand.IsShoreAcceptable(UpTile))
                    {
                        Details.Add(new SandShore(NxUp, NyUp, Directions.Up));
                    }
                    if (Sand.IsShoreAcceptable(DownTile))
                    {
                        Details.Add(new SandShore(NxDown, NyDown, Directions.Down));
                    }
                }

                if (T.Type == TileType.GRAVEL)
                {
                    if (Gravel.IsShoreAcceptable(LeftTile))
                    {
                        Details.Add(new GravelShore(NxLeft, NyLeft, Directions.Left));
                    }
                    if (Gravel.IsShoreAcceptable(RightTile))
                    {
                        Details.Add(new GravelShore(NxRight, NyRight, Directions.Right));
                    }
                    if (Gravel.IsShoreAcceptable(UpTile))
                    {
                        Details.Add(new GravelShore(NxUp, NyUp, Directions.Up));
                    }
                    if (Gravel.IsShoreAcceptable(DownTile))
                    {
                        Details.Add(new GravelShore(NxDown, NyDown, Directions.Down));
                    }
                }

                if (T.Type == TileType.GRASS)
                {
                    if (Grass.IsShoreAcceptable(LeftTile))
                    {
                        Details.Add(new GrassShore(NxLeft, NyLeft, Directions.Left));
                    }
                    if (Grass.IsShoreAcceptable(RightTile))
                    {
                        Details.Add(new GrassShore(NxRight, NyRight + 1, Directions.Right));
                    }
                    if (Grass.IsShoreAcceptable(UpTile))
                    {
                        Details.Add(new GrassShore(NxUp, NyUp, Directions.Up));
                    }
                    if (Grass.IsShoreAcceptable(DownTile))
                    {
                        Details.Add(new GrassShore(NxDown, NyDown, Directions.Down));
                    }

                    if (Program.Rand.Next(128) < 48)
                    {
                        Details.Add(new Flower((int)T.X + Program.Rand.Next(30 - Flower.WIDTH), (int)T.Y + Program.Rand.Next(30 - Flower.HEIGHT)));
                    }
                }
            }

            return(Details);
        }
Example #8
0
        public MapEditor(InputHandler Input, int levelWidth, int levelHeight, int fillTile, Modes mapMode, MapEditorGuiScreen parent)
        {
            _parent = parent;
            _mode   = mapMode;

            LevelWidth  = levelWidth;
            LevelHeight = levelHeight;
            this.Input  = Input;

            Tiles    = new List <GEntity>();
            Entities = new List <GEntity>();
            Spawners = new List <GEntity>();

            GEntity e, t;
            int     tx, ty;

            for (int i = 0; i < LevelHeight; i++)
            {
                ty = i * GTile.HEIGHT;
                for (int j = 0; j < levelWidth; j++)
                {
                    e  = t = null;
                    tx = j * GTile.WIDTH;
                    if (_isBorder(j, i))
                    {
                        Entities.Add(new Metal(tx, ty));
                        Tiles.Add(new GTile(tx, ty, true));
                        continue;
                    }
                    switch (fillTile)
                    {
                    case TileType.WALL:
                        e = new Wall(tx, ty);
                        t = new Gravel(tx, ty);
                        break;

                    case TileType.METAL:
                        e = new Metal(tx, ty);
                        break;

                    case TileType.SAND:
                        t = new Sand(tx, ty);
                        break;

                    case TileType.WATER:
                        t = new Water(tx, ty);
                        break;

                    case TileType.GRAVEL:
                        t = new Gravel(tx, ty);
                        break;

                    case TileType.GRASS:
                        t = new Grass(tx, ty);
                        break;
                    }

                    if (t == null)
                    {
                        t = new GTile(tx, ty, true);
                    }
                    Tiles.Add(t);
                    Entities.Add(e);
                }
            }
            _endConstruct();
        }