Snoke
ball.cpp
Go to the documentation of this file.
1 
11 #include "ball.h"
12 
18 bool Ball::init(Point fieldSize)
19 {
20  if(fieldSize.x > 2 && fieldSize.y > 2)
21  {
22  seed = time(NULL);
23  randomEngine.seed(seed);
24  distributionX = *(new std::uniform_int_distribution<int>(1, fieldSize.x - 1));
25  distributionY = *(new std::uniform_int_distribution<int>(1, fieldSize.y - 1));
26  position.x = -1;
27  position.y = -1;
28  position.style.letter = '0';
29  return true;
30  }
31  return false;
32 }
33 
38 {
39  return position;
40 }
41 
48 {
49  if(p.x >= 1 && p.x <= gameFieldSize.x && p.y >= 1 && p.y <= gameFieldSize.y)
50  {
51  this->position.x = p.x;
52  this->position.y = p.y;
53  return true;
54  }
55  return false;
56 }
57 
58 std::mt19937* Ball::getRandomEngine()
59 {
60  return &this->randomEngine;
61 }
short x
Definition: common.h:55
std::mt19937 * getRandomEngine()
Definition: ball.cpp:58
definitions and prototypes for Ball class
Point getCoords()
Get the ball coords without giving the direct access.
Definition: ball.cpp:37
bool init(Point dim)
Initialization.
Definition: ball.cpp:18
std::mt19937 randomEngine
Definition: ball.h:37
Point position
Definition: ball.h:36
uint32_t seed
Definition: ball.h:38
std::uniform_int_distribution< int > distributionX
Definition: ball.h:40
Point gameFieldSize
Definition: game.cpp:17
PointStyle style
Definition: common.h:57
bool setCoords(Point p)
Sets coordinates of the ball to given if they are correct.
Definition: ball.cpp:47
short y
Definition: common.h:56
char letter
Definition: common.h:40
std::uniform_int_distribution< int > distributionY
Definition: ball.h:41
Coordinates and style of the cell in console window.
Definition: common.h:52