public void Swap(IList<ITile> tiles, ITile first, ITile second)
 {
     int firstIndex = tiles.IndexOf(first);
     int secondIndex = tiles.IndexOf(second);
     if (firstIndex == -1 || secondIndex == -1)
         return;
     tiles[firstIndex] = second;
     tiles[secondIndex] = first;
 }
Exemple #2
0
        /// <summary>
        /// A Gaul can move twice if it crosses a Plain
        /// Cannot cross Water
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        public override bool CheckMove(ITile destination)
        {
            if (!destination.IsAdjacent(this.Position) || destination.Type == TileType.Water)
                return false;

            return base.CheckMove(destination); ;
        }
Exemple #3
0
 public override void Move(ITile destination)
 {
     if (!this.CheckMove(destination))
         return;
     this.Mvt--;
     base.Move(destination);
 }
 public TemplateOveridingDefinitionTile(string name, ITemplate template, ITile extends,
                                    IEnumerable<TileAttribute> attributes)
     : base(name, template, attributes)
 {
     _extends = extends;
     Attributes.MergeTileLazy(_extends);
 }
Exemple #5
0
 public EntityManager(ITile parent, List<IEntity> entityList)
 {
     this.entityList = entityList ?? new List<IEntity>();
     this.newEntityList = new List<IEntity>();
     this.oldEntityList = new List<IEntity>();
     this.drawEntityList = new List<IDrawableEntity>();
 }
 public SpriteEntity(ITile location, Texture2D texture, Color color,
     bool isBlocked, float layerDepth)
     : base(location)
 {
     this.Rotation = Vector2.Zero.ToRotation();
     this.DrawEnding += _OnDrawEnding;
 }
Exemple #7
0
        public TowerEntity(ITile location, Texture2D texture, Color color,
            bool isBlocked, float layerDepth, IEntity owner)
            : base(location)
        {
            this.destinationRectangle = new Rectangle
            {
                X = location.Rectangle.X,
                Y = location.Rectangle.Y,
                Height = location.Rectangle.Height,
                Width = location.Rectangle.Width
            };
            this.enabled = true;
            this.isBlocked = true;
            this.texture = texture;
            this.color = color;
            this.layerDepth = layerDepth;

            this.owner = owner;

            this.timer = 5.0f;

            this.IsEnemy = false;
            this.Intensity = 70.0f;
            this.HP = 150;
            this.Damage = 100;
            this.attackRate = 50;
        }
        public static bool IsTileTheSame(ITile tile1, ITile tile2)
        {
            if (tile1.Active != tile2.Active)
                return false;

            if (tile1.Active)
            {
                if (tile1.Type != tile2.Type)
                    return false;

                if (Main.tileFrameImportant[(int)tile1.Type])
                {
                    if ((tile1.FrameX != tile2.FrameX) || (tile1.FrameY != tile2.FrameY))
                        return false;
                }
            }
            return
                tile1.Wall == tile2.Wall
                &&
                tile1.Liquid == tile2.Liquid
                &&
                tile1.Lava == tile2.Lava
                &&
                tile1.Wire == tile2.Wire;
        }
 public static void Load()
 {
     prevVisitedTiles = new List<KeyValuePair<int, int>>();
     tileList = TileLoader.Load("Tiles");
     player = new PlayerCharacter();
     tile = tileList[new KeyValuePair<int,int>(1,1)];
 }
        public HardZombieEntity(ITile location, Texture2D texture, Color color,
            bool isBlocked, float layerDepth)
        {
            this.destinationRectangle = new Rectangle
            {
                X = location.Rectangle.X,
                Y = location.Rectangle.Y,
                Height = location.Rectangle.Height,
                Width = location.Rectangle.Width
            };
            this.enabled = true;

            this.isBlocked = isBlocked;
            this.texture = texture;
            this.color = color;
            this.layerDepth = layerDepth;

            this.MoveRate = 100;
            this.Tile = location;

            this.IsEnemy = true;
            this.Intensity = 0.1f;
            this.HP = 10000;
            this.Damage = 200;
            this.attackRate = 200;
            this.moveTask = new MoveTask(this, location);
            this.rand = new Random((int)this.Position.X + DateTime.Now.Second);

            //this.Memory = new Memory_Tile[Tile_Engine.Map.Width, Tile_Engine.Map.Height];

            //this.Map.Add(this.Tile.Clone());

            Tile_Engine.Map.Enemies.Add(this);
        }
Exemple #11
0
 public void TransferToTile(ITile next)
 {
     this.currentTile.RemoveEntity(this.entity);
     this.previousTile = this.currentTile;
     this.currentTile = next;
     this.currentTile.AddEntity(this.entity);
 }
