Addsy

snake.cpp

Apr 13th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include "snake.hpp"
  2.  
  3.  
  4. #include <cstdlib>
  5.  
  6.  
  7. void Snake::move()
  8. {
  9.     switch(direction_){
  10.     case Direction::North:
  11.         position_.y += 1;
  12.         break;
  13.     case Direction::East:
  14.         position_.x += 1;
  15.         break;
  16.     case Direction::South:
  17.         position_.y -= 1;
  18.         break;
  19.     case Direction::West:
  20.         position_.x -= 1;
  21.     }
  22.  
  23.     if (position_.x < 6.4) position_.x = 44.8; else if (position_.x > 44.8) position_.x = 6.4;
  24.     if (position_.y < 0) position_.y = 38.4; else if (position_.y > 38.4) position_.y = 0;
  25.  
  26. }
  27.  
  28.  
  29. //Snake canot move back on its self
  30. //Cannot get working
  31.  
  32. //bool Snake::MoveValid (Direction move) const
  33. //{
  34. //   switch (move)
  35. //   {
  36. //      case Direction::North:
  37. //         switch ()
  38. //         {
  39. //            case Direction::North:
  40. //            case Direction::West:
  41. //            case Direction::East:
  42. //               return true;
  43. //
  44. //            default:
  45. //               return false;
  46. //         }
  47. //
  48. //      case Direction::West:
  49. //         switch ()
  50. //         {
  51. //            case Direction::West:
  52. //            case Direction::North:
  53. //            case Direction::South:
  54. //               return true;
  55. //
  56. //            default:
  57. //               return false;
  58. //         }
  59. //
  60. //      case Direction::East:
  61. //         switch ()
  62. //         {
  63. //            case Direction::East:
  64. //            case Direction::North:
  65. //            case Direction::South:
  66. //               return true;
  67. //
  68. //            default:
  69. //               return false;
  70. //         }
  71. //
  72. //      case Direction::South:
  73. //         switch ()
  74. //         {
  75. //            case Direction::South:
  76. //            case Direction::West:
  77. //            case Direction::East:
  78. //               return true;
  79. //
  80. //            default:
  81. //               return false;
  82. //         }
  83. //
  84. //      default:
  85. //         return false;
  86. //   }
  87. //
  88. //   return false;
  89. //}
  90.  
  91.  
  92.  
  93. void Snake::render(prg::Canvas& canvas) const
  94. {
  95.  
  96.     canvas.drawCircle(getPosition().x * 20, getPosition().y * 20,19.2,prg::Colour::GREEN);
  97. }
  98.  
  99. void Snake::changeDirection(Direction new_direction)
  100. {
  101.     direction_ = new_direction;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment