SERG-Delft / jpacman

Pacman-inspired game, for teaching testing purposes. (>= v9.0.0)
5 stars 684 forks source link

Add `opposite` method to `Direction` #29

Open FWDekker opened 5 years ago

FWDekker commented 5 years ago

When Clyde runs away from the player, it looks up the opposite of the direction it would otherwise have gone in. To find the opposite, Clyde uses a hash map that maps each direction to its opposite. This PR replaces that hash map with a dedicated function in the Direction class.

The default branch in the getOpposite method is not reachable because it is not possible to instantiate new instances of an enum class, but at the same time the code won't compile without it.

casperboone commented 5 years ago

Thanks for the PR @FWDekker, I like the change :)

I'd personally prefer opposite() as a method instead of getOpposite(), but don't have very strong feelings about this.

FWDekker commented 5 years ago

@casperboone I don't really have any strong feelings either so I've renamed it to opposite().