Exemple #12
0
        public LavaEntity(ITile tile, Texture2D texture, Color color,
            bool isBlocked, float layerDepth, int damage, IEntity parent,
            IDefendable defender, Vector2 target)
            : base(tile)
        {
            this.destinationRectangle = new Rectangle
            {
                X = tile.Rectangle.Center.X,
                Y = tile.Rectangle.Center.Y,
                Height = texture.Height,
                Width = texture.Width
            };
            this.enabled = true;

            this.isBlocked = isBlocked;
            this.texture = texture;
            this.color = Color.White;
            this.layerDepth = layerDepth;
            this.MoveRate = 5000;
            this.tile = tile;
            this.parent = parent;
            this.Damage = damage;
            this.target = target;
            this.defender = defender;
            this.Position = new Vector2(parent.Rectangle.Center.X, parent.Rectangle.Center.Y);
            this.IsFlying = true;

            this.isTileMovement = false;
        }
Exemple #13
0
 /// <summary>
 /// Checks if the unit can move during this round to a certain destination.
 /// The destination must be next to the current position,
 /// the unit must have some movement points left,
 /// the tile can't be a sea.
 /// </summary>
 /// <param name="currentPosition">The current position.</param>
 /// <param name="currentTile">The current type of tile.</param>
 /// <param name="destination">The destination to reach.</param>
 /// <param name="tile">The type of tile the destination is.</param>
 /// <returns>True if the unit can move to the destination.</returns>
 public override bool CanMove(IPoint currentPosition, ITile currentTile, IPoint destination, ITile tile, bool occupied)
 {
     return !(tile is ISea)
         && destination.IsNext(currentPosition)
         && (remainingMovementPoints >= MOVEMENT_COST
             // Special case for movement to lowland.
             || ((tile is ILowland) && remainingMovementPoints >= MOVEMENT_COST / 2));
 }
Exemple #14
0
 public void AddTile(ITile tile)
 {
     if (cache.ContainsKey(tile.Name))
     {
         throw TileException.DoubleDefinition(tile.Name);
     }
     cache.Add(tile.Name, tile);
 }
Exemple #15
0
        public TileManager(IEntity entity, ITile current)
        {
            this.entity = entity;
            this.currentTile = current;
            this.previousTile = null;

            this.currentTile.AddEntity(this.entity);
        }
        /// <summary>
        /// The method overrides default Equals method.
        /// </summary>
        /// <param name="other">Object to compare with.</param>
        /// <returns>Returns true or false.</returns>
        public bool Equals(ITile other)
        {
            if (other == null)
            {
                return false;
            }

            return this.Id == other.Id;
        }
Exemple #17
0
        public Robber(ITile initialTile)
        {
            if (initialTile == null)
                throw new ArgumentNullException(nameof(initialTile));
            if (initialTile.Rawmaterial != MaterialType.Unsourced)
                throw new ArgumentException("Robber should always start on the desert!");

            CurrentTile = initialTile;
        }
 public PathingNode(ITile tile)
 {
     this.tile = tile;
     this.next = null;
     this.cost = 0f;
     this.order = 0f;
     this.isOpen = false;
     this.isClosed = false;
 }
Exemple #19
0
 public void TestGetPoints()
 {
     ITile[] neighbours = new ITile[] {new Lowland(), new Lowland(), new Lowland(), new Lowland()};
     Assert.AreEqual(1, gaulois.GetPoints(new Forest(), neighbours));
     Assert.AreEqual(0, gaulois.GetPoints(new Sea(), neighbours));
     Assert.AreEqual(2, gaulois.GetPoints(new Lowland(), neighbours));
     Assert.AreEqual(1, gaulois.GetPoints(new Desert(), neighbours));
     Assert.AreEqual(0, gaulois.GetPoints(new Mountain(), neighbours));
 }
        public void Create_ReturnsAUnitWithALocationAndAnOwner(ITile location, Player owner, ICityFactory<City> factory)
        {
            // :::: ACT ::::
            var city = factory.Create(location, owner);

            // :::: ASSERT ::::
            city.Location.Should().Be(location);
            city.Owner.Should().Be(owner);
        }
Exemple #21
0
        public TileMemory(ITile source)
        {
            this.id = source.ID;
            this.rectangle = source.Rectangle.Clone();
            this.adjacentTiles = new ITile[8];
            this.enabled = false;

            this.entityManager = new EntityManager(this);
        }
Exemple #22
0
        public EntityManager(ITile parent, IDictionary<Guid, IEntity> entityList)
        {
            this.parentTile = parent;

            this.entityList = entityList ?? new Dictionary<Guid, IEntity>();
            this.newEntityQueue = new Queue<IEntity>();
            this.oldEntityQueue = new Queue<IEntity>();
            this.drawEntityList = new List<IDrawableEntity>();
            this.transferTemp = new Guid[8];
        }
Exemple #23
0
        /// <summary>
        ///     Computes the distance from this tile to another tile.
        /// </summary>
        /// <param name="destination">The destination tile to which the distance is computed.</param>
        public int DistanceTo(ITile destination)
        {
            var squareTileDestination = destination as SquareTile;
            if (squareTileDestination == null) throw new NotSupportedException();

            var destinationRow = squareTileDestination.Row;
            var destinationColumn = squareTileDestination.Column;

            return Math.Max(Math.Abs(Row - destinationRow), Math.Abs(Column - destinationColumn));
        }
