C语言五子棋游戏源代码

#include

#define N 10 void welcome(); void initqipan(); void showqi(int i); void save(int p); void panduan(int p); void heqi(); void over(); int zouqihang(); int zouqilie();

/******************结构体*****************/ struct zuobiao {

int x[N*N]; int y[N*N]; }weizhi[N*N];

/******************主函数*****************/ void main() {

int p=0; welcome(); initqipan();

for(p=1;p<=N*N;p++) {

weizhi[p].x[p]=zouqihang(); weizhi[p].y[p]=zouqilie(); save(p); showqi(p); panduan(p); }

if(p==N*N) heqi(); over(); }

/******************建立棋盘*****************/ void initqipan() {

int i,j;

for(i=0;i

printf(\ printf(\ }

printf(\ for(i=1;i

for(j=0;j

if(j==0)

printf(\ else

printf(\\ }

printf(\ } }

/******************显示棋子*****************/ void showqi(int p) {

int i,j,k,m;

int a[N*N],b[N*N]; FILE *fp;

fp=fopen(\ for(i=1;i<=N*N;i++) {

fread(&weizhi[i],sizeof(struct zuobiao),1,fp); a[i]=weizhi[i].x[i]; b[i]=weizhi[i].y[i]; }

for(m=1;m

while(weizhi[p].x[p]==a[m]&&weizhi[p].y[p]==b[m]) {

printf(\

weizhi[p].x[p]=zouqihang(); weizhi[p].y[p]=zouqilie(); m=1; } }

for(i=0;i

printf(\ printf(\ }

printf(\ for(i=1;i

for(j=1;j

if(j==1)

printf(\ for(k=1;k<=p;k++) {

if(i==weizhi[k].x[k]&&j==weizhi[k].y[k]) {

if(k%2==1)

{printf(\○\ else if(k%2==0) {printf(\●\ } }

if(k>p)printf(\\ else continue; }

printf(\ } }

/******************走棋行*****************/ int zouqihang() {

int x;

printf(\请输入要走棋子所在行数!\\n\ printf(\ scanf(\ while(x>N-1||x<1) {

printf(\

printf(\请输入要走棋子所在行数!\\n\ printf(\ scanf(\ }

return x; }

/******************走棋列*****************/ int zouqilie() {

int y;

printf(\请输入要走棋子所在列数!\\n\ printf(\ scanf(\ while(y>N-1||y<1) {

printf(\

printf(\请输入要走棋子所在列数!\\n\ printf(\ scanf(\ }

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4