summaryrefslogtreecommitdiffstats
path: root/mbbsd/chc_play.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
commit1603deaec5d0a94c9a8201b0ba286e8e492a3602 (patch)
treee6405cfd39f8ac166ab7d00752ed6cfa3ac0a928 /mbbsd/chc_play.c
parent10bda3e57cad194ac33ccdcd01aee2d935f1544a (diff)
downloadpttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.gz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.bz2
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.lz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.xz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.zst
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.zip
indent
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@415 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/chc_play.c')
-rw-r--r--mbbsd/chc_play.c133
1 files changed, 72 insertions, 61 deletions
diff --git a/mbbsd/chc_play.c b/mbbsd/chc_play.c
index cffe3959..de093052 100644
--- a/mbbsd/chc_play.c
+++ b/mbbsd/chc_play.c
@@ -1,8 +1,8 @@
-/* $Id: chc_play.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */
+/* $Id: chc_play.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */
#include "bbs.h"
-typedef int (*play_func_t)(int, board_t, board_t);
+typedef int (*play_func_t) (int, board_t, board_t);
-static int chc_ipass = 0, chc_hepass = 0;
+static int chc_ipass = 0, chc_hepass = 0;
#define CHC_TIMEOUT 300
#define SIDE_ROW 10
@@ -13,14 +13,16 @@ static int chc_ipass = 0, chc_hepass = 0;
#define MYWIN_ROW 17
#define HISWIN_ROW 18
-static int hisplay(int s, board_t board, board_t tmpbrd) {
- int start_time;
- int endgame = 0, endturn = 0;
-
+static int
+hisplay(int s, board_t board, board_t tmpbrd)
+{
+ int start_time;
+ int endgame = 0, endturn = 0;
+
start_time = now;
- while(!endturn) {
+ while (!endturn) {
chc_lefttime = CHC_TIMEOUT - (now - start_time);
- if(chc_lefttime < 0) {
+ if (chc_lefttime < 0) {
chc_lefttime = 0;
/* to make him break out igetkey() */
@@ -30,13 +32,13 @@ static int hisplay(int s, board_t board, board_t tmpbrd) {
chc_drawline(board, TIME_ROW);
move(1, 0);
oflush();
- switch(igetkey()) {
+ switch (igetkey()) {
case 'q':
endgame = 2;
endturn = 1;
break;
case 'p':
- if(chc_hepass) {
+ if (chc_hepass) {
chc_from.r = -1;
chc_sendmove(s);
endgame = 3;
@@ -44,11 +46,11 @@ static int hisplay(int s, board_t board, board_t tmpbrd) {
}
break;
case I_OTHERDATA:
- if(chc_recvmove(s)) { /* disconnect */
+ if (chc_recvmove(s)) { /* disconnect */
endturn = 1;
endgame = 1;
} else {
- if(chc_from.r == -1) {
+ if (chc_from.r == -1) {
chc_hepass = 1;
strcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m");
chc_drawline(board, WARN_ROW);
@@ -56,7 +58,7 @@ static int hisplay(int s, board_t board, board_t tmpbrd) {
chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c;
chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c;
chc_cursor = chc_to;
- if(CHE_P(board[chc_to.r][chc_to.c]) == 1)
+ if (CHE_P(board[chc_to.r][chc_to.c]) == 1)
endgame = 2;
endturn = 1;
chc_hepass = 0;
@@ -72,50 +74,52 @@ static int hisplay(int s, board_t board, board_t tmpbrd) {
return endgame;
}
-static int myplay(int s, board_t board, board_t tmpbrd) {
- int ch, start_time;
- int endgame = 0, endturn = 0;
-
+static int
+myplay(int s, board_t board, board_t tmpbrd)
+{
+ int ch, start_time;
+ int endgame = 0, endturn = 0;
+
chc_ipass = 0, chc_selected = 0;
start_time = now;
chc_lefttime = CHC_TIMEOUT - (now - start_time);
bell();
- while(!endturn) {
+ while (!endturn) {
chc_drawline(board, TIME_ROW);
chc_movecur(chc_cursor.r, chc_cursor.c);
oflush();
ch = igetkey();
- chc_lefttime = CHC_TIMEOUT - (now - start_time);
- if(chc_lefttime < 0)
+ chc_lefttime = CHC_TIMEOUT - (now - start_time);
+ if (chc_lefttime < 0)
ch = 'q';
- switch(ch) {
+ switch (ch) {
case I_OTHERDATA:
- if(chc_recvmove(s)) { /* disconnect */
+ if (chc_recvmove(s)) { /* disconnect */
endgame = 1;
endturn = 1;
- } else if(chc_from.r == -1 && chc_ipass) {
+ } else if (chc_from.r == -1 && chc_ipass) {
endgame = 3;
endturn = 1;
}
break;
case KEY_UP:
chc_cursor.r--;
- if(chc_cursor.r < 0)
+ if (chc_cursor.r < 0)
chc_cursor.r = BRD_ROW - 1;
break;
case KEY_DOWN:
chc_cursor.r++;
- if(chc_cursor.r >= BRD_ROW)
+ if (chc_cursor.r >= BRD_ROW)
chc_cursor.r = 0;
break;
case KEY_LEFT:
chc_cursor.c--;
- if(chc_cursor.c < 0)
+ if (chc_cursor.c < 0)
chc_cursor.c = BRD_COL - 1;
break;
case KEY_RIGHT:
chc_cursor.c++;
- if(chc_cursor.c >= BRD_COL)
+ if (chc_cursor.c >= BRD_COL)
chc_cursor.c = 0;
break;
case 'q':
@@ -133,21 +137,21 @@ static int myplay(int s, board_t board, board_t tmpbrd) {
case '\r':
case '\n':
case ' ':
- if(chc_selected) {
- if(chc_cursor.r == chc_select.r &&
- chc_cursor.c == chc_select.c) {
+ if (chc_selected) {
+ if (chc_cursor.r == chc_select.r &&
+ chc_cursor.c == chc_select.c) {
chc_selected = 0;
chc_drawline(board, LTR(chc_cursor.r));
- } else if(chc_canmove(board, chc_select, chc_cursor)) {
- if(CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1)
+ } else if (chc_canmove(board, chc_select, chc_cursor)) {
+ if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1)
endgame = 1;
chc_from = chc_select;
chc_to = chc_cursor;
- if(!endgame) {
+ if (!endgame) {
memcpy(tmpbrd, board, sizeof(board_t));
chc_movechess(tmpbrd);
}
- if(endgame || !chc_iskfk(tmpbrd)) {
+ if (endgame || !chc_iskfk(tmpbrd)) {
chc_drawline(board, STEP_ROW);
chc_movechess(board);
chc_sendmove(s);
@@ -161,8 +165,8 @@ static int myplay(int s, board_t board, board_t tmpbrd) {
chc_drawline(board, WARN_ROW);
}
}
- } else if(board[chc_cursor.r][chc_cursor.c] &&
- CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) {
+ } else if (board[chc_cursor.r][chc_cursor.c] &&
+ CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) {
chc_selected = 1;
chc_select = chc_cursor;
chc_drawline(board, LTR(chc_cursor.r));
@@ -173,29 +177,31 @@ static int myplay(int s, board_t board, board_t tmpbrd) {
return endgame;
}
-static void mainloop(int s, board_t board) {
- int endgame;
- board_t tmpbrd;
- play_func_t play_func[2];
-
+static void
+mainloop(int s, board_t board)
+{
+ int endgame;
+ board_t tmpbrd;
+ play_func_t play_func[2];
+
play_func[chc_my] = myplay;
play_func[chc_my ^ 1] = hisplay;
- for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) {
+ for (chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) {
chc_firststep = 0;
chc_drawline(board, TURN_ROW);
- if(chc_ischeck(board, chc_turn)) {
+ if (chc_ischeck(board, chc_turn)) {
strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m");
bell();
} else
chc_warnmsg[0] = 0;
chc_drawline(board, WARN_ROW);
- endgame = play_func[chc_turn](s, board, tmpbrd);
+ endgame = play_func[chc_turn] (s, board, tmpbrd);
}
-
- if(endgame == 1) {
+
+ if (endgame == 1) {
strcpy(chc_warnmsg, "對方認輸了!");
cuser.chc_win++;
- } else if(endgame == 2) {
+ } else if (endgame == 2) {
strcpy(chc_warnmsg, "你認輸了!");
cuser.chc_lose++;
} else {
@@ -209,8 +215,10 @@ static void mainloop(int s, board_t board) {
oflush();
}
-static void chc_init(int s, board_t board) {
- userinfo_t *my = currutmp;
+static void
+chc_init(int s, board_t board)
+{
+ userinfo_t *my = currutmp;
setutmpmode(CHC);
clear();
@@ -222,34 +230,37 @@ static void chc_init(int s, board_t board) {
chc_redraw(board);
chc_cursor.r = 9, chc_cursor.c = 0;
add_io(s, 0);
-
- if(my->turn) chc_recvmove(s);
+
+ if (my->turn)
+ chc_recvmove(s);
passwd_query(usernum, &xuser);
cuser.chc_win = xuser.chc_win;
cuser.chc_lose = xuser.chc_lose + 1;
cuser.chc_tie = xuser.chc_tie;
- cuser.money = xuser.money;
+ cuser.money = xuser.money;
passwd_update(usernum, &cuser);
-
+
getuser(chc_mateid);
chc_hiswin = xuser.chc_win;
chc_hislose = xuser.chc_lose;
chc_histie = xuser.chc_tie;
-
- if(!my->turn) {
+
+ if (!my->turn) {
chc_sendmove(s);
chc_hislose++;
}
-
chc_redraw(board);
}
-void chc(int s) {
- board_t board;
-
+void
+chc(int s)
+{
+ board_t board;
+
chc_init(s, board);
mainloop(s, board);
close(s);
add_io(0, 0);
- if(chc_my) pressanykey();
+ if (chc_my)
+ pressanykey();
}