Update column.c
This commit is contained in:
+29
-3
@@ -1,10 +1,12 @@
|
|||||||
|
#include <SDL2/SDL.h>
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
#include "render.h"
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
* tile colours *
|
* TILE COLOURS *
|
||||||
* empty = 0 *
|
* empty = 0 *
|
||||||
* pink = 1 *
|
* pink = 1 *
|
||||||
* green = 2 *
|
* green = 2 *
|
||||||
@@ -88,11 +90,15 @@ int new_column(void) {
|
|||||||
if (colcnt[i] > 3) {totcol_avail++;} // count total available columns
|
if (colcnt[i] > 3) {totcol_avail++;} // count total available columns
|
||||||
}
|
}
|
||||||
if (totcol_avail == 0) {
|
if (totcol_avail == 0) {
|
||||||
printf("game over\n"); restart=true;} else { // no more columns available
|
printf("game over\n");
|
||||||
|
restart = true;
|
||||||
|
} else { // no more columns available
|
||||||
randc = randombytes_uniform(totcol_avail) + 0; // choose random number from available columns
|
randc = randombytes_uniform(totcol_avail) + 0; // choose random number from available columns
|
||||||
avl = -1;
|
avl = -1;
|
||||||
for (int i = 0; randc != avl; i++) { // translate random num from avail column to actual column
|
for (int i = 0; randc != avl; i++) { // translate random num from avail column to actual column
|
||||||
if (colcnt[i] > 3) {avl++;}
|
if (colcnt[i] > 3) {
|
||||||
|
avl++;
|
||||||
|
}
|
||||||
actual_col = i; // might need to move this down to next brace
|
actual_col = i; // might need to move this down to next brace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,3 +145,23 @@ return 0;
|
|||||||
int move_down(void) {
|
int move_down(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////// RESET GAME VARS ///////////////////////
|
||||||
|
int reset(void) {
|
||||||
|
// clear grid
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
for (int k = 0; k < 18; k++) {
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
grid[i][k][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// reset column count
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
colcnt[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset row/column
|
||||||
|
row = col = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user