From 250b10118895f2dd0e5da31d3489523bcb494181 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 20 Jun 2023 23:31:05 +0200 Subject: [PATCH] add: victory --- game.🗿 | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/game.🗿 b/game.🗿 index feb12c0..519988d 100644 --- a/game.🗿 +++ b/game.🗿 @@ -135,9 +135,41 @@ cursor_update(cursor_x_ptr, cursor_y_ptr) [cursor_x_ptr] = ([cursor_x_ptr] + 1) % 3; } +check_victory(map, new_block_x, new_block_y) +{ + local row = 1; + loop + { + if ([map + ((new_block_x + row) % 3) * 3 + new_block_y] != [map + new_block_x * 3 + new_block_y]) + break; + if (row == 2) + return (1); + row++; + } + row = 1; + loop + { + if ([map + new_block_x * 3 + ((new_block_y + row) % 3)] != [map + new_block_x * 3 + new_block_y]) + break; + if (row == 2) + return (1); + row++; + } + row = 1; + loop + { + if ([map + ((new_block_x + row) % 3) * 3 + ((new_block_y + row) % 3)] != [map + new_block_x * 3 + new_block_y]) + break; + if (row == 2) + return (1); + row++; + } + return (0); +} + map_update(map, cursor_x, cursor_y) { - if (input_space == 0) + if (input_space == 0 | [map + cursor_x * 3 + cursor_y] != 'b') return; if (player_turn) [map + cursor_x * 3 + cursor_y] = 'x'; @@ -150,7 +182,7 @@ main() { local cursor_x, cursor_y; local map = {'b', 'b', 'b','b', 'b', 'b', 'b', 'b', 'b'}; - + cursor_x = SPAWN_X; cursor_y = SPAWN_Y; @@ -162,6 +194,11 @@ main() draw_map(map, cursor_x, cursor_y); input_update(); cursor_update(&cursor_x, &cursor_y); - map_update(map, cursor_x, cursor_y); + if (input_space) + { + map_update(map, cursor_x, cursor_y); + if (check_victory(map, cursor_x, cursor_y)) + break; + } } }