Skip to content

Add opposite method to Direction#29

Open
fwdekker wants to merge 2 commits intomasterfrom
opposite-method
Open

Add opposite method to Direction#29
fwdekker wants to merge 2 commits intomasterfrom
opposite-method

Conversation

@fwdekker
Copy link
Member

@fwdekker fwdekker commented May 3, 2019

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 casperboone added the next-year We will include this change after the current edition of the course label May 5, 2019
@casperboone
Copy link
Member

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
Copy link
Member Author

fwdekker commented May 8, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next-year We will include this change after the current edition of the course

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments