LogDoctor 2.00
Parse Apache2/Nginx/IIS logs and create statistics
Loading...
Searching...
No Matches
Classes | Private Types | Private Slots | Private Member Functions | Private Attributes | List of all members
Snake Class Reference

Snake. More...

#include <snake.h>

Inheritance diagram for Snake:

Classes

struct  BodyPart
 Instance of a part of the body of the snake. More...
 
struct  Food
 Instance of the egg which will be eat by the snake. More...
 

Private Types

enum  Direction { UP , DOWN , LEFT , RIGHT }
 Enumerates the possible directions. More...
 

Private Slots

void on_button_Play_clicked ()
 Starts the game.
 
void processGameLogic ()
 Processes the logic of the game.
 

Private Member Functions

void keyPressEvent (QKeyEvent *event) override
 Stores the valid key events in a queue. More...
 
void processNextKeyEvent ()
 Processes the key events in the queue. More...
 
const bool snakeInTile (const unsigned int &x, const unsigned int &y)
 Checks whether is there a part of the snake in the given position.
 
void increaseSnakeBody (const bool &initial=false)
 Increases the length of the body of the snake of 1 part.
 
void updateSnakePosition (const bool &dry=false)
 Update the position and direction of the entire snake.
 
void checkCollision ()
 Checks if the head will collide with another entity.
 
void spawnFood ()
 Spawns the egg in a new position.
 
void increaseGameScore ()
 Increases the player's score by one.
 

Private Attributes

std::queue< unsigned short > key_events
 Stores the key events.
 
const unsigned int MAX_SNAKE_LENGTH = 64
 The maximum length of the snake.
 
std::vector< BodyPartsnake
 The snake.
 

Detailed Description

Snake.

A reproduction of the timeless classic game

Member Enumeration Documentation

◆ Direction

enum Snake::Direction
private

Enumerates the possible directions.

Enumerator
UP 

Up.

DOWN 

Down.

LEFT 

Left.

RIGHT 

Right.

Member Function Documentation

◆ keyPressEvent()

void Snake::keyPressEvent ( QKeyEvent *  event)
overrideprivate

Stores the valid key events in a queue.

Valid keys are UP/DOWN/LEFT/RIGHT arrows and W/S/A/D letters

See also
key_events, processNextKeyEvent()

◆ processNextKeyEvent()

void Snake::processNextKeyEvent ( )
private

Processes the key events in the queue.

See also
key_events, keyPressEvent()

The documentation for this class was generated from the following files: