/// <summary> /// Takes the direction and moves the Entity to the tile according to the direction. /// Checks if the game is paused and if the Entity is able to move. /// Asks if there is a neighbor tile next to the Entity in the current direction. /// Asks if something is in that tile. /// Depending what is in that tile, returns true (to not move) or false (to move). /// Moving the Entity saves it in that tile and saves null in its place. /// </summary> /// <param name="pDirection"></param> /// <returns></returns> /// public bool Move(Direction pDirection) { Tile neighborTile = thisTile.GetNeighbour(pDirection); if (neighborTile == null) { return(false); } else if (neighborTile.GetEntity() == null) { neighborTile.SaveEntity(this); thisTile.SaveEntity(null); thisTile = neighborTile; _level.DrawEntities(); return(true); } else if (neighborTile.GetEntity() is Pillar && IsEnemy == false) { if (((Pillar)neighborTile.GetEntity()).Move(pDirection)) { neighborTile.SaveEntity(this); thisTile.SaveEntity(null); _level.DrawEntities(); thisTile = neighborTile; return(true); } else { return(false); } } else if (neighborTile.GetEntity() is Player && IsEnemy == true) { _timer.Stop(); thisTile.GetEntity().Move(Direction.None); GetTexture.Dispose(); if (MessageBox.Show("You got hit by the enemy! Restart?", "Angry Chicken", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _game.Restart(); } else { Application.Exit(); } return(true); } else if (neighborTile.GetEntity() is Enemy) { return(false); } else { return(false); } }
public void MoveRandomly(int count) { switch (count) { case 1: rngDirection = Direction.North; break; case 2: rngDirection = Direction.South; break; case 3: rngDirection = Direction.East; break; case 4: rngDirection = Direction.West; break; } Tile neighborTile = EnemyTile.GetNeighbour(rngDirection); if (neighborTile.GetEntity() == null || neighborTile.GetEntity() is Player) { Move(rngDirection); } if (Move(Direction.North) == false && Move(~Direction.North) == false && Move(Direction.West) == false && Move(~Direction.West) == false) { _timer.Stop(); if (MessageBox.Show("You win! Restart?", "Angry Chicken", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _game.Restart(); } else { Application.Exit(); } } }