c语言多人五子棋

本文介绍了如何使用C语言开发一款多人在线五子棋游戏,探讨了实现的关键技术和流程,包括网络通信、游戏逻辑和用户交互等方面。
摘要由CSDN通过智能技术生成
#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
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值