Exemple #24
0
 /// <summary>
 /// Computes the points won by the unit.
 /// </summary>
 /// <remarks>
 /// Dwarfs win twice the points when they are on a forest;
 /// they don't win any if they are on a sea or on a lowland tile.
 /// </remarks>
 /// <param name="tile">The type of tile the unit is currently on.</param>
 /// <param name="neighbours">The neighbour tiles (array of 4 tiles or null if out bounds).</param>
 /// <returns>The number of points won by the unit depending on the tile she's on.</returns>
 public override int GetPoints(ITile tile, ITile[] neighbours)
 {
     if(tile is IForest) {
         return 2;
     } else if(tile is ISea || tile is ILowland) {
         return 0;
     } else {
         return 1;
     }
 }
 /// <summary>
 /// Reshuffles all the tiles in a random order
 /// </summary>
 public void ResetCommand()
 {
     if (_selectedTile != null)
     {
         _selectedTile.IsChecked = false;
         _selectedTile = null;
     }
     _tileService.Reset(Tiles);
     CheckIfTilesAreOrdered();
 }
 public void TestInitialize()
 {
     this.Tile = new Tile
     {
         Id = "ce402b30-3611-4b26-a6a2-750a46a9f3e0",
         EmbedUrl = "https://msit.powerbi.com/embed?dashboardId=86ffe081-a67a-4337-b141-62344e514af5&tileId=cbc13590-7b9b-4f00-b2af-d562534ac674"
     };
     this.viewModel = new TileViewModel { Tile = this.Tile };
     this.htmlHelper = TestHelper.CreateHtmlHelper(new ViewDataDictionary<TileViewModel>(this.viewModel));
 }
Exemple #27
0
 public BasicTileMap(int width = 27, int height = 15)
 {
     Metadata = new MapMetadata
     {
         MapName = "Test Map",
         Width = width,
         Height = height
     };
     TileMap = new ITile[height, width];
 }
Exemple #28
0
 public MinecraftMap()
 {
     Metadata = new MapMetadata
     {
         MapName = "World 1",
         Width = 256,
         Height = 256, //256 x 256 cube
     };
     TileMap = new ITile[Metadata.Height, Metadata.Width];
 }
Exemple #29
0
        public MoveTask(IEntity entity, ITile destination)
        {
            this.isActive = true;
            this.Destination = destination;
            this.Entity = entity;
            this.Path = new List<PathingNode>();

            this.isEnabled = false;
            this.insanityCheck = 0;
        }
Exemple #30
0
        public void Move_UpdatesTheLocationOfTheUnitAccordingly(IUnit<Archer> unit, ITile destination)
        {
            // :::: ARRANGE ::::
            var movableUnit = new Movability<Archer>(unit);

            // :::: ACT ::::
            movableUnit.MoveTo(destination);

            // :::: ASSERT ::::
            unit.Location.Should().Be(destination);
        }
Exemple #31
0
            public override void OnMouseDown(MouseButtonDownEventArgs e)
            {
                if (e.Button != (int)MouseButton.Left || Ui.UIHovering)
                {
                    return;
                }

                ITile tile = Input.GetTileUnderCursor();

                if (tile == null)
                {
                    return;
                }

                IntRect rect = GetBuildingRectangle(tile, BuildingType);

                if (BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level))
                {
                    IBuilding building = Level.BuildBuilding(BuildingType, rect.TopLeft(), Quaternion.Identity, Input.Player);
                    Tree      tree     = (Tree)building.BuildingPlugin;
                    tree.SetSize((sizeSlider.Value / sizeSlider.Range) + startSize);
                }
            }
        internal void Initialize(string Name, int X, int Y, int Width, int Height, ITile[,] CopyFrom, int Layer = 0)
        {
            this.Index  = Index;
            this.Name   = Name;
            this.Data   = new StructTile[Width, Height];
            this.X      = X;
            this.Y      = Y;
            this.Width  = Width;
            this.Height = Height;
            this.Layer  = Layer;

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    ITile t = CopyFrom[i, j];
                    if (t != null)
                    {
                        this[i, j].CopyFrom(t);
                    }
                }
            }
        }
Exemple #33
0
        private void PlaceFood()
        {
            while (!IsFoodPlaced)
            {
                int yPos;
                int xPos;
                lock (RandomNumberLock)
                {
                    yPos = RandomNumberGenerator.GetNextNumber(0, Map.Height - 1);
                    xPos = RandomNumberGenerator.GetNextNumber(0, Map.Width - 1);
                }

                ITile tile = Map.GetTile(xPos, yPos);
                if (tile.Value == TileValues.Empty)
                {
                    tile.SetValue(TileValues.Food);
                    IsFoodPlaced = true;

                    FoodXPos = xPos;
                    FoodYPos = yPos;
                }
            }
        }
