From bc2aa4ac9dd0deeea1b2db2cc1ae9b0e38e08690 Mon Sep 17 00:00:00 2001 From: "3190104610@zju.edu.cn" <3190104610@zju.edu.cn> Date: Tue, 19 Oct 2021 13:12:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9=E6=88=98=E5=89=8D?= =?UTF-8?q?=E9=BB=91=E8=89=B2=E6=96=B9=E7=A1=AE=E8=AE=A4=E7=99=BD=E8=89=B2?= =?UTF-8?q?=E6=96=B9=E6=98=AF=E5=90=A6=E5=B7=B2=E8=BF=9B=E5=85=A5=E6=B8=B8?= =?UTF-8?q?=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- User/APP_Gobang/APP_Gobang.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/User/APP_Gobang/APP_Gobang.c b/User/APP_Gobang/APP_Gobang.c index 9b6b00c..8c49d69 100644 --- a/User/APP_Gobang/APP_Gobang.c +++ b/User/APP_Gobang/APP_Gobang.c @@ -41,6 +41,7 @@ #define REQUEST_MSG 'R' #define AGREE_MSG 'A' #define REFUSE_MSG 'N' +#define CONFIRM_MSG 'X' #define START_BYTE '#' #define END_BYTE '&' @@ -95,6 +96,7 @@ uint8_t APP_Gobang_InitiateConnet(void); uint8_t APP_Gobang_ReplyConnect(void); void APP_Gobang_DecideMyTurn(void); void APP_Gobang_RevMyTurn(void); +void APP_Gobang_ConfirmBeforeStart(void); void APP_Gobang_ConnectRevHandler(uint8_t byte); /*****************************************************************************************/ @@ -454,6 +456,7 @@ uint8_t APP_Gobang_Connect(void) GE_GUI_MsgBox(60, 75, 200, 90, head, "按“OK”开始游戏", NULL); Delay_ms(500); KEY_WaitKey(JOY_OK); + APP_Gobang_ConfirmBeforeStart(); return 1; } else @@ -478,8 +481,9 @@ uint8_t APP_Gobang_Connect(void) uint8_t *head = (my_turn == BLACK_TURN ? "本局我方执黑" : "本局我方执白"); GE_Draw_Fill(60, 75, 200, 90, WHITE); GE_GUI_MsgBox(60, 75, 200, 90, head, "按“OK”开始游戏", NULL); - Delay_ms(200); + Delay_ms(500); KEY_WaitKey(JOY_OK); + APP_Gobang_ConfirmBeforeStart(); return 1; } else @@ -515,11 +519,10 @@ uint8_t APP_Gobang_InitiateConnet(void) if (connetion_msg == AGREE_MSG) { - //APP_Gobang_RevMyTurn(); GE_Draw_Fill(60, 75, 200, 90, WHITE); GE_GUI_MsgBox(60, 75, 200, 90, "联机成功", "按“OK”进入游戏", NULL); + //connetion_msg = NONE_MSG; KEY_WaitKey(JOY_OK); - connetion_msg = NONE_MSG; return 1; } @@ -579,6 +582,28 @@ void APP_Gobang_DecideMyTurn(void) HC12_SendBuff(msg, 2); } +void APP_Gobang_ConfirmBeforeStart(void) +{ + if (my_turn == BLACK_TURN) + { + GE_Draw_Fill(60, 75, 200, 90, WHITE); + GE_GUI_MsgBox(60, 75, 200, 90, "游戏即将开始", "正在确认白色方设备状态...", NULL); + while (connetion_msg != CONFIRM_MSG) + { + Delay_ms(100); + } + GE_Draw_Fill(60, 75, 200, 90, WHITE); + GE_GUI_MsgBox(60, 75, 200, 90, "准备就绪", "按“OK”开始游戏", NULL); + Delay_ms(500); + KEY_WaitKey(JOY_OK); + } + else + { + uint8_t msg[] = {START_BYTE, CONFIRM_MSG}; + HC12_SendBuff(msg, 2); + } +} + void APP_Gobang_ConnectRevHandler(uint8_t byte) { static uint8_t is_receiving = FALSE; @@ -591,7 +616,7 @@ void APP_Gobang_ConnectRevHandler(uint8_t byte) if (is_receiving == TRUE) { - if (byte == REQUEST_MSG || byte == AGREE_MSG || byte == REFUSE_MSG) + if (byte == REQUEST_MSG || byte == AGREE_MSG || byte == REFUSE_MSG || byte == CONFIRM_MSG) { connetion_msg = byte; is_receiving = FALSE;