diff --git a/README.md b/README.md index 8f396b0..6f19d00 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ snake-game ========== -A snake game based on Qt. \ No newline at end of file +A snake game based on Qt. +The game is created with c++ and c language. +With the graphics it looks good. diff --git a/gamecontroller.cpp b/gamecontroller.cpp index 837cc81..bc5ad02 100644 --- a/gamecontroller.cpp +++ b/gamecontroller.cpp @@ -39,9 +39,9 @@ void GameController::snakeAteFood(Food *food) addNewFood(); } -//void GameController::snakeHitWall(Snake *snake, Wall *wall) -//{ -//} + + + void GameController::snakeAteItself() { diff --git a/snake.cpp b/snake.cpp index ed3500f..6dec2d3 100644 --- a/snake.cpp +++ b/snake.cpp @@ -1,11 +1,14 @@ +//Snake game with c++ + +//Adding important libraries #include #include "constants.h" #include "gamecontroller.h" #include "snake.h" -static const qreal SNAKE_SIZE = TILE_SIZE; - +static const qreal SNAKE_SIZE = TILE_SIZE; //snake size +//setup controller of game Snake::Snake(GameController &controller) : head(0, 0), growing(7), @@ -39,7 +42,7 @@ QRectF Snake::boundingRect() const ); return bound; } - +//head to tail QPainterPath Snake::shape() const { QPainterPath path; @@ -54,14 +57,14 @@ QPainterPath Snake::shape() const return path; } - +//adding graphics void Snake::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->save(); painter->fillPath(shape(), Qt::yellow); painter->restore(); } - +//setting bottons for changing direction of snake . void Snake::setMoveDirection(Direction direction) { if (moveDirection == MoveLeft && direction == MoveRight) @@ -79,7 +82,7 @@ Snake::Direction Snake::currentDirection() { return moveDirection; } - +//add counter and speed of the snake void Snake::advance(int step) { if (!step) { @@ -120,6 +123,7 @@ void Snake::advance(int step) handleCollisions(); } +//increasing size of snake void Snake::moveLeft() { head.rx() -= SNAKE_SIZE; @@ -156,7 +160,7 @@ void Snake::handleCollisions() { QList collisions = collidingItems(); - // Check collisions with other objects on screen +// Check collisions with other objects on screen foreach (QGraphicsItem *collidingItem, collisions) { if (collidingItem->data(GD_Type) == GO_Food) { // Let GameController handle the event by putting another apple @@ -165,8 +169,9 @@ void Snake::handleCollisions() } } - // Check snake eating itself +// Check snake eating itself if (tail.contains(head)) { controller.snakeAteItself(); } } +//now lets time to test it.