admin管理员组

文章数量:1621658

#include <stdio.h>
#include <conio.h>
#include <Windows.h>
#include <malloc.h>

#define up 'w'
#define down 's'
#define left 'a'
#define right 'd'
#define fall 'p'
#define exitgame 'q'
#define replay 'y'
#define nPlayer 3


struct stuPos
{
    int x;
    int y;
};

struct stuBoard
{
    stuPos pos;        //position
    int flag;          //player id, initalize is 0
};

struct stuChesBoard
{
    stuBoard **pBoard;
    int w;
    int h;
};

struct stuPlayer
{
    int id;
    char* chess;
    stuPos pos;
};


void moveCursor(int x, int y)
{
    COORD c;
    c.X = 2 * x;
    c.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}

int playerMove(stuChesBoard *pChessBoard,stuPlayer *pPlayer,int x, int y,char flag)
{
    int iPlace = 0;
    if (pChessBoard->pBoard[x][y].pos.x == x
        && pChessBoard->pBoard[x][y].pos.y == y
        )
    {
        if(fall == flag && pChessBoard->pBoard[x][y].flag == 0)
        {
            printf(pPlayer->chess);
            pChessBoard->pBoard[x][y].flag = pPlayer->id;
            iPlace = 1;
        }
        moveCursor(x,y);
        pPlayer->pos.x = x;
        pPlayer->pos.y = y;

    }
    return iPlace;
}

bool check(stuChesBoard *pChessBoard,int x, int y)
{
    stuBoard **board = pChessBoard->pBoard;
    int id = board[x][y].flag;  //get id of player
   

本文标签: 五子语言