枚举

枚举,也称为枚举,是一种包含一组固定常量的数据类型。

全局枚举

  1. enum {LEFT, RIGHT, UP, DOWN}
  2. # Same as writing
  3. const LEFT = 0
  4. const RIGHT = 1
  5. const UP = 2
  6. const DOWN = 3

本地枚举

  1. enum MOVE_SET {LEFT, RIGHT, UP, DOWN}
  2. MOVE_SET.LEFT # 0
  3. MOVE_SET.RIGHT # 1
  4. MOVE_SET.UP # 2
  5. MOVE_SET.DOWN # 3