Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add point for shells in multiple matches #91

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions src/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ std::vector<Match> Board::match() {
std::vector<Match> matchesFound = getMatches(this->shells);

for (Match m : matchesFound) {
if (m.direction == Direction::HORIZONTAL) {
if (m.match_type == MatchType::HORIZONTAL) {
for(int x = 0; x < 3; x++) {
this->shells[m.x+x][m.y] = ShellType::NONE;
}
} else {
} else if (m.match_type == MatchType::VERTICAL) {
for(int y = 0; y < 3; y++) {
this->shells[m.x][m.y+y] = ShellType::NONE;
}
Expand All @@ -53,22 +53,49 @@ std::vector<Match> Board::match() {

std::vector<Match> Board::getMatches(std::vector<std::vector<ShellType>> shells){
std::vector<Match> matchesFound;
std::vector<Match> verticalMatches;
std::vector<Match> horizontalMatches;
std::vector<Match> bonusMatches;

for (int x = 0; x < getWidth(); x++) {
for (int y = 0; y < getHeight() - 2; y++) {
if (shellsMatch(shells, {x,y},{x,y+1},{x,y+2})) {
matchesFound.push_back({shells[x][y], x, y, Direction::VERTICAL});
verticalMatches.push_back({shells[x][y], x, y, MatchType::VERTICAL});
}
}
}
for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth() - 2; x++) {
if (shellsMatch(shells, {x,y},{x+1,y},{x+2,y})) {
matchesFound.push_back({shells[x][y], x, y, Direction::HORIZONTAL});
horizontalMatches.push_back({shells[x][y], x, y, MatchType::HORIZONTAL});
}
}
}

// Find bonus matches, aka shells that are in both a horizontal and vertical match
for (Match horizontal : horizontalMatches) {
for (Match vertical : verticalMatches) {
for (int h = 0; h < 3; h++) {
for (int v = 0; v < 3; v++) {
if (horizontal.x + h == vertical.x && horizontal.y == vertical.y + v) {
if (horizontal.type == ShellType::BUBBLE) {
continue;
}
if (horizontal.type == ShellType::URCHIN) {
continue;
}
bonusMatches.push_back({horizontal.type, horizontal.x + h, vertical.y + v, MatchType::BONUS});
}
}
}
}
}

matchesFound.reserve(verticalMatches.size() + horizontalMatches.size() + bonusMatches.size());
matchesFound.insert(matchesFound.end(), verticalMatches.begin(), verticalMatches.end());
matchesFound.insert(matchesFound.end(), horizontalMatches.begin(), horizontalMatches.end());
matchesFound.insert(matchesFound.end(), bonusMatches.begin(), bonusMatches.end());

return matchesFound;
}

Expand Down Expand Up @@ -178,15 +205,15 @@ std::vector<std::vector<ShellType>> Board::getShellsAfterSwap(std::vector<std::v

ShellType type1 = shells[p1.x][p1.y];
if (p1.y == p2.y) {
int direction = ((p2.x - p1.x) > 0) ? 1 : -1;
for (int i = p1.x + direction; i != p2.x + direction; i+=direction) {
shells[i-direction][p1.y] = shells[i][p1.y];
int match_type = ((p2.x - p1.x) > 0) ? 1 : -1;
for (int i = p1.x + match_type; i != p2.x + match_type; i+=match_type) {
shells[i-match_type][p1.y] = shells[i][p1.y];
shells[i][p1.y] = type1;
}
} else if (p1.x == p2.x) {
int direction = ((p2.y - p1.y) > 0) ? 1 : -1;
for (int i = p1.y + direction; i != p2.y + direction; i+=direction) {
shells[p1.x][i-direction] = shells[p1.x][i];
int match_type = ((p2.y - p1.y) > 0) ? 1 : -1;
for (int i = p1.y + match_type; i != p2.y + match_type; i+=match_type) {
shells[p1.x][i-match_type] = shells[p1.x][i];
shells[p2.x][i] = type1;
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/BoardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ void BoardManager::drawIntroduction(SDL_Renderer * renderer) {

bool BoardManager::isDoubleMatch(Match match) {
for(Match m : this->matches_made) {
if (m.direction != match.direction) {
if (m.direction == Direction::HORIZONTAL) {
if (m.match_type != match.match_type) {
if (m.match_type == MatchType::HORIZONTAL) {
if (m.x+1 == match.x && m.y == match.y+1) {
return true;
}
Expand Down Expand Up @@ -592,6 +592,10 @@ void BoardManager::drawMatches(SDL_Renderer * renderer) {
current_shell_size = (this->options->getShellSize()*(MATCH_STEPS-animation))/MATCH_STEPS;
}
for(int i = 0; i < 3; i++) {
// Do not draw extra shells for bonus matches
if (match.match_type == MatchType::BONUS) {
break;
}
SDL_Rect srcrect;
srcrect.x = this->options->getShellSize() * (int) match.type;
srcrect.y = 0;
Expand All @@ -604,9 +608,9 @@ void BoardManager::drawMatches(SDL_Renderer * renderer) {
dstrect.w = current_shell_size;
dstrect.h = current_shell_size;

if (match.direction == Direction::HORIZONTAL) {
if (match.match_type == MatchType::HORIZONTAL) {
dstrect.x += this->options->getShellSize()*i;
} else {
} else if (match.match_type == MatchType::VERTICAL) {
dstrect.y += this->options->getShellSize()*i;
}

Expand Down Expand Up @@ -644,9 +648,9 @@ void BoardManager::drawMatches(SDL_Renderer * renderer) {
SDL_QueryTexture(text, NULL, NULL, &rect_plus_one.w, &rect_plus_one.h);
rect_plus_one.x += this->options->getShellSize()/2 - rect_plus_one.w/2;
rect_plus_one.y += this->options->getShellSize()/2 - rect_plus_one.h/2;
if (match.direction == Direction::HORIZONTAL) {
if (match.match_type == MatchType::HORIZONTAL) {
rect_plus_one.x += this->options->getShellSize();
} else {
} else if (match.match_type == MatchType::VERTICAL) {
rect_plus_one.y += this->options->getShellSize();
}

Expand Down
7 changes: 4 additions & 3 deletions src/Shell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ struct Shell {
int y;
};

enum class Direction {
enum class MatchType {
HORIZONTAL,
VERTICAL
VERTICAL,
BONUS // Having a shell in both a vertical and horizontal match results in a bonus point
};

struct Match {
ShellType type;
int x;
int y;
Direction direction;
MatchType match_type;
};

#endif // SHELL_HPP
2 changes: 1 addition & 1 deletion src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inline constexpr float ANALOG_DEADZONE_MULTIPLIER = 0.5;

inline constexpr int DROP_TIME = 300; // in ms

inline constexpr int MATCH_TIME = 500; // in ms
inline constexpr int MATCH_TIME = 2000; // in ms
inline constexpr int MATCH_STEPS = 100;
inline constexpr float MATCH_DELAY = MATCH_TIME/MATCH_STEPS;

Expand Down
Loading