summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2022-05-29 16:30:44 +0000
committerrillig <rillig@NetBSD.org>2022-05-29 16:30:44 +0000
commit19d385338f7a592bf672dafe654fc06a6d687aff (patch)
treeef97060f47d60945609dd6199bd1f5ac34405461 /games
parent741ac63d1bcbb8332f8f119c603e5745b4a32a85 (diff)
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.
Diffstat (limited to 'games')
-rw-r--r--games/gomoku/bdinit.c6
-rw-r--r--games/gomoku/bdisp.c9
-rw-r--r--games/gomoku/gomoku.h4
3 files changed, 12 insertions, 7 deletions
diff --git a/games/gomoku/bdinit.c b/games/gomoku/bdinit.c
index be1681ace00..3d4d7d3a43b 100644
--- a/games/gomoku/bdinit.c
+++ b/games/gomoku/bdinit.c
@@ -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++) {
diff --git a/games/gomoku/bdisp.c b/games/gomoku/bdisp.c
index 27550e2222b..a9a8bae14a1 100644
--- a/games/gomoku/bdisp.c
+++ b/games/gomoku/bdisp.c
@@ -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);
}
diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h
index 799b874fe69..c96ffc5edf1 100644
--- a/games/gomoku/gomoku.h
+++ b/games/gomoku/gomoku.h
@@ -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[];