apply strict/pedantic C90 updates
This commit is contained in:
parent
b99df2dc62
commit
e055d9eee4
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
// Created by Gregory Gauthier on 06/10/2025.
|
* Created by Gregory Gauthier on 06/10/2025.
|
||||||
*/
|
*/
|
||||||
/* game.c - Game logic implementation */
|
/* game.c - Game logic implementation */
|
||||||
#include "../include/game.h"
|
#include "../include/game.h"
|
||||||
#include "../include/ui.h"
|
#include "../include/ui.h"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
// Created by Gregory Gauthier on 06/10/2025.
|
* Created by Gregory Gauthier on 06/10/2025.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* main.c - Entry point and main game loop */
|
/* main.c - Entry point and main game loop */
|
||||||
/* Compile with: gcc -std=c90 -o cordle src\/\*.c -Iinclude -lncurses */
|
/* Compile with: gcc -std=c90 -o cordle src\/\*.c -Iinclude -lncurses */
|
||||||
@ -53,7 +53,7 @@ void parse_arguments(int argc, char *argv[], char *filename, char *difficulty) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Main game loop */
|
/* Main game loop */
|
||||||
int main_game_loop(const int argc, char *argv[]) {
|
int main_game_loop(int argc, char *argv[]) {
|
||||||
WINDOW *stdscr;
|
WINDOW *stdscr;
|
||||||
GameState game;
|
GameState game;
|
||||||
char filename[MAX_FILENAME];
|
char filename[MAX_FILENAME];
|
||||||
|
|||||||
39
src/ui.c
39
src/ui.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
// Created by Gregory Gauthier on 06/10/2025.
|
* Created by Gregory Gauthier on 06/10/2025.
|
||||||
*/
|
*/
|
||||||
/* ui.c - User interface implementation */
|
/* ui.c - User interface implementation */
|
||||||
#include "../include/ui.h"
|
#include "../include/ui.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -15,11 +15,11 @@ static const char *keyboard_rows[3] = {
|
|||||||
/* Draw game title */
|
/* Draw game title */
|
||||||
void draw_title(WINDOW *win, int y, const char *difficulty) {
|
void draw_title(WINDOW *win, int y, const char *difficulty) {
|
||||||
char title[256];
|
char title[256];
|
||||||
int height, width, x;
|
int width, x;
|
||||||
|
|
||||||
sprintf(title, "CORDLE - The C90 Wordle Game [%s]", difficulty);
|
sprintf(title, "CORDLE - The C90 Wordle Game [%s]", difficulty);
|
||||||
|
|
||||||
getmaxyx(win, height, width);
|
width = getmaxx(win);
|
||||||
x = (width - strlen(title)) / 2;
|
x = (width - strlen(title)) / 2;
|
||||||
|
|
||||||
wattron(win, A_BOLD);
|
wattron(win, A_BOLD);
|
||||||
@ -29,11 +29,11 @@ void draw_title(WINDOW *win, int y, const char *difficulty) {
|
|||||||
|
|
||||||
/* Draw the game board */
|
/* Draw the game board */
|
||||||
void draw_board(WINDOW *win, GameState *game, int y) {
|
void draw_board(WINDOW *win, GameState *game, int y) {
|
||||||
int height, width, board_x;
|
int width, board_x;
|
||||||
int row, col, x_pos, y_pos;
|
int row, col, x_pos, y_pos;
|
||||||
char cell[4];
|
char cell[4];
|
||||||
|
|
||||||
getmaxyx(win, height, width);
|
width = getmaxx(win);
|
||||||
board_x = (width - (WORD_LENGTH * 4 - 1)) / 2;
|
board_x = (width - (WORD_LENGTH * 4 - 1)) / 2;
|
||||||
|
|
||||||
for (row = 0; row < MAX_GUESSES; row++) {
|
for (row = 0; row < MAX_GUESSES; row++) {
|
||||||
@ -75,13 +75,13 @@ void draw_board(WINDOW *win, GameState *game, int y) {
|
|||||||
|
|
||||||
/* Draw visual keyboard */
|
/* Draw visual keyboard */
|
||||||
void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
||||||
int height, width;
|
int width;
|
||||||
int row_idx, x, y_pos, i;
|
int row_idx, x, y_pos, i;
|
||||||
const char *row;
|
const char *row;
|
||||||
char letter;
|
char letter;
|
||||||
int status, color;
|
int status, color;
|
||||||
|
|
||||||
getmaxyx(win, height, width);
|
width = getmaxx(win);
|
||||||
|
|
||||||
for (row_idx = 0; row_idx < 3; row_idx++) {
|
for (row_idx = 0; row_idx < 3; row_idx++) {
|
||||||
row = keyboard_rows[row_idx];
|
row = keyboard_rows[row_idx];
|
||||||
@ -89,21 +89,28 @@ void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
|||||||
y_pos = y + row_idx;
|
y_pos = y + row_idx;
|
||||||
|
|
||||||
/* Add indentation for keyboard layout */
|
/* Add indentation for keyboard layout */
|
||||||
if (row_idx == 1) x += 1;
|
if (row_idx == 1) {
|
||||||
else if (row_idx == 2) x += 3;
|
x += 1;
|
||||||
|
} else if (row_idx == 2) {
|
||||||
|
x += 3;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; row[i]; i++) {
|
for (i = 0; row[i]; i++) {
|
||||||
letter = row[i];
|
letter = row[i];
|
||||||
status = game->letter_status[letter - 'A'];
|
status = game->letter_status[letter - 'A'];
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case STATUS_CORRECT: color = COLOR_CORRECT;
|
case STATUS_CORRECT:
|
||||||
|
color = COLOR_CORRECT;
|
||||||
break;
|
break;
|
||||||
case STATUS_PRESENT: color = COLOR_PRESENT;
|
case STATUS_PRESENT:
|
||||||
|
color = COLOR_PRESENT;
|
||||||
break;
|
break;
|
||||||
case STATUS_ABSENT: color = COLOR_ABSENT;
|
case STATUS_ABSENT:
|
||||||
|
color = COLOR_ABSENT;
|
||||||
break;
|
break;
|
||||||
default: color = COLOR_UNUSED;
|
default:
|
||||||
|
color = COLOR_UNUSED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,9 +130,9 @@ void draw_keyboard(WINDOW *win, GameState *game, int y) {
|
|||||||
|
|
||||||
/* Draw centered message */
|
/* Draw centered message */
|
||||||
void draw_message(WINDOW *win, const char *message, const int y, const int color_pair) {
|
void draw_message(WINDOW *win, const char *message, const int y, const int color_pair) {
|
||||||
int height, width, x;
|
int width, x;
|
||||||
|
|
||||||
getmaxyx(win, height, width);
|
width = getmaxx(win);
|
||||||
x = (width - strlen(message)) / 2;
|
x = (width - strlen(message)) / 2;
|
||||||
|
|
||||||
wattron(win, COLOR_PAIR(color_pair));
|
wattron(win, COLOR_PAIR(color_pair));
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
// Created by Gregory Gauthier on 06/10/2025.
|
* Created by Gregory Gauthier on 06/10/2025.
|
||||||
*/
|
*/
|
||||||
/* words.c - Word list management implementation */
|
/* words.c - Word list management implementation */
|
||||||
#include "../include/words.h"
|
#include "../include/words.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user