Exemple #34
0
            public static CutterWrapper CreateNewCutter(ILevelManager level, AggressivePlayer player)
            {
                foreach (var position in PossiblePositions)
                {
                    ITile tile = GetTileRelativeToKeepCenter(position, player);
                    if (player.takenPositions.Contains(position) ||
                        !player.type.TreeCutter.CanBuild(tile.MapLocation, player.Player, level))
                    {
                        continue;
                    }

                    IBuilding newBuilding = level.BuildBuilding(player.type.TreeCutter.MyTypeInstance,
                                                                tile.MapLocation,
                                                                Quaternion.Identity,
                                                                player.Player);
                    if (newBuilding != null)
                    {
                        player.takenPositions.Add(position);
                        return(new CutterWrapper(newBuilding, player, position));
                    }
                }
                return(null);
            }
        public int calculate(ITile currentTile, bool gameover)
        {
            int          points           = 0;
            List <ITile> surroundingTiles = TileUtils.GetAllSurroundingTiles(currentTile);

            var churchTile = (Church)currentTile;

            if (gameover)
            {
                points = surroundingTiles.Count;
            }
            else
            {
                if (surroundingTiles.Count == 8 && surroundingTiles.All(e => e != null))
                {
                    if (churchTile.CenterFigure != null)
                    {
                        points = 9;
                    }
                }
            }
            return(points);
        }
Exemple #36
0
        public static bool HasWire(this ITile tile, WireColor color = WireColor.None)
        {
            if (color == WireColor.None)
            {
                return(tile.wire() || tile.wire2() || tile.wire3() /* || tile.wire4()*/);
            }
            if (color == WireColor.Red)
            {
                return(tile.wire());
            }
            if (color == WireColor.Blue)
            {
                return(tile.wire2());
            }
            if (color == WireColor.Green)
            {
                return(tile.wire3());
            }
            //if (color == WireColor.Yellow)
            //  return tile.wire4();

            return(false);
        }
Exemple #37
0
        public override void Paint(Graphics graphics, IDrawingSurface layer, ITile iTile, int offsetX, int offsetY)
        {
            if (!m_enabled)
            {
                return;
            }

            //LibSys.StatusBar.Trace("LabeledPoint::Paint()  - " + Location + " : " + m_doName + m_labelBoundingRect);

            int x, y, w, h;

            x = m_imageBoundingRect.X + 1 + offsetX;
            y = m_imageBoundingRect.Y + 1 + offsetY;
            w = m_imageBoundingRect.Width - 2;
            h = m_imageBoundingRect.Height - 2;

            graphics.DrawEllipse(penMain, x, y, w, h);

            // debug only - show bounding rectangles:
            //graphics.DrawRectangle(Project.debugPen, m_boundingRect);			// red
            //graphics.DrawRectangle(Project.debug2Pen, m_imageBoundingRect);		// green
            //graphics.DrawRectangle(Project.debug3Pen, m_labelBoundingRect);		// yellow
        }
 public ITilesCollection WorldMapTiles()
 {
     ITile[] tiles = new ITile[]
     {
         new Tile("Graphics/Maps/WorldMap/Overlay/Land/Grass"),
         new Tile("Graphics/Maps/WorldMap/Overlay/Land/Sand"),
         new Tile("Graphics/Maps/WorldMap/Overlay/Water/Shallow"),
         new Tile("Graphics/Maps/WorldMap/Overlay/Water/Ocean"),
         new Tile("Graphics/Maps/WorldMap/Overlay/Water/DeepOcean"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/CityGround"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/CityWall"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/Harbour"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofStoneUp"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofStoneDown"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofStoneRight"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofStoneLeft"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofStoneCornerUpRight"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofMiddleVertical"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofMiddleHorisontal"),
         new Tile("Graphics/Maps/WorldMap/Overlay/City/House/Roof/RoofMiddleCornerUpRight")
     };
     return(new TileCollection(Content, tiles));
 }
Exemple #39
0
        void UpdateHighlight()
        {
            ITile endTile = input.GetTileUnderCursor();

            if (endTile == null)
            {
                Level.Map.DisableHighlight();
            }

            if (endTile != line[line.Count - 1])
            {
                line = GetLine(line[0], endTile);
            }

            Level.Map.HighlightTileList(line,
                                        line.All((tile) =>
                                                 BuildingType.CanBuild(GetBuildingRectangle(tile, BuildingType).TopLeft(),
                                                                       input.Player,
                                                                       Level)) &&
                                        cost.HasResources(input.Player, line.Count)
                                                                                        ? AbleColor
                                                                                        : UnableColor);
        }
