#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
c语言多人五子棋
最新推荐文章于 2024-06-22 23:38:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)