nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Player Class Reference

Public Types

enum  Direction { UP , DOWN , LEFT , RIGHT }
 

Public Member Functions

 Player (int x, int y)
 
bool isAlive ()
 
int getSize ()
 
int getX ()
 Returns the head's x position.
 
int getY ()
 Returns the head's y position.
 
void moveTo (int x, int y)
 
void move (Direction direction)
 
void kill ()
 
void update (Board *board)
 
void draw (Window *win)
 
bool headHit (int x, int y)
 
bool bodyHit (int x, int y, bool isCheckingHead=false)
 Tells if something at #x and #y collides with any part of the snake.
 
void increase ()
 

Detailed Description

Definition at line 23 of file Player.hpp.

Member Enumeration Documentation

◆ Direction

enum Player::Direction

Definition at line 26 of file Player.hpp.

Constructor & Destructor Documentation

◆ Player()

Player::Player ( int x,
int y )

Definition at line 4 of file Player.cpp.

◆ ~Player()

virtual Player::~Player ( )
inlinevirtual

Definition at line 32 of file Player.hpp.

Member Function Documentation

◆ bodyHit()

bool Player::bodyHit ( int x,
int y,
bool isCheckingHead = false )

Tells if something at #x and #y collides with any part of the snake.

Note
#isHead is a huge HACK to allow me to check if the head collides with the body. Ignore it.

Definition at line 146 of file Player.cpp.

◆ draw()

void Player::draw ( Window * win)

Definition at line 122 of file Player.cpp.

◆ getSize()

int Player::getSize ( )

Definition at line 21 of file Player.cpp.

◆ getX()

int Player::getX ( )

Returns the head's x position.

Definition at line 25 of file Player.cpp.

◆ getY()

int Player::getY ( )

Returns the head's y position.

Definition at line 29 of file Player.cpp.

◆ headHit()

bool Player::headHit ( int x,
int y )

Definition at line 141 of file Player.cpp.

◆ increase()

void Player::increase ( )

Definition at line 158 of file Player.cpp.

◆ isAlive()

bool Player::isAlive ( )

Definition at line 17 of file Player.cpp.

◆ kill()

void Player::kill ( )

Definition at line 42 of file Player.cpp.

◆ move()

void Player::move ( Direction direction)

Definition at line 38 of file Player.cpp.

◆ moveTo()

void Player::moveTo ( int x,
int y )

Definition at line 33 of file Player.cpp.

◆ update()

void Player::update ( Board * board)

Definition at line 46 of file Player.cpp.


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