private void UpdateMovables(Movement movement) { Point newPlayerPos = playerPos; newPlayerPos = CalcNewPosition(newPlayerPos, movement); ElementType type = level.GetElement(newPlayerPos.X, newPlayerPos.Y); if (ElementType.Wall == type) { return; } if (ElementType.Box == type || ElementType.BoaxOnGoal == type) { //box will be moved Point newBoxPos = CalcNewPosition(newPlayerPos, movement); ElementType type2 = level.GetElement(newBoxPos.X, newBoxPos.Y); //is new box position invalid if (ElementType.Floor != type2 && ElementType.Goal != type2) { return; } //moving box level.MoveBox(newPlayerPos, newBoxPos); } Point oldPlayerPos = playerPos; playerPos = newPlayerPos; level.MovePlayer(oldPlayerPos, playerPos); }
public static void MovePlayer(this Level level, Point oldPos, Point newPos) { ElementType type = level.GetElement(oldPos); switch (type) { case ElementType.Man: level.SetElement(oldPos, ElementType.Floor); break; case ElementType.ManOnGoal: level.SetElement(oldPos, ElementType.Goal); break; default: return; } ElementType type2 = level.GetElement(newPos); switch (type2) { case ElementType.Floor: level.SetElement(newPos, ElementType.Man); break; case ElementType.Goal: level.SetElement(newPos, ElementType.ManOnGoal); break; default: return; } }