From 26eda706aae4a6ab69711d5be2751cdf4d196315 Mon Sep 17 00:00:00 2001 From: sourabhv7 <54184997+sourabhv7@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:15:05 +0530 Subject: [PATCH 1/3] Update snake.cpp some important comment added in program to understand the code by everyone. --- snake.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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. From facee43a05c50583b3a5f98afbe85260c9316e2d Mon Sep 17 00:00:00 2001 From: sourabhv7 <54184997+sourabhv7@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:17:19 +0530 Subject: [PATCH 2/3] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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. From beb904ad50d29defddd99f47f8518da167f24d48 Mon Sep 17 00:00:00 2001 From: sourabhv7 <54184997+sourabhv7@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:19:15 +0530 Subject: [PATCH 3/3] Update gamecontroller.cpp Bug fixes --- gamecontroller.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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() {