纸牌游戏:十点半纸牌游戏:十点半
设计报告
题目:纸牌游戏:十点半
学院:化学工程学院
专业:制药工程
班级:050607班
姓名:李艳明
指导教师:
设计日期: 2007年1月10日
一(选题背景
扑克牌是一种大众化的游戏牌,日常生活中我们为了娱乐消遣经常用之来进行一
些小游戏,如红心大战,斗地主,活龙等,多种多样。
十点半是这些游戏中一种比较简单的玩法。这个程序模仿了十点半的各个过程,
将游戏在程序运行中表示其玩法过程。
二.设计思想
(一)游戏规则:游戏可为两人或多人,但不超过八人。本游戏中选了人与电脑及
四人...
纸牌游戏:十点半
设计
题目:纸牌游戏:十点半
学院:化学工程学院
专业:制药工程
班级:050607班
姓名:李艳明
指导教师:
设计日期: 2007年1月10日
一(选题背景
扑克牌是一种大众化的游戏牌,日常生活中我们为了娱乐消遣经常用之来进行一
些小游戏,如红心大战,斗地主,活龙等,多种多样。
十点半是这些游戏中一种比较简单的玩法。这个程序模仿了十点半的各个过程,
将游戏在程序运行中表示其玩法过程。
二.设计思想
(一)游戏规则:游戏可为两人或多人,但不超过八人。本游戏中选了人与电脑及
四人间的玩法为例。第一轮玩家依次取一张牌,之后玩家根据自己牌的总点数,选择
继续要牌或不要牌,但一旦选择不要牌以后就不能再要牌。玩家牌的总点数一旦超过
10.5,不能再要牌,J,Q,K算为半点。如果玩家牌的总点数都大于或小于10.5,点大者
胜;如果有大于也有小于10.5,则点数最小者赢。
(二)任何一张纸牌都有其本身的属性:花色,数值及起其所代表的点数。为将这些
特征表示出来,特定义一个结构体数组来表示一副扑克牌,由于十点半游戏中不需要
大小王,故可以定义如下:
Struct book{
int color;
char number;
float num;
}Card[52];
(三)不论何种扑克游戏都有其必经的三个步骤:一是有一副牌(即牌的初始化)
二是洗牌,三是发牌。这三个步骤在程序中通过三个函数来实现:
void Build_Show(int HuaSe[],float DianShu[],char ShuZi[]);
void Wash_Card(void);
void Get_Card(int n);
三(流程图
for
调用函数
do循环
调用函数
终止
Main()函数流程图
Build_Show()的流程图 Wash_Card()的流程图
for for
i=0
i=0
i<4
结束 i<1000
puts() for
产生rand1,rand2 i++ for j=0 i++
i=0,j=0 j<13 Rand1!=rand2 j++
j<52 交换牌 Card[j+13*i].color=HuaSe[i]
Card[j+13*i].number=ShuZi[i] j%13==0 Card[j+13*i].num=DianShu[i]
\n
printf()
结束 Get_Card()的流程图 DuoRen()的流程图
调用函数 调用函数
if
每个人都拿第一张牌
n==1 n==4 当所有人都不能
拿牌时结束循环
人与电脑游
戏并输出游
戏结果 调用函数
Duo_Ren() 公布结果,由各
人的点数可知
调用结束
调用结束
四。程序清单
#define N 5
#include
#include
struct book{
int color;
char number;
float num;
} Card[52]; /*To store the color,number and the points*/
void Build_Show(int HuaSe[], float DianShu[], char ShuZi[]);
/*Establish a pair of cards and show it to the player*/ void Wash_Card(void); /*Wash the cards*/
void Get_Card(int n) ; /*Give the player cards and the result*/ void DuoRen();
int main(void)
{
int flag, n;
the color*/ int HuaSe[4]={3,4,5,6}; /*Store
char ShuZi[13]={'A','K','Q','J','0','9','8','7','6','5','4','3','2'};
/*Store the number*/
float DianShu[13]={1,0.5,0.5,0.5,10,9,8,7,6,5,4,3,2};/*Store the points*/
Build_Show(HuaSe, DianShu,ShuZi); /*Establish the card and show it*/
do{
Wash_Card(); /*Wash cards*/
a: puts("\nPlease input the number of the player:");
scanf("%d", &n);
switch(n)
{
case 1:puts("You play with the computer!");
break;
case 2:puts(:You two play!:);
break;
case 3:puts("You three play!");
break;
case 4:puts("You four play!");
break;
case 5:puts("You five play!");
break;
case 6:puts("You six play!");
break;
case 7:puts("You seven play!");
break;
case 8:puts("You eight play!");
break;
default:puts("The number of the players is too large!");
goto a;
}
Get_Card(n); /*Hand out the cards and give the result*/
do{
puts("\nDo you want to play again?1 represents yes and 0 no:");
scanf("%d", &flag);
}while(flag != 1 && flag != 0);
} while(flag == 1);
}
void Build_Show(int HuaSe[], float DianShu[], char ShuZi[])
{
int i, j;
for(i=0; i<4; i++) /*Establish a pair of cards*/
for(j=0; j<13; j++)
{
+13*i].color = HuaSe[i]; Card[j
Card[j+13*i].number = ShuZi[j];
Card[j+13*i].num = DianShu[j];
}
puts("This is a new pair of cards:");
/*Show the whole pair to the players to check*/
for(i=0,j=0; i<52; i++,j++)
{
if(!(j%13))
printf("\n");
printf ("%c%c", Card[i].color , Card[i].number);
}
}
void Wash_Card(void)
{
int i,rand1,rand2,hua;
char dian;
float shu;
for(i=0; i<1; i++)
{
rand1=random(52); /*Get a card by random,and put the cards into mess*/
rand2=random(52);
if(rand1!=rand2)
hua=Card[rand1].color;
Card[rand1].color=Card[rand2].color;
Card[rand2].color=hua;
dian=Card[rand1].number;
Card[rand1].number=Card[rand2].number;
Card[rand2].number=dian;
shu=Card[rand1].num;
Card[rand1].num=Card[rand2].num;
Card[rand2].num=shu;
}
}
void Get_Card(int n) /*Hand out the cards one by one and give the result*/
{
int i=0, j=0, k=0, flag=1, flag2=1;
float sum_m=0, sum_c=0;
struct book Man[52], Computer[52];
if(n == 1)
{
while(flag == 1 && i < 52)
{
Man[j++]=Card[i++]; /*Man gets the card firstly*/
sum_m += Man[j-1].num; /*Acumulate the whole points of the man*/
if(flag2 == 1 && i < 52 && (sum_m <= 10.5 &&sum_c <= 10.5 && (sum_c +
Card[i].num) <= 10.5|| sum_m > 10.5 && (sum_c + Card[i].num) >=sum_m))
/*Let the computer know what the next card is and decide whetherto get a card */
{
Computer[k++]=Card[i++]; /*The computer gets a card*/
sum_c += Computer[k-1].num; /*Acumulate the whole points of the computer*/
}
else
flag2=0;
printf("\n");
puts("Now the cards you get are:");
for(i=0; i 10.5 && (sum_c + Card[i].num) >=sum_m))
/*Let the computer knonws what the next card is and decide wheter to get one*/
{
Computer[k++]=Card[i++];
sum_c += Computer[k-1].num;
> 10.5) if( sum_c
break;
}
puts("Okay,now give out the result:");
puts("Now the cards you've got are:");
for( i=0; i 10.5 && sum_c > 10.5)||(sum_m <= 10.5&& sum_c <= 10.5))
if(sum_m > sum_c)
!It's unbelievable!"); puts("You win the computer
else
if(sum_m == sum_c)
puts("You play as well as the computer,and you're really good.");
else
puts("The computer wins and you need more practice!");
else
if(sum_m <= 10.5 && sum_c > 10.5)
puts("You win the computer!It's unbelievable!");
else
puts("The computer wins and you need more practice!");
}
else
DuoRen();
}
void DuoRen()
{
struct book Man[N][52];
int i, a[N]={0}, k=0, flag[N], flag2=1, s=0,m=0;
float sum[N]={0},q,t;
for(i=0; i 10.5)
flag[i]=0;
}
s=0;
for(k=0; k
本文档为【纸牌游戏:十点半】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。