SnakeGame  1
Implementing a game of Snake
 All Classes Functions Variables Pages
Public Attributes | List of all members
com.gradescope.spampede.SnakeMode Enum Reference

SnakeMode - is an enumeration (aka enum) rather than an class. More...

Public Attributes

 GOING_NORTH
 
 GOING_SOUTH
 
 GOING_EAST
 
 GOING_WEST
 

Detailed Description

SnakeMode - is an enumeration (aka enum) rather than an class.

Enumerations are used when we want behavior like a class (i.e., methods), but we don't want people to be able to make additional objects of the type. We should only have a set number of these objects. Instead of creating this enum, we could have had SpampedeData store a String (e.g. "N", "S", "E", "W", or "A") to keep track of the mode. However, if we accidentally set the mode to be "M" or some other invalid String we wouldn't get any compile time check! If we use this enum (i.e., SnakeMode) we can't incorrectly set the mode within SpampedeMode.

Author
CS60 instructors

The documentation for this enum was generated from the following file: