Advertisement
Guest User

snake.hpp

a guest
Jan 8th, 2014
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <ctime>
  7. #include <list>
  8. #include "config.hpp"
  9.  
  10. enum SnakeCellType {
  11.     head, body, tail
  12. };
  13.  
  14. struct SnakeCell {
  15.     SnakeCellType cellType;
  16.     unsigned char positionX;
  17.     unsigned char positionY;
  18.     SnakeCell(SnakeCellType initCellType, unsigned char initPosX, unsigned char initPosY):
  19.         cellType(initCellType), positionX(initPosX), positionY(initPosY) {}
  20.     SnakeCell() {}
  21. };
  22.  
  23. class Snake {
  24. private:
  25.     std::list<SnakeCell> _snakeCell;
  26.     std::list<SnakeCell>::iterator itHead;
  27.     std::list<SnakeCell>::iterator itTail;
  28.     SnakeCell _preCell;
  29.     Snake();
  30.     void CutTail();
  31.     void UpdateLimbs();
  32.     void UpdateTail();
  33.     void UpdateHead();
  34. public:
  35.     Snake(unsigned char initPosX, unsigned char initPosY);
  36.     void MoveLeft();
  37.     void MoveRight();
  38.     void MoveUp();
  39.     void MoveDown();
  40.     void MoveByKeyPressed(ControlKeyCodes keyPressed);
  41.     void GrowTo(unsigned char newPosX, unsigned char newPosY);
  42.     void GrowLeft();
  43.     void GrowRight();
  44.     void GrowUp();
  45.     void GrowDown();
  46.     unsigned char GetHeadPosX();
  47.     unsigned char GetHeadPosY();
  48.     unsigned char GetTailPosX();
  49.     unsigned char GetTailPosY();
  50.     unsigned char GetTailPrePosX();
  51.     unsigned char GetTailPrePosY();
  52. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement