summaryrefslogtreecommitdiff
path: root/sirtet.c
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-06-06 12:23:34 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-06-06 12:23:34 +0800
commit5c43e5da6e3768b9c734fbd6a4a4b824f953d842 (patch)
treece376b58a949f6ec6106499a92b7cc7f6218c3f9 /sirtet.c
parentd7ac8dcb88a5cd93f505f1f00b1daec8ac6cceaf (diff)
Implement combo
Diffstat (limited to 'sirtet.c')
-rw-r--r--sirtet.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/sirtet.c b/sirtet.c
index 3332aeb..79685ae 100644
--- a/sirtet.c
+++ b/sirtet.c
@@ -15,7 +15,12 @@ void clearmap(char* map, int mapH, int mapW) {
}
}
-int clearfull(char* map, int mapH, int mapW) {
+struct clearfull_data {
+ int rows;
+ int cols;
+};
+
+struct clearfull_data clearfull(char* map, int mapH, int mapW) {
// if a row or column is full, clear it
// if a row and a column are full at the same time, clear both
// which is why we need to scan all rows/columns before actually clearing them
@@ -61,7 +66,7 @@ int clearfull(char* map, int mapH, int mapW) {
}
free(rows_to_clear);
free(cols_to_clear);
- return (rtc_count * mapW + ctc_count * mapH - rtc_count * ctc_count);
+ return (struct clearfull_data) {rtc_count, ctc_count};
}
void sirtet(int H, int W, int P) {
@@ -80,6 +85,8 @@ void sirtet(int H, int W, int P) {
bool over = false;
int points = 0;
+ int combo = 0;
+ int max_combo = 0;
// initialize ncurses
setlocale(LC_ALL, "");
@@ -98,10 +105,13 @@ void sirtet(int H, int W, int P) {
clear();
printrect(0, 0, H, W);
printmap(map, 1, 1, H, W);
- printhelp(3, 2 * W + 8);
+ printhelp(4, 2 * W + 8);
// display game stats
mvprintw(1, 2 * W + 8, "Points: %d", points);
+ if (combo)
+ mvprintw(2, 2 * W + 8, "Combo: %d", combo);
+
refresh();
// select piece and position
@@ -200,8 +210,15 @@ void sirtet(int H, int W, int P) {
hand[pc_idx] = NULL;
// clear full rows and columns
- int blocks_cleared = clearfull(map, H, W);
- points += blocks_cleared;
+ struct clearfull_data cleared = clearfull(map, H, W);
+ points += cleared.rows * W + cleared.cols * H - cleared.rows * cleared.cols;
+ if (cleared.rows || cleared.cols) {
+ combo += cleared.rows + cleared.cols;
+ if (combo > max_combo)
+ max_combo = combo;
+ } else {
+ combo = 0;
+ }
// if player has no piece left, refill
bool pieces_left = false;
@@ -230,8 +247,8 @@ void sirtet(int H, int W, int P) {
if (!has_placeable) {
// game over
printmap(map, 1, 1, H, W);
- mvprintw(7, 2 * W + 8, "Game over");
- mvprintw(8, 2 * W + 8, "Press any key to exit");
+ mvprintw(8, 2 * W + 8, "Game over");
+ mvprintw(9, 2 * W + 8, "Press any key to exit");
refresh();
while (getch() == 0);
over = true;
@@ -252,6 +269,7 @@ void sirtet(int H, int W, int P) {
// print game stats
printf("SIRTET\n");
printf("You scored %d points\n", points);
+ printf("Max combo: %d\n", max_combo);
}
int main(int argc, char *argv[]) {