社区
C语言
帖子详情
求21点游戏的C/C++代码
quchch
2005-06-20 04:29:53
要求:
随机的产生一副扑克排(不需要画出),玩家和计算机轮流抓牌,如果谁的点超过21点。即告负,否则,点多者胜.
如果哪位有程序代码或能编出来,请发送给chengsoft@gmail.com.
如果能解决问题的哥们,吾将赠送88分同时再发一个google的gmail邮箱注册邀请函给你.谢谢啦!
...全文
568
6
打赏
收藏
求21点游戏的C/C++代码
要求: 随机的产生一副扑克排(不需要画出),玩家和计算机轮流抓牌,如果谁的点超过21点。即告负,否则,点多者胜. 如果哪位有程序代码或能编出来,请发送给chengsoft@gmail.com. 如果能解决问题的哥们,吾将赠送88分同时再发一个google的gmail邮箱注册邀请函给你.谢谢啦!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jixingzhong
2005-06-20
打赏
举报
回复
main()
{
int i,result;
char ch;
int gdriver,gmode;
clrscr();
init(); /*图形初始化*/
while(1)
{
setbkcolor(BLACK);
cleardevice();
play();
gotoxy(1,15);
printf("-----------------------------------note------------------------------------------------\n"); /*表达式的输入*/
printf("Please enter express include only four numbers:\n");
printf("Format as follows:2.*(3.+5.)/2.\n");
printf("-----------------------------------------------------------------------------------------\n");
gets(str);
change(str);
result=compute();
if(result==24)
text1("VERY GOOD!!!");
else
text1("WRONG!!!");
printf("continue?(Y or N)\n");
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
close(); /*关闭图形*/
return;
}
以上是24点的游戏代码,基本上就是一个意思的拉
楼主参考参考把
jixingzhong
2005-06-20
打赏
举报
回复
int text1(char *s) /*显示文本*/
{
setbkcolor(BLUE);
cleardevice();
setcolor(12);
settextstyle(1,0,8);
outtextxy(120,120,s);
setusercharsize(2,1,4,1);
setcolor(15);
settextxy(220,220,s);
getch();
return;
}
void init()
{int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"d:\\turboc2");
cleardevice();
}
void close()
{
closegraph();
}
void change(char stm[]) /*将表达式的输出类型进行转换*/
{int i=0,j=0;
char ch;
initstack(L);
ch=stm[i];
while(ch!='\0')
{
while(isdigit(ch)||ch='.')
{
after[j]=ch;
j++;
ch=stm[++i];
}
switch(ch)
{
case '+':
case '-':
while(L->top!=0&&L->stack[L->top]!='(')
{
after[j]=L->stack[L->top];
j++;
L->top--;
}
L->top++;
L->stack[L->top]=ch;
break;
case '*':
case '/':
while(L->stack(L->top)=='*'||L->stack[L->top]='/')
{
after[j]=L->stack[L->top];
j++;
L->top--;
}
L->top++;
L->stack[L->top]=ch;
break;
case '(':
L->top++;
L->stack[L->top]=ch;
break;
case ')':
while(L->stack[L->top]!='('&&L->top!='\0')
{
after[j]=L->stack[L->top];
j++;
L->top--;
}
if(L->top==0)
{
printf("wrong input format!\n");
exit(0);
}
L->top--;
break;
case ' ':
break;
default:
printf("the express include illegal character!\n");
exit(0);
}
i++;
ch=stm[i];
}
while(L->top!=0)
{
after[j]=L->stack[L->top];
j++;
}
after[j]='\0';
printf("the changed expression is:");
puts(after);
printf("\n");
}
int compute() /*计算表达式的值*/
{
int m=0,n;
char ch;
initstack1(S);
ch=after[m];
while(ch!='\0')
{
if(isdigit(ch))
{
n=0;
do
{
n=10*n+ch-'0';
ch=after[++m];
}while(ch!='.')
switch(ch)
{
case '+':
S->stack1[S->top-1]=S->stack1[S->top-1]+S->stack1[S->top];
S->top--;
break;
case '-':
S->stack1[S->top-1]=S->stack1[S->top-1]-S->stack1[S->top];
S->top--;
break;
case '*':
S->stack1[S->top-1]=S->stack1[S->top]*S->stack1[S->top-1];
S->top--;
break;
case '/':
S->stack1[S->top-1]=S->stack1[S->top-1]/S->stack1[S->top];
S->top--;
break;
}
ch=after[++m];
}
return S->stack1[S->top];
}
jixingzhong
2005-06-20
打赏
举报
回复
#include<stdio.h>
#include<graphics.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
#define COL 100
#define COM 40
#define max 20
char after[max];
typedef struct stack /*定义栈1存放运算符*/
{
char stack[max];
int top;
}stack;
stack L;
typedef struct stack1 /*定义栈2计算表达式值*/
{
int stack1[max];
int top;
}stack1;
stack1 S;
void initstack(stack M)
{
M->top=0;
}
voidinitstack1(stack1 N)
{
N->top=0;
}
char p[4][13]={
{'A','2,'3','4','5','6','7','8','9','0','J','Q','K'},
{'A','2,'3','4','5','6','7','8','9','0','J','Q','K'},
{'A','2,'3','4','5','6','7','8','9','0','J','Q','K'},
{'A','2,'3','4','5','6','7','8','9','0','J','Q','K'}
};
void play() /*发牌函数*/
{
int j;
for(j=1;j<=4;j++)
{
bar(COL+100*j-35,COM+100-50,COL+100*j+35,COM+100+50);
setcolor(BLUE);
rectangle(COL+100*j-32,COM+100-48,COL+100*j+32,COM+100+48);
rand1(j);
delay(10000);
}
}
void rand1(int j)
{
int kind,number;
char str[3];
randomize();
while(1)
{
kind=random(4);
num=random(13);
if(p[kind][num]!=-1)
{
n=p[kind][num];
p[kind][num]=-1;
break;
}
}
switch(kind)
{
case 0:
setcolor(RED);
sprintf(str,"%c",3);
break;
case 1:
setcolor(BLACK);
sprintf(str,"%c",3);
break;
case 2:
setcolor(RED);
sprintf(str,"%c",4);
break;
case 3:
setcolor(BLACK);
sprintf(str,"%c",5);
break;
}
settextstyle(0,0,2);
outtextxy(COL+j*100-30,ROW+100-46,str);
outtextxy(COL+j*100+16,ROW+100+32,str);
if(n!='0')
{
settextstyle(0,0,3);
sprintf(str,"%c",n);
outtextxy(COL+j*100-5,ROW+100-5,str);
}
else
{
sprintf("str,"%d",10);
outtextxy(COL+j*100-6,ROW+100-5,str);
}
}
MagicCarmack
2005-06-20
打赏
举报
回复
www.cn700.com
自己找找看
user_c
2005-06-20
打赏
举报
回复
0 o 0!!!
我们的期末实验作业里就有这个!!
laolaoliu2002
2005-06-20
打赏
举报
回复
《Visual C++.NET小游戏开发时尚编程百例》书里面有。
21
点
游戏
代码
C语言
比较完美的
游戏
界面,基本功能都具备,属于人机
游戏
。
免费下载:C语言难
点
分析整理.doc
PC-Lint是一款静态
代码
分析工具,可以帮助检测C/
C++
代码
中的潜在问题。 ### 32. sprintf函数使用大全 这部分详细介绍了`sprintf()`函数的使用方法。 ### 33. 二叉树的数据结构 这部分介绍了二叉树的基本概念和实现...
推荐开源项目:C/
C++
代码
漏洞数据集——深入洞察软件安全
???? 推荐开源项目:C/
C++
代码
漏洞数据集——深入洞察软件安全 ...1. 项目介绍 在不断发展的软件工程领域中,安全...为应对这一挑战,我们向您隆重推荐一款强大而全面的开源工具:“C/
C++
代码
漏洞数据集(A C/
C++
Code ...
《C/
C++
实战专栏》介绍
本文详细介绍《C/
C++
实战专栏》的主体内容构成。
C/
C++
学习路线总结与分享
C/
C++
学习路线总结与分享
C语言
70,022
社区成员
243,263
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章