-
Notifications
You must be signed in to change notification settings - Fork 324
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
Change tile width dynamically to allow longer strings #56
Changes from 1 commit
8bfeb67
78afb8e
e39ea6d
ea4d5d5
c4da264
1cd01f0
4d9b5c2
b47a4bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
|
||
|
||
Mihir 1596 0 170 128 17.8156 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
1596 | ||
2 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
323 | ||
43.6693 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ enum { CODE_HOTKEY_ACTION_SAVE = 'Z', CODE_HOTKEY_ALTERNATE_ACTION_SAVE = 'P' }; | |
|
||
} // namespace Code | ||
} // namespace Keypress | ||
|
||
enum { CELL_BORDER_PADDING = 1, MINIMUM_CELL_WIDTH = 4 }; | ||
|
||
} // namespace | ||
|
||
Color::Modifier Tile::tileColor(ull value) { | ||
|
@@ -166,21 +169,10 @@ void Game::collectFreeTiles(std::vector<std::vector<int>> &freeTiles) { | |
|
||
void Game::drawBoard() { | ||
|
||
// The number of spaces between the border of a cell and a number | ||
enum { CELL_BORDER = 1 }; | ||
|
||
clearScreen(); | ||
drawAscii(); | ||
drawScoreBoard(std::cout); | ||
|
||
int numlen = std::to_string(largestTile).length(); | ||
|
||
std::string border; | ||
// Multiple cell border enum by 2 so it applies the same padding | ||
// to both sides | ||
for(int i = 0; i < numlen+( CELL_BORDER * 2); i++){ | ||
border.append("─"); | ||
} | ||
for (int y = 0; y < gameBoardPlaySize; y++) { | ||
|
||
std::cout << " "; | ||
|
@@ -191,7 +183,7 @@ void Game::drawBoard() { | |
std::cout << "├"; | ||
} | ||
for (int i = 0; i < gameBoardPlaySize; i++) { | ||
std::cout << border; | ||
std::cout << horizontalBorder; | ||
if (i < gameBoardPlaySize - 1) { | ||
if (y == 0) { | ||
std::cout << "┬"; | ||
|
@@ -214,10 +206,10 @@ void Game::drawBoard() { | |
|
||
std::cout << " │ "; | ||
if (!currentTile.value) { | ||
std::cout << std::setw(numlen) << " "; | ||
std::cout << std::setw(cellWidth) << " "; | ||
} else { | ||
std::cout << currentTile.tileColor(currentTile.value) << bold_on | ||
<< std::setw(numlen) << currentTile.value << bold_off << def; | ||
<< std::setw(cellWidth) << currentTile.value << bold_off << def; | ||
} | ||
} | ||
|
||
|
@@ -228,7 +220,7 @@ void Game::drawBoard() { | |
std::cout << " └"; | ||
|
||
for (int i = 0; i < gameBoardPlaySize; i++) { | ||
std::cout << border; | ||
std::cout << horizontalBorder; | ||
if (i < gameBoardPlaySize - 1) { | ||
std::cout << "┴"; | ||
} else { | ||
|
@@ -508,8 +500,20 @@ void Game::move(int y, int x, int k, int l) { | |
score += targetTile.value; | ||
targetTile.blocked = true; | ||
|
||
largestTile = | ||
largestTile < targetTile.value ? targetTile.value : largestTile; | ||
if (largestTile < targetTile.value) { | ||
largestTile = targetTile.value; | ||
|
||
/** | ||
* Default border length is 4. When largestTileLength exceeds 4 | ||
* then increase the border and cell width by 1 | ||
*/ | ||
int largestTileLength = std::to_string(largestTile).length(); | ||
if (cellWidth > MINIMUM_CELL_WIDTH) { | ||
cellWidth = largestTileLength; | ||
horizontalBorder.append("─"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With an anonymous-namespace free function, you can take in a parameter |
||
} | ||
} | ||
|
||
if (!win) { | ||
if (targetTile.value == GAME_TILE_WINNING_SCORE) { | ||
win = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ class Game { | |
ull score; | ||
ull bestScore; | ||
ull largestTile; | ||
int cellWidth; | ||
std::string horizontalBorder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better practice would be:
|
||
long long moveCount; | ||
double duration; | ||
ull gameBoardPlaySize; | ||
|
@@ -89,8 +91,8 @@ class Game { | |
public: | ||
Game() | ||
: win(false), moved(true), boardFull(false), rexit(false), score(0), | ||
bestScore(0), moveCount(-2), largestTile(2), stateSaved(false), | ||
noSave(false) {} | ||
bestScore(0), moveCount(-2), largestTile(2), cellWidth(4), | ||
horizontalBorder("──────"), stateSaved(false), noSave(false) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means one would not need the |
||
void startGame(); | ||
void continueGame(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everytime you want to draw the
[horizontalBorder string]
, you would just call the function.