Exemple #40
0
        internal void TransferRunOnToSuccessors(ITile runOn)
        {
            ParanoidAssertValid();

            bool done;

            do
            {
                var item = (WordItem)_headItems[_selectedIndex + 1];

                var selected = CreateHeadWordItem(item.Content);
                _headItems[_selectedIndex + 1] = selected;
                SetSelectedIndex(_selectedIndex + 1);

                AddSequenceTail(Context, PersistedSequenceWeight);

                done = ReferenceEquals(item, runOn);
            }while (!done);

            ContinueRunOnSuggestions();

            ParanoidAssertValid();
        }
Exemple #41
0
 internal void UpdateResources(ITile tile, bool ownerCities = true)
 {
     for (int relY = -3; relY <= 3; relY++)
     {
         for (int relX = -3; relX <= 3; relX++)
         {
             if (tile[relX, relY] == null)
             {
                 continue;
             }
             City city = tile[relX, relY].City;
             if (city == null)
             {
                 continue;
             }
             if (!ownerCities && CurrentPlayer == city.Owner)
             {
                 continue;
             }
             city.UpdateResources();
         }
     }
 }
Exemple #42
0
        private void CreateMaze(IReadOnlyList <string> mazeData, ITileType pellet)
        {
            Height    = mazeData.Count;
            Width     = mazeData[0].Length;
            MazeArray = new ITile[Height, Width];

            var x = 0;

            foreach (var lineData in mazeData)
            {
                var y = 0;
                foreach (var tileType in lineData.Select(Parser.GetTileType))
                {
                    MazeArray[x, y] = new Tile(tileType);
                    if (tileType.Display == pellet.Display)
                    {
                        Pellets++;
                    }
                    y++;
                }
                x++;
            }
        }
        public override void Apply(T map)
        {
            for (int xx = 0; xx < map.Width - 1; xx++)
            {
                for (int yy = 0; yy < map.Height - 1; yy++)
                {
                    ITile a1 = map.GetTile(new Loc(xx, yy));
                    ITile b1 = map.GetTile(new Loc(xx + 1, yy));
                    ITile a2 = map.GetTile(new Loc(xx, yy + 1));
                    ITile b2 = map.GetTile(new Loc(xx + 1, yy + 1));

                    int dropType = map.Rand.Next(3);
                    if (a1.TileEquivalent(this.Terrain) && b1.TileEquivalent(map.WallTerrain) && a2.TileEquivalent(map.WallTerrain) && b2.TileEquivalent(this.Terrain))
                    {
                        if (dropType % 2 == 0)
                        {
                            map.TrySetTile(new Loc(xx + 1, yy), this.Terrain.Copy());
                        }
                        if (dropType < 2)
                        {
                            map.TrySetTile(new Loc(xx, yy + 1), this.Terrain.Copy());
                        }
                    }
                    else if (a1.TileEquivalent(map.WallTerrain) && b1.TileEquivalent(this.Terrain) && a2.TileEquivalent(this.Terrain) && b2.TileEquivalent(map.WallTerrain))
                    {
                        if (dropType % 2 == 0)
                        {
                            map.TrySetTile(new Loc(xx, yy), this.Terrain.Copy());
                        }
                        if (dropType < 2)
                        {
                            map.TrySetTile(new Loc(xx + 1, yy + 1), this.Terrain.Copy());
                        }
                    }
                }
            }
        }
Exemple #44
0
 private static void DrawOceanBorderEast(ref Picture output, ITile tile)
 {
     if (tile.GetBorderType(Direction.East) == Terrain.Ocean)
     {
         return;
     }
     if (tile.GetBorderType(Direction.North) == Terrain.Ocean)
     {
         if (tile.GetBorderType(Direction.NorthEast) == Terrain.Ocean)
         {
             output.AddLayer(Res.GetPart("TER257", 72, 176, 8, 8), 8, 0);
         }
         else
         {
             output.AddLayer(Res.GetPart("TER257", 104, 176, 8, 8), 8, 0);
         }
     }
     else
     {
         output.AddLayer(Res.GetPart("TER257", 88, 176, 8, 8), 8, 0);
     }
     if (tile.GetBorderType(Direction.South) == Terrain.Ocean)
     {
         if (tile.GetBorderType(Direction.SouthEast) == Terrain.Ocean)
         {
             output.AddLayer(Res.GetPart("TER257", 24, 184, 8, 8), 8, 8);
         }
         else
         {
             output.AddLayer(Res.GetPart("TER257", 56, 184, 8, 8), 8, 8);
         }
     }
     else
     {
         output.AddLayer(Res.GetPart("TER257", 88, 184, 8, 8), 8, 8);
     }
 }
        public void Update(float dt)
        {
            this.tile = this.getCurrentTile();

            var bb = this.tile.CollisionBox;

            if (this.LookAt.X > 0)
            {
                bb = MathUtil.FlipHorizontal(bb, (int)this.tile.Size.X);
            }

            this.BoundingBox = new Rectangle(
                (int)this.Positon.X + bb.X,
                (int)this.Positon.Y + bb.Y,
                bb.Width,
                bb.Height);

            var pos = this.Positon;

            foreach (var force in this.forces.Values)
            {
                force.vel += force.acc * dt;
                pos       += force.vel;
            }

            this.Velocity = pos - this.Positon;

            var collResult = GameState.Collision.Move(this, pos);

            if (collResult != null)
            {
                this.Positon             = collResult.AvailablePosition;
                this.LastCollisionResult = collResult;
            }

            this.ResetForces(this.LastCollisionResult);
        }
