Refactor Directions.
This commit is contained in:
		
							parent
							
								
									3958b3504d
								
							
						
					
					
						commit
						8c68ea4844
					
				
					 2 changed files with 6 additions and 21 deletions
				
			
		|  | @ -11,7 +11,7 @@ import lombok.experimental.FieldDefaults; | |||
| public class Tile { | ||||
|     // FIXME remove me; only for debugging | ||||
|     @Getter | ||||
|     final Directions walls = new Directions(); | ||||
|     final Walls walls = new Walls(); | ||||
|     @Getter | ||||
|     boolean visited = false; | ||||
| 
 | ||||
|  | @ -44,7 +44,7 @@ public class Tile { | |||
|     } | ||||
| 
 | ||||
|     public Option<Direction> getRandomAvailableDirection() { | ||||
|         return Stream.ofAll(this.walls.getSet(true)).shuffle().headOption(); | ||||
|         return Stream.ofAll(this.walls.getUnhardenedSet()).shuffle().headOption(); | ||||
|     } | ||||
| 
 | ||||
|     public boolean hasWallAt(@NonNull final Direction direction) { | ||||
|  |  | |||
|  | @ -1,17 +1,14 @@ | |||
| package ch.fritteli.labyrinth; | ||||
| 
 | ||||
| import io.vavr.collection.Stream; | ||||
| import lombok.Getter; | ||||
| import lombok.NonNull; | ||||
| 
 | ||||
| import java.util.EnumSet; | ||||
| import java.util.HashSet; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| public class Directions { | ||||
| public class Walls { | ||||
|     private final Set<Direction> directions = new HashSet<>(); | ||||
|     // FIXME remove getter, only for debugging | ||||
|     @Getter | ||||
|     private final Set<Direction> hardened = new HashSet<>(); | ||||
| 
 | ||||
|     public boolean set(@NonNull final Direction direction) { | ||||
|  | @ -29,25 +26,13 @@ public class Directions { | |||
|         return this.directions.remove(direction); | ||||
|     } | ||||
| 
 | ||||
|     public void clearAll() { | ||||
|         this.directions.clear(); | ||||
|         this.directions.addAll(this.hardened); | ||||
|     } | ||||
| 
 | ||||
|     public boolean isSet(@NonNull final Direction direction) { | ||||
|         return this.directions.contains(direction); | ||||
|     } | ||||
| 
 | ||||
|     public Iterable<Direction> getSet() { | ||||
|         return this.getSet(false); | ||||
|     } | ||||
| 
 | ||||
|     public Iterable<Direction> getSet(final boolean onlyBrittleWalls) { | ||||
|         if (onlyBrittleWalls) { | ||||
|             return Stream.ofAll(this.directions) | ||||
|                     .removeAll(this.hardened); | ||||
|         } | ||||
|         return Stream.ofAll(this.directions); | ||||
|     public Iterable<Direction> getUnhardenedSet() { | ||||
|         return Stream.ofAll(this.directions) | ||||
|                 .removeAll(this.hardened); | ||||
|     } | ||||
| 
 | ||||
|     public void harden(@NonNull final Direction direction) { | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue