Update column.c

This commit is contained in:
Jason Bou-Samra
2024-09-10 19:24:26 +10:00
committed by GitHub
parent 7039117c40
commit ee346db118
+31 -5
View File
@@ -1,10 +1,12 @@
#include <SDL2/SDL.h>
#include <sodium.h>
#include <stdio.h>
#include <stdbool.h>
#include "events.h"
#include "render.h"
/********************
* tile colours *
* TILE COLOURS *
* empty = 0 *
* pink = 1 *
* green = 2 *
@@ -63,7 +65,7 @@ int grid [2][18][8] = {
///////////////////////////// COUNT COLUMNS ////////////////////////////////
int count_col(void) {
for (int i=0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
colcnt[i] = 0;
}
@@ -88,11 +90,15 @@ int new_column(void) {
if (colcnt[i] > 3) {totcol_avail++;} // count total available columns
}
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
avl = -1;
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
}
}
@@ -134,8 +140,28 @@ int move_horiz(void) {
return 0;
}
//////////////////////////////// MOVE VERTICALLY//////////////////////////
//////////////////////////////// MOVE VERTICALLY //////////////////////////
// move brick down one place at a time
int move_down(void) {
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;
}