add: victory

This commit is contained in:
starnakin 2023-06-20 23:31:05 +02:00
parent 950e932a3a
commit 250b101188

View File

@ -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';
@ -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;
}
}
}