* Constructor of SnakeGame. * * @param {object} args Configurations for the game. Fields include: * - height {number} height of the board (positive integer). * - width {number} width of the board (positive integer). * - numFruits {number} number of fruits present on the screen
(args)
| 58 | * - initLen {number} initial length of the snake. |
| 59 | */ |
| 60 | constructor(args) { |
| 61 | if (args == null) { |
| 62 | args = {}; |
| 63 | } |
| 64 | if (args.height == null) { |
| 65 | args.height = DEFAULT_HEIGHT; |
| 66 | } |
| 67 | if (args.width == null) { |
| 68 | args.width = DEFAULT_WIDTH; |
| 69 | } |
| 70 | if (args.numFruits == null) { |
| 71 | args.numFruits = DEFAULT_NUM_FRUITS; |
| 72 | } |
| 73 | if (args.initLen == null) { |
| 74 | args.initLen = DEFAULT_INIT_LEN; |
| 75 | } |
| 76 | |
| 77 | assertPositiveInteger(args.height, 'height'); |
| 78 | assertPositiveInteger(args.width, 'width'); |
| 79 | assertPositiveInteger(args.numFruits, 'numFruits'); |
| 80 | assertPositiveInteger(args.initLen, 'initLen'); |
| 81 | |
| 82 | this.height_ = args.height; |
| 83 | this.width_ = args.width; |
| 84 | this.numFruits_ = args.numFruits; |
| 85 | this.initLen_ = args.initLen; |
| 86 | |
| 87 | this.reset(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Reset the state of the game. |
nothing calls this directly
no test coverage detected