gomoku: when starting a new game, start in the middle of the board
Previously, when starting a new game, the user coordinate was kept at the previously selected spot. Since playing in the center is common sense, reset the coordinate.
This commit is contained in:
parent
28df150fd1
commit
1f981c0ac1
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 rillig Exp $ */
|
||||
/* $NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
/* from: @(#)bdinit.c 8.2 (Berkeley) 5/3/95 */
|
||||
__RCSID("$NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 rillig Exp $");
|
||||
__RCSID("$NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $");
|
||||
|
||||
#include <string.h>
|
||||
#include "gomoku.h"
|
||||
|
@ -130,6 +130,8 @@ init_board(void)
|
|||
|
||||
game.nmoves = 0;
|
||||
game.win_spot = 0;
|
||||
game.user_x = 1 + (BSZ - 1) / 2;
|
||||
game.user_y = 1 + (BSZ - 1) / 2;
|
||||
|
||||
struct spotstr *sp = board;
|
||||
for (int i = 0; i < 1 + BSZ + 1; i++, sp++) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $ */
|
||||
/* $NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
/* @(#)bdisp.c 8.2 (Berkeley) 5/3/95 */
|
||||
__RCSID("$NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $");
|
||||
__RCSID("$NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $");
|
||||
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
|
@ -355,8 +355,7 @@ get_coord_mouse(int *x, int *y)
|
|||
int
|
||||
get_coord(void)
|
||||
{
|
||||
static int x = 1 + (BSZ - 1) / 2;
|
||||
static int y = 1 + (BSZ - 1) / 2;
|
||||
int x = game.user_x, y = game.user_y;
|
||||
|
||||
move(scr_y(y), scr_x(x));
|
||||
refresh();
|
||||
|
@ -457,6 +456,8 @@ get_coord(void)
|
|||
case '\r':
|
||||
selected:
|
||||
(void)mvhline(BSZ + 3, 6, ' ', 6);
|
||||
game.user_x = x;
|
||||
game.user_y = y;
|
||||
return PT(x, y);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: gomoku.h,v 1.53 2022/05/29 15:31:12 rillig Exp $ */
|
||||
/* $NetBSD: gomoku.h,v 1.54 2022/05/29 16:30:44 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994
|
||||
|
@ -236,6 +236,8 @@ struct game {
|
|||
spot_index moves[BSZ * BSZ]; /* log of all played moves */
|
||||
spot_index win_spot; /* the winning move, or 0 */
|
||||
direction win_dir;
|
||||
int user_x;
|
||||
int user_y;
|
||||
};
|
||||
|
||||
extern const char letters[];
|
||||
|
|
Loading…
Reference in New Issue