Exemple #46
0
 private static void DrawOceanBorderWest(ref Picture output, ITile tile)
 {
     if (tile.GetBorderType(Direction.West) == Terrain.Ocean)
     {
         return;
     }
     if (tile.GetBorderType(Direction.North) == Terrain.Ocean)
     {
         if (tile.GetBorderType(Direction.NorthWest) == Terrain.Ocean)
         {
             output.AddLayer(Res.GetPart("TER257", 16, 176, 8, 8), 0, 0);
         }
         else
         {
             output.AddLayer(Res.GetPart("TER257", 48, 176, 8, 8), 0, 0);
         }
     }
     else
     {
         output.AddLayer(Res.GetPart("TER257", 80, 176, 8, 8), 0, 0);
     }
     if (tile.GetBorderType(Direction.South) == Terrain.Ocean)
     {
         if (tile.GetBorderType(Direction.SouthWest) == Terrain.Ocean)
         {
             output.AddLayer(Res.GetPart("TER257", 64, 184, 8, 8), 0, 8);
         }
         else
         {
             output.AddLayer(Res.GetPart("TER257", 96, 184, 8, 8), 0, 8);
         }
     }
     else
     {
         output.AddLayer(Res.GetPart("TER257", 80, 184, 8, 8), 0, 8);
     }
 }
Exemple #47
0
        private void PostProcessing(Object tiles)
        {
            List <ITile> Tiles = (List <ITile>)tiles;

            for (int i = 0; i < Tiles.Count; i++)
            {
                //ITile tile = map.Tiles[Tiles[i]];
                ITile tile = Tiles[i];

                if (tile.Height <= firstLevel)
                {
                    tile.color = blue;
                }
                else if (tile.Height > firstLevel && tile.Height <= secondLevel)
                {
                    tile.color = green;
                }
                else if (tile.Height > secondLevel && tile.Height <= thirdLevel)
                {
                    tile.color = tree;
                }
                else if (tile.Height > thirdLevel && tile.Height <= fourthLevel)
                {
                    tile.color = brown;
                }
                else if (tile.Height > fourthLevel)
                {
                    tile.color = red;
                }
            }


            //List<int> tileQueue = (List<int>)tiles;
            //Console.WriteLine("Clearing "+ tileQueue.Count+ " Tiles");
            //tileQueue.Clear();
        }
Exemple #48
0
    public void OnNeighborChanged(ITile neighbor)
    {
        int dx = neighbor.GetCoordinate().x - GetCoordinate().x;
        int dz = neighbor.GetCoordinate().z - GetCoordinate().z;

        bool isRight    = (dx == 1 && dz == 0);
        bool isLeft     = (dx == -1 && dz == 0);
        bool isForward  = (dx == 0 && dz == 1);
        bool isBackward = (dx == 0 && dz == -1);

        IAttachment attachment         = GetAttachment();
        IAttachment neighborAttachment = neighbor.GetAttachment();

        if (attachment is Road)
        {
            Road road = (Road)attachment;

            bool isNeighborRoad = (neighborAttachment is Road);
            if (isNeighborRoad && isRight)
            {
                road.connectRight = true;
            }
            if (isNeighborRoad && isLeft)
            {
                road.connectLeft = true;
            }
            if (isNeighborRoad && isForward)
            {
                road.connectForward = true;
            }
            if (isNeighborRoad && isBackward)
            {
                road.connectBackward = true;
            }
        }
    }
Exemple #49
0
        public bool Lock(ITile tile, bool blocking)
        {
            var startTime = DateTime.Now;
            var result    = AttemptLock(tile);

            if (result)
            {
                return(true);
            }
            if (!blocking)
            {
                return(false);
            }
            while (result != true)
            {
                if (DateTime.Now - startTime > Timeout)
                {
                    throw new Exception(string.Format("You appear to have a stuck lock. You may wish to remove the lock named:\n{0}", this.GetLockName(tile)));
                }
                Thread.Sleep(TimeSpan.FromSeconds(0.25));
                result = AttemptLock(tile);
            }
            return(true);
        }
Exemple #50
0
        protected override bool Confront(int relX, int relY)
        {
            ITile moveTarget = Map[X, Y][relX, relY];
            City  city       = moveTarget.City;

            if (city == null || city == Home || (city.Owner == Owner && Home != null && moveTarget.DistanceTo(Home) < 10))
            {
                MovementTo(relX, relY);
                return(true);
            }

            if (city.Owner != Owner)
            {
                EstablishTradeRoute(moveTarget.City);
                return(true);
            }

            if (Game.Human == Owner)
            {
                GameTask.Enqueue(Show.CaravanChoice(this, city));
            }

            return(true);
        }
