Coding Snake Getting Started
I'm take a class about basics in C++ and now i try to make the exercise.
The exercise is to code a console snake game. Given is the following interface:
It isn't allowed to change this code.
Now my problem is, that i don't now how to start and how i can use this classes.
The exercise is to code a console snake game. Given is the following interface:
Code:
#ifndef INTERFACES_H_
#define INTERFACES_H_
struct Field_S
{
Field_S()
: m_Fruit( false ) ,
m_SnakeHead( false ) ,
m_SnakeBody( 0 ) ,
m_Wall( false )
{} ;
~Field_S() {} ;
bool m_Fruit ;
bool m_SnakeHead ;
unsigned int m_SnakeBody ;
bool m_Wall ;
};
// Enum for the movement of the snakes head.
enum Directions_E
{
Up_e, Down_e, Left_e, Right_e
};
class IBoard
{
public:
IBoard() {} ;
virtual ~IBoard() {} ;
// Initializes the board with the given ID, places the
// snake in the center and a fruit randomly on the board.
virtual void InitBoard( unsigned int ID ) = 0 ;
// Returns the field at the given position.
virtual Field_S GetField( unsigned int PosX , unsigned int PosY ) const = 0 ;
// Moves the head of the snake.
virtual void Move( Directions_E Direction ) = 0 ;
// Returns true, if the snake is alive and the game can
// continue and false otherwise.
virtual bool IsSnakeAlive() const = 0 ;
// Returns the current amount of points.
virtual int GetPoints() const = 0 ;
};
class IPlayer
{
public:
IPlayer() {} ;
virtual ~IPlayer() {} ;
// Plays the given board by moving the snake.
virtual void Play( IBoard* pBoard ) = 0 ;
};
#endif /*INTERFACES_H_*/
Now my problem is, that i don't now how to start and how i can use this classes.