# 前言

Input：判断是否进行游戏

num1,num2,

a1,a2：累计掷出骰子数所对应棋盘上的位置

fund=2000,fund2=2000：初始资金

c：判断游戏是否终止

b1 = b2=：掷出的总数

i=1：判断A/B进行游戏

# 二、设计思路

## 四:程序代码

play.c

``````#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int num1,num2, a1,a2, fund=2000,fund2=2000,c, b1 = 0,b2=0,i=1;

int play(int row , int col)
{

printf("玩家A与B的初始资金均2000元n");
do
{
printf("****************************n");
printf("*********  1.continue  *****n");
printf("*********  0.end  **********n");
printf("****************************n");
scanf("%d", &c);//是否继续游戏
if (c == 0)
break;//判断游戏是否终止
if (i % 2 == 1)//判断玩家A/B进行
{
printf("玩家A的回合n");
srand((int)time(NULL));//用于设置rand()产生随机数时的种子,time(NULL)变化的种子
num1 = rand() % 6 + 1;//生成随机数
printf("掷出结果为%dn", num1);
b1 += num1;

a1 = b1 % (((row+col))*2+4);//在地图上所走位置
i++;
switch (a1)//判断其走的步数所对应效果
{
case 6:
printf("倒退三步n");
a1 -= 3;
b1 -= 3;
break;
case 2:
printf("银行利率增长n");
fund *= 2;
printf("剩余资金为%dn", fund);
break;
case 5:
printf("科创获奖得500元n");
fund += 500;
printf("剩余资金为%dn", fund);
break;
case 7:
printf("被电信诈骗700元n");
fund -= 700;
printf("剩余资金为%dn", fund);
break;
case 9:
printf("投资基金增长n");
fund *= 5;
printf("剩余资金为%dn", fund);
break;
case 8:
printf("前进四步n");
a1 += 4;
b1 += 4;
case 12:
printf("奖学金得1000元n");
fund += 1000;
printf("剩余资金为%dn", fund);
break;
case 11:
printf("股票暴跌n");
fund /= 4;
printf("剩余资金为%dn", fund);
break;
case 15:
printf("投资被骗n");
fund /= 2;
printf("剩余资金为%dn", fund);
break;
default:
printf("剩余资金为%dn", fund);
break;

}
if (fund > 20000 &&fund<50000)
printf("累计达成成就初出茅庐n");
else if (fund > 50000&&fund<70000 )
printf("累计达成成就初出茅庐 小有成就n");
else if (fund > 70000&&fund<100000 )
printf("累计达成成就初出茅庐 小有成就 资金充裕n");
else if (fund > 100000 )
printf("累计达成成就初出茅庐 小有成就 资金充裕 资金高手n");
//判断获得的成就
}
else
{
printf("玩家B的回合n");
srand((int)time(NULL));
num2 = rand() % 6 + 1;
printf("掷出结果为%dn", num2);
b2 += num2;

a2 = b2 % (((row + col)) * 2 + 4);
i++;
switch (a2)
{
case 6:
printf("倒退三步n");
a2 -= 3;
b2 -= 3;
break;
case 2:
printf("银行利率增长n");
fund2 *= 2;
printf("剩余资金为%dn", fund2);
break;
case 5:
printf("科创获奖得500元n");
fund2 += 500;
printf("剩余资金为%dn", fund2);
break;
case 7:
printf("被电信诈骗700元n");
fund2 -= 700;
printf("剩余资金为%dn", fund2);
break;
case 9:
printf("投资基金增长n");
fund2 *= 5;
printf("剩余资金为%dn", fund2);
break;
case 8:
printf("前进四步n");
a2 += 4;
b2 += 4;
case 12:
printf("奖学金得1000元n");
fund2 += 1000;
printf("剩余资金为%dn", fund2);
break;
case 11:
printf("股票暴跌n");
fund2 /= 4;
printf("剩余资金为%dn", fund2);
break;
case 15:
printf("投资被骗n");
fund2 /= 2;
printf("剩余资金为%dn", fund2);
break;
default:
printf("剩余资金为%dn", fund2);
break;

}
if (fund2 > 20000 && fund2 < 50000)
printf("累计达成成就初出茅庐n");
else if (fund2 > 50000 && fund2 < 70000)
printf("累计达成成就初出茅庐 小有成就n");
else if (fund2 > 70000 && fund2 < 100000)
printf("累计达成成就初出茅庐 小有成就 资金充裕n");
else if (fund2 > 100000)
printf("累计达成成就初出茅庐 小有成就 资金充裕 资金高手 资金高手n");
}

} while (fund > 0&&fund2 > 0);//判断是否出现破产
if (fund2 > fund)
{
printf("恭喜B胜利");
}
else
printf("恭喜A胜利");
return 0;//判断A/B胜利
}
``````

main.c

``````#include<stdio.h>
#include"game.h"
int main()
{
int input;

do
{
printf("****************************n");
printf("*********  1.play  *********n");
printf("*********  0.exit  *********n");
printf("****************************n");
printf("请选择：>");//请选择是否开始游戏
scanf("%d", &input);

switch (input)//判断用户的选择
{
case 1:
play( ROW , COL);
break;
case 0:
printf("退出游戏n");
break;
default:
printf("选择错误重新选择n");
break;
}
} while (input);
}
``````

game.h

``````#pragma once
#define ROW 7
#define COL 4//确定棋盘大小
int play(int row, int col);//调用函数
``````

THE END

)">