Exemple #51
0
        public void Run()
        {
            // Not using Flyweight
            for (int i = 0; i < 20; i++)
            {
                ITile ceramicTile = new CeramicTile(GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                ceramicTile.Draw("CeramicTile");
                ITile stoneTile = new StoneTile(GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                stoneTile.Draw("StoneTile");
            }
            Console.WriteLine($"Total of files created not using Flyweight pattern and TileFactory factory : {CeramicTile.objectCounter} + {StoneTile.objectCounter} created");


            // Using Flyweight
            for (int i = 0; i < 20; i++)
            {
                ITile ceramicTile = TileFactory.GetTile("Ceramic");
                ceramicTile.Draw("CeramicTile", GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
                ITile stoneTile = TileFactory.GetTile("Stone");
                stoneTile.Draw("StoneTile", GetRandomNumber(), GetRandomNumber(), GetRandomNumber(), GetRandomNumber());
            }
            Console.WriteLine($"Total of files created using Flyweight pattern using TileFactory factory : {CeramicTile.objectCounter} + {StoneTile.objectCounter} created");
            Console.ReadKey();
        }
Exemple #52
0
        protected override void MovementDone(ITile previousTile)
        {
            base.MovementDone(previousTile);

            if (MovesLeft > 0)
            {
                return;
            }

            // Check if the Trireme is at open sea
            if (Tile.GetBorderTiles().Any(t => !(t is Ocean)))
            {
                return;
            }

            // The Trireme unit is surrounded by oceans, there's a 50% chance it will be lost at sea
            if (Common.Random.Next(0, 100) < 50)
            {
                return;
            }

            Game.DisbandUnit(this);
            GameTask.Enqueue(Message.Error("-- Civilization Note --", TextFile.Instance.GetGameText("ERROR/TRIREME")));
        }
Exemple #53
0
        private static void DrawDiagonalCoast(ref Picture output, ITile tile)
        {
            bool north = (tile.GetBorderType(Direction.North) == Terrain.Ocean);
            bool east  = (tile.GetBorderType(Direction.East) == Terrain.Ocean);
            bool south = (tile.GetBorderType(Direction.South) == Terrain.Ocean);
            bool west  = (tile.GetBorderType(Direction.West) == Terrain.Ocean);

            if (north && west && (tile.GetBorderType(Direction.NorthWest) != Terrain.Ocean))
            {
                output.AddLayer(Res.GetPart("TER257", 32, 176, 8, 8), 0, 0);
            }
            if (north && east && (tile.GetBorderType(Direction.NorthEast) != Terrain.Ocean))
            {
                output.AddLayer(Res.GetPart("TER257", 40, 176, 8, 8), 8, 0);
            }
            if (south && west && (tile.GetBorderType(Direction.SouthWest) != Terrain.Ocean))
            {
                output.AddLayer(Res.GetPart("TER257", 32, 184, 8, 8), 0, 8);
            }
            if (south && east && (tile.GetBorderType(Direction.SouthEast) != Terrain.Ocean))
            {
                output.AddLayer(Res.GetPart("TER257", 40, 184, 8, 8), 8, 8);
            }
        }
Exemple #54
0
        private Point[] GetLinePoints(ITile tile, Point[] hexagonPoints)
        {
            Point[] points = new Point[2];

            if (tile.Coordinate.Direction == EnumHarbourDirection.topright)
            {
                points[0] = hexagonPoints[0];
                points[1] = hexagonPoints[1];
            }
            if (tile.Coordinate.Direction == EnumHarbourDirection.right)
            {
                points[0] = hexagonPoints[1];
                points[1] = hexagonPoints[2];
            }
            if (tile.Coordinate.Direction == EnumHarbourDirection.downright)
            {
                points[0] = hexagonPoints[2];
                points[1] = hexagonPoints[3];
            }
            if (tile.Coordinate.Direction == EnumHarbourDirection.downleft)
            {
                points[0] = hexagonPoints[3];
                points[1] = hexagonPoints[4];
            }
            if (tile.Coordinate.Direction == EnumHarbourDirection.left)
            {
                points[0] = hexagonPoints[4];
                points[1] = hexagonPoints[5];
            }
            if (tile.Coordinate.Direction == EnumHarbourDirection.topleft)
            {
                points[0] = hexagonPoints[5];
                points[1] = hexagonPoints[6];
            }
            return(points);
        }
Exemple #55
0
        public bool CanMoveTo(int relX, int relY)
        {
            // Issue #93: fix problems with zone-of-control.

            // refactored out for unit testability
            ITile moveTarget = Map[X, Y][relX, relY];

            if (moveTarget == null)
            {
                return(false);
            }

            var thisUnits = Map[X, Y].GetBorderTiles().SelectMany(t => t.Units);
            var destUnits = moveTarget.GetBorderTiles().SelectMany(t => t.Units);

            // Any enemy units around my position OR the target position?
            bool thisBlocked = thisUnits.Any(u => u.Owner != Owner);
            bool destBlocked = destUnits.Any(u => u.Owner != Owner);
            bool destOK      = moveTarget.Units.Any(u => u.Owner == Owner) || moveTarget.HasCity;

            // Cannot move from a square adjacent to enemy unit to a square adjacent to enemy unit
            // but _can_ move to square occupied by own units or to any undefended city square
            return(destOK || !thisBlocked || !destBlocked);
        }
Exemple #56
0
        protected void CalculatePossibleMoves(Vector2 playerPosition)
        {
            int x = (int)playerPosition.x;
            int y = (int)playerPosition.y;

            //Tile playerTile = Tile.GetTile(x, y);
            ITile playerTile = board[x, y];

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        possibleMoves[i, j] = false;
                    }
                    else if (Math.Abs(x - i) <= 1 && Math.Abs(j - y) <= 1)
                    {
                        //Tile tile = Tile.GetTile(i, j);
                        ITile tile = board[i, j];
                        if (tile.HasPlayer() || tile.Height == Height.ROOF || (playerTile.Height + 1).CompareTo(tile.Height) < 0)
                        {
                            possibleMoves[i, j] = false;
                        }
                        else
                        {
                            possibleMoves[i, j] = true;
                        }
                    }
                    else
                    {
                        possibleMoves[i, j] = false;
                    }
                }
            }
        }
