Snake.h
1 // SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include "Arduino.h" 6 7 class Snake { 8 private: 9 uint8_t foodX; //(0-7) 10 uint8_t foodY; //(0-15) 11 uint16_t snakeLength; 12 int8_t snakeHeadX; 13 int8_t snakeHeadY; 14 int8_t snakeHeadDX; 15 int8_t snakeHeadDY; 16 uint8_t snakeBoard[16][8]; 17 uint8_t activeSnakeBoard[16]; 18 unsigned long lastSnakeMoveTime; 19 bool allowToChangeDirection; 20 21 void placeFood(); 22 bool moveSnake(); // return true if move is valid 23 void gameOver(); 24 25 public: 26 bool gameRunning; 27 void init(); 28 void run(); 29 void changeDirection(int8_t dx, int8_t dy); // should not run twice 30 uint8_t* getActiveBoard(); 31 };