improved
This commit is contained in:
+1
-1
@@ -32,7 +32,7 @@ public:
|
||||
void updateScore();
|
||||
Score getScore();
|
||||
|
||||
bool canMove() const;
|
||||
bool hasMoves() const;
|
||||
bool move(Direction direction);
|
||||
|
||||
std::vector<Position> getEmptyTiles() const;
|
||||
|
||||
@@ -14,24 +14,24 @@ int main() {
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
|
||||
while (canMove) {
|
||||
while (field.hasMoves()) {
|
||||
field.debug();
|
||||
std::cin >> action;
|
||||
switch (action) {
|
||||
case 'w':
|
||||
canMove = field.move(Direction::up);
|
||||
field.move(Direction::up);
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
break;
|
||||
case 's':
|
||||
canMove = field.move(Direction::down);
|
||||
field.move(Direction::down);
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
break;
|
||||
case 'a':
|
||||
canMove = field.move(Direction::left);
|
||||
field.move(Direction::left);
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
break;
|
||||
case 'd':
|
||||
canMove = field.move(Direction::right);
|
||||
field.move(Direction::right);
|
||||
field.spawnTile(field.getEmptyTiles());
|
||||
break;
|
||||
default:
|
||||
|
||||
+10
-7
@@ -39,7 +39,7 @@ Field::Field(size_t fieldSize) : mt(std::random_device{}()), FieldSize(fieldSize
|
||||
|
||||
void Field::updateScore() {
|
||||
for (size_t i = 0; i < this->FieldSize; ++i) {
|
||||
this->score += this->field[i].score;
|
||||
this->score = this->field[i].score;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,18 +47,21 @@ Score Field::getScore() {
|
||||
return this->score;
|
||||
}
|
||||
|
||||
bool Field::canMove() const {
|
||||
bool Field::hasMoves() const {
|
||||
if (!this->getEmptyTiles().empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int x = 0; x < this->field.size(); ++x) {
|
||||
for (int y = 0; y < this->field.size(); ++y) {
|
||||
// TODO: implement
|
||||
// if (x + 1 < )
|
||||
for (size_t x = 0; x < this->field.size(); ++x) {
|
||||
for (size_t y = 0; y < this->field.size(); ++y) {
|
||||
if (this->field[x][y] == this->field[x + 1][y] ||
|
||||
this->field[x][y] == this->field[x][y + 1] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Field::move(Direction direction) {
|
||||
auto oldField = this->field;
|
||||
@@ -132,7 +135,7 @@ bool Field::spawnTile(const std::vector<Position> &empty) {
|
||||
void Field::debug() const {
|
||||
for (size_t i = 0; i < this->FieldSize; ++i) {
|
||||
for (size_t j = 0; j < this->FieldSize; ++j) {
|
||||
printf("%5llu ", this->field[i][j]);
|
||||
printf("%3llu ", this->field[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,14 +1,8 @@
|
||||
#include "line.h"
|
||||
|
||||
Line::Line() {
|
||||
this->line.clear();
|
||||
this->line.resize(0);
|
||||
}
|
||||
Line::Line() = default;
|
||||
|
||||
Line::Line(size_t length) {
|
||||
this->line.clear();
|
||||
this->line.resize(length);
|
||||
}
|
||||
Line::Line(size_t length) : line(length) {}
|
||||
|
||||
void Line::process() {
|
||||
std::vector<Tile> result;
|
||||
|
||||
Reference in New Issue
Block a user