Exemple #57
0
        public static void CheckModifiedTiles(int i, int j, Stream stream)
        {
            if (modifiedTile.Where(t => t.i == i && t.j == j).ToArray().Length != 0)
            {
                return;
            }

            ITile tile = Main.tile[i, j];

            stream.Seek(0, SeekOrigin.Begin);
            var  newTile = new NetTile(stream);
            byte Slope   = 0;

            if (newTile.Slope)
            {
                Slope += 1;
            }
            if (newTile.Slope2)
            {
                Slope += 2;
            }
            if (newTile.Slope3)
            {
                Slope += 4;
            }
            modifiedTile.Add(new TileData()
            {
                i         = i,
                j         = j,
                type      = tile.type,
                slope     = Slope,
                active    = tile.active(),
                halfBrick = newTile.IsHalf,
                wall      = tile.wall
            });
        }
 public override byte[] Render(ITile tile)
 {
     if (MetaTile)
     {
         MetaTile metatile = GetMetaTile(tile);
         try
         {
             Cache.Lock(metatile);
             return(Cache.Get(tile) ?? RenderMetaTile(metatile, tile));
         }
         finally
         {
             Cache.Unlock(metatile);
         }
     }
     else
     {
         if (!string.IsNullOrEmpty(WatermarkImage))
         {
             return(Watermark(RenderTile(tile)).GetBytes());
         }
         return(RenderTile(tile));
     }
 }
        /// <summary>
        /// METHOD: MakeGrid, this method initialises and returns a 2D array of tiles
        /// which will be the "boards" for the game. 10x10 as per spec
        /// </summary>
        /// <returns> Return the initialised 2D array of tiles</returns>
        private ITile[,] MakeGrid()
        {
            // Use 2 * (10*10)2D Arrays to create two tile grids. 1. For the player
            // to place their ships on
            // 2. For the player to visibly see where they have fired shots to, what was
            // a miss and what was a hit

            ITile[,] grid = new ITile[10, 10];

            // FOR LOOP for the X acis
            for (int x = 0; x < 10; x++)
            {
                // FOR LOOP for the Y axis
                for (int y = 0; y < 10; y++)
                {
                    // INITIALISE a new tile at grid position X and Y, pass in
                    // the string found at y - 1 in the in to string array and then the x value
                    grid[x, y] = new Tile((_intToCharDict[y + 1].ToString()) + x);
                }
            }

            // RETURN the 2D array of ITiles called grid
            return(grid);
        }
Exemple #60
0
        public static bool AllowIrrigation(this ITile tile)
        {
            if (tile.Irrigation)
            {
                return(false);
            }
            // TODO fire-eggs: this should be a flag in ITile or Terrain
            switch (tile.Type)
            {
            case Terrain.Desert:
            case Terrain.Grassland1:
            case Terrain.Grassland2:
            case Terrain.Hills:
            case Terrain.Plains:
            case Terrain.River:
                break;

            default:
                return(false);
            }
            //if (!(tile is Desert || tile is Grassland || tile is Hills || tile is Plains || tile is River)) return false;
            // fire-eggs 20190810 irrigation is NOT allowed e.g. to left of city
            return(CrossTiles(tile).Any(x => (x.Irrigation || x.Type == Terrain.River || x.IsOcean) && !x.HasCity));
        }