有关五子棋程序编写的求解

问题遇到的现象和发生背景

编写五子棋程序

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

我希望在每一步棋后加一个倒计时程序,使得如果在上一步棋下完一定时间内没有下一步棋,程序会进行提示,然后待用户输入后,继续棋局,如果在上一步棋下完的一定时间内完成了下一步棋,则程序不会提示,直接继续进行

http://t.csdn.cn/F1QDz
看我博客


#define ROW 20 //显示行数
#define COL 20 //显示列数
#define ROWS ROW+8 //存储行数
#define COLS COL+8 //存储列数
#define DE 4 //相差的值
//这里我指使用了一个数组,也可以用两个数组实现
 
#include<stdio.h>
#include<Windows.h>
#include<time.h>
#include<string.h>
#include<stdbool.h>
 
void Initboard(char board[ROWS][COLS], int row, int col); //初始化棋盘
void Displayboard(char board[ROWS][COLS], int row, int col); //打印显示棋盘
int Playermove(char board[ROWS][COLS],char sb); //玩家下棋移动
int computermove(char board[ROWS][COLS],char sb); //电脑下棋移动
int Getresult(char board[ROWS][COLS], int x, int y, char sb); //判断输赢
bool Isfull(char board[ROWS][COLS]); //判断棋盘十否已满
 
//
//
//
 
void menu()
{
    printf("*******************************************\n");
    printf("*************     五子棋      *************\n");
    printf("************* 1.Play   0.exit *************\n");
    printf("*******************************************\n");
}
void game()
{
    int ret;
    char choice;
    char board[ROWS][COLS] = {0};
a:    Initboard(board, ROWS, COLS);
    Displayboard(board, ROW, COL);
    while (1)
    {
        ret=Playermove(board,'*'); //‘*’代表玩家的棋
        Displayboard(board, ROW, COL);
        if (ret == 1)//这里加了一个是否继续游戏的判断,写的不好
        {
            system("cls");
            printf("是否继续游戏>; Y/N\n");
            scanf("%c", &choice);
            getchar();
            if (choice == 'Y')
                goto a;
            else
                exit(0);
        }
        system("cls");
        ret=computermove(board,'#');//‘#’代表电脑的棋
        Displayboard(board, ROW, COL);
        if (ret == 1)
        {
            system("cls");
            printf("是否继续游戏>; Y/N\n");
            getchar();
            scanf("%c", &choice);
            if (choice == 'Y')
                goto a;
            else
                break;
            goto a;
        }
    }
}
void start()
{
    menu();
    int choice;
    do {
        printf("请选择:> \n");
        scanf("%d", &choice);
        switch (choice)
        {
        case 1:
            game();
            break;
        case 0:
            printf("退出游戏\n");
            break;
        default:
            printf("选择有误,请重新选择:> \n");
            break;
        }
    } while (choice);
}
int main()
{
    srand((unsigned int) time(NULL));
    start();
    return 0;
}
 
void Initboard(char board[ROWS][COLS], int row, int col)
{
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
            board[i][j] =' ';
    }
}
void Displayboard(char board[ROWS][COLS], int row, int col)
{
    for (int i = DE; i <=row+DE; i++)
    {
        for (int j = DE; j <col+DE; j++)
            printf(" —");
        printf("\n");
        if (i == row+DE)
            return;
        for (int j = DE; j < col+DE; j++)
            printf("| %c", board[i][j]);
        printf("|");
        printf("\n");
    }
}
int Playermove(char board[ROWS][COLS],char sb)
{
    int x, y;
    while (1)
    {
        printf("请输入坐标位置>; \n");
         scanf("%d %d", &x, &y);
        if (x > ROW || x<0 || y>ROW || y < 0)
        {
            printf("坐标位置非法,请重新输入:> \n");
            continue;
        }
        else if (board[x+DE-1][y+DE-1]=='*'||board[x + DE-1][y + DE-1] == '#')
        {
            printf("该位置已被占用,请重新选择>: \n");
            continue;
        }
        else
        {
            board[x+DE-1][y+DE-1] = sb;
            int judge = Getresult(board, x+ DE-1, y+ DE-1, sb);
            if (judge == 1)
            {
                system("cls");
                Displayboard(board, ROW, COL);
                printf("你赢了\n");
                Sleep(2000);
            }
            else if (Isfull(board))
            {
                system("cls");
                Displayboard(board, ROW, COL);
                printf("平局\n");
                Sleep(2000);
            }
            else
                return 0;
            break;
        }
    }
    return 1;
}
int computermove(char board[ROWS][COLS],char sb)
{
    while (1)
    {
        int x = rand() % ROW;
        int y = rand() % COL;
        if (board[x+DE][y+DE] != ' ')
            continue;
        else
        {
            board[x+DE][y+DE] = sb;
            int judge = Getresult(board, x + DE, y + DE, sb);
            if (judge == 1)
            {
                system("cls");
                Displayboard(board, ROW, COL);
                printf("你赢了\n");
                Sleep(2000);
            }
            else if (Isfull(board))
            {
                system("cls");
                Displayboard(board, ROW, COL);
                printf("平局\n");
                Sleep(2000);
            }
            else
                return 0;
            break;
        }
    }
    return 1;
}
bool Isfull(char board[ROWS][COLS])
{
    for (int i = DE; i < ROW + DE; i++)
    {
        for (int j = DE; j < ROW + DE; j++)
            if (board[i][j] == ' ')
                return false;
    }
    return true;
}
 
//用字符代表黑白子,判断输赢
//存储当前行,列及两对角线上的棋对应的字符
//这里统一用一种字符判断,省得写两个对照字符串
int Getresult(char board[ROWS][COLS], int x, int y,char sb)
{
    if (Isfull(board))
        return 0;
    char key_c[10] = { 0 }; 
    char key_r[10] = { 0 };
    char key_stdl[10] = { 0 };
    char key_atdl[10] = { 0 };
    char dest[] ="aaaaa";
    for (int i = -4; i <5; i++)
    {
        if (board[x+i][y] == sb)
            key_c[i + 4] = 'a';
        else
            key_c[i + 4] = 'b';
        if (board[x][y + i] == sb)
            key_r[i+4] = 'a';
        else
            key_r[i+4] = 'b';
        if (board[x + i][y + i] == sb)
            key_stdl[i+4] = 'a';
        else
            key_stdl[i+4] = 'b';
        if (board[x - i][y + i] == sb)
            key_atdl[i+4] = 'a';
        else
            key_atdl[i+4] = 'b';
    }
 if(strstr(key_c,dest)||strstr(key_r,dest)||strstr(key_stdl,dest)||strstr(key_atdl,dest))
    return 1;
 else
    return -1;
}