/// <summary> /// Handles the click method specifically in design mode. /// </summary> /// <param name="mapLocation">The map location clicked.</param> private void HandleDesignClick(MapLocation mapLocation) { List <Entity> entitys = mapLocation.GetEntitys(); EntityType entityType = ((DesignForm)SokobanProgram.getFormFromState(GameState.DESIGN)).GetToolType(); if (entityType == EntityType.HERO && HasEntity(EntityType.HERO)) { MessageBox.Show("There can only be one Hero on the game board."); return; } if (entitys.Count > 0) { mapLocation.ClearEntities(); } Entity entity = Entity.GetEntityByType(entityType); if (entity == null) { return; } mapLocation.AddEntity(entity); }
public void HandleMoveClick(Direction direction) { Hero hero = SokobanProgram.GetGameManager().GetHero(); if (hero == null) { return; } MapLocation location = hero.GetLocation(); hero.SetDirection(direction); MapLocation moveSpot = GetNextMoveSpot(location, direction); if (moveSpot == null) { return; } bool checkWinning = false; if (moveSpot.HasEntitys()) { Entity entity; for (int i = 0; i < moveSpot.GetEntitys().Count; i++) { entity = moveSpot.GetEntitys()[i]; if (entity.GetEntityType() == EntityType.BOX) { MapLocation boxMoveSpot = GetNextMoveSpot(entity.GetLocation(), direction); if (boxMoveSpot == null) { return; } //Box attempting to move to a spot with entites. if (boxMoveSpot.HasEntitys()) { Entity e; for (int k = 0; k < boxMoveSpot.GetEntitys().Count; k++) { e = boxMoveSpot.GetEntitys()[k]; if (e.GetEntityType() != EntityType.DESTINATION) { return; } if (e.GetEntityType() == EntityType.DESTINATION) { ((Box)entity).SetColor(BoxColor.BLUE); checkWinning = true; break; } } } else { //Box moving off destination if (entity.GetEntityType() == EntityType.BOX) { ((Box)entity).SetColor(BoxColor.RED); } } entity.GetLocation().RemoveEntity(entity); boxMoveSpot.AddEntity(entity); hero.IncrementBoxesPushed(); break; } if (entity.GetEntityType() != EntityType.DESTINATION) { return; } } } location.RemoveEntity(hero); moveSpot.AddEntity(hero); hero.IncrementMoves(); if (checkWinning) { CheckGameWinning(); } }