基于掷色子规则的c语言编程,掷骰子游戏-C语言
上面是我用C语言做出来的掷骰子游戏。
掷骰子游戏中最有意思的我觉得是画骰子,还有其中getchar()的用法。就这个getchar()
的用法就折磨了我好长时间,之后我将专门发一篇博文来记录 getchar()的用法。
接下来就是掷骰子游戏的源程序了,想玩的话,大家就可以把程序复制下来,就能实现了。
源程序:
#include
#include
#include
#include
void gotoxy(int row, int
col){
printf("\033[%d;%dH", row, col);
}
void drawrect(){
for
(int i=0;
i<3;
i++) {
for (int
j=0; j<
se-mark="1">9; j++) {
gotoxy(5, 10+j+12*i);
printf("-\n");
gotoxy(11,10+j+12*i);
printf("-\n");
}
for (int
j=0; j<
se-mark="1">5; j++) {
gotoxy(j+6, 10+12*i);
printf("|\n");
gotoxy(j+6, 18+12*i);
printf("|\n");
}
}
}
void drawdice(int num,int
row,int col){
if
(num==1) {
gotoxy(row+3,
col+4);
printf("。\n");
}
if
(num==2) {
gotoxy(row+3,
col+3);
printf("。\n");
gotoxy(row+3,
col+4);
printf("。\n");
}
if
(num==3) {
gotoxy(row+2,
col+3);
printf("。\n");
gotoxy(row+3,
col+4);
printf("。\n");
gotoxy(row+4,
col+5);
printf("。\n");
}
if
(num==4) {
gotoxy(row+2,
col+3);
printf("。\n");
gotoxy(row+2,
col+5);
printf("。\n");
gotoxy(row+4,
col+3);
printf("。\n");
gotoxy(row+4,
col+5);
printf("。\n");
}
if
(num==5) {
gotoxy(row+2,
col+3);
printf("。\n");
gotoxy(row+2,
col+5);
printf("。\n");
gotoxy(row+3,
col+4);
printf("。\n");
gotoxy(row+4,
col+3);
printf("。\n");
gotoxy(row+4,
col+5);
printf("。\n");
}
if
(num==6) {
gotoxy(row+2,
col+3);
printf("。\n");
gotoxy(row+2,
col+5);
printf("。\n");
gotoxy(row+3,
col+3);
printf("。\n");
gotoxy(row+3,
col+4);
printf("。\n");
gotoxy(row+4,
col+3);
printf("。\n");
gotoxy(row+4,
col+5);
printf("。\n");
}
}
void cleardice(){
for
(int j=0;
j<3;
j++) {
for (int
i=0; i<
se-mark="1">3; i++) {
gotoxy(7+i, 13+12*j);
printf(" \n");
}
}
}
int main(int argc, const
char * argv[]) {
system("clear
screen");
drawrect();
srand((unsigned
int)time(0));
int
dice1=rand()%6+1;
drawdice(dice1,5,10);
int
dice2=rand()%6+1;
drawdice(dice2,5,22);
int
dice3=rand()%6+1;
drawdice(dice3,5,34);
int
playermoney=1000;
int
bossmoney=1000;
while
(1) {
gotoxy(12, 1);
printf("输入0、1、2,0买大、1买小、2买豹子\n");
int choose;
scanf("%d",&choose);
if
(0<=choose<=2){
for (int i=0;
i<
se-mark="1">20; i++) {
dice1=rand()%6+1;
drawdice(dice1,5,10);
dice2=rand()%6+1;
drawdice(dice2,5,22);
dice3=rand()%6+1;
drawdice(dice3,5,34);
usleep(200000);
if
(i==19) {
break;
}
cleardice();
}
}
else{
gotoxy(14, 1);
printf("输入有误,请重新输入\n");
sleep(2);
gotoxy(14, 1);
printf("
\n");
continue;
}
if ((choose==0
&&
dice1+dice2+dice3>10) ||
(choose==1 &&
dice1+dice2+dice3<
se-mark="1">11) ||
(choose==2 &&
dice1==dice2==dice3)){
gotoxy(14, 1);
printf("你赢了\n");
playermoney+=200;
bossmoney-=200;
}
else{
gotoxy(14, 1);
printf("你输了\n");
playermoney-=200;
bossmoney+=200;
}
gotoxy(15, 1);
printf("playermoney:
");
gotoxy(15, 1);
printf("playermoney:%d\n",playermoney);
gotoxy(16, 1);
printf("bossmoney:
");
gotoxy(16, 1);
printf("bossmoney:%d\n",bossmoney);
if (playermoney==0)
{
gotoxy(17, 1);
printf("真倒霉,您的钱已经输完了!!!y重新开始,任意键离开\n");
sleep(2);
gotoxy(17, 1);
printf("
\n");
char ch=getchar();
ch=getchar();
if (ch=='y') {
playermoney=1000;
bossmoney=1000;
continue;
}
printf("gameover!!!\n");
break;
}
}
return
0;
}
基于掷色子规则的c语言编程,掷骰子游戏-C语言相关推荐
- c语言编程期刊论文管理系统,C语言编程下计算机软件论文
1计算机软件C语言的编程实验 1.1计算机软件C语言的编程技巧 计算机软件C语言的编程中,最主要的依据是指针应用,C语言指针能够根据软件程序的编写需求,构建可行的函数,而程序员在设计函数编程的过程中, ...
- c语言化学专业,通化c语言编程学习,通化学c语言编程学校,通化学c语言编程报个培训班怎么样...
通化c语言编程学习,通化学c语言编程学校,通化学c语言编程报个培训班怎么样 首页 > C语言 > 通化c语言编程学习 作者:镀金池 发布时间:2017-10-21 08:17 map ...
- 高斯消元法的c语言编程,列主元高斯消元法的C语言编程
列主元高斯消元法的C语言编程 列主元高斯消元法 基本思想:用高斯消元法求解线性方程组时,为避免小的主元,在进行第k步消元前,应该在第k列(k)元素aik(i k,(k)(k)例如|aikk| max| ...
- c语言程序设计自学跟谁好,双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好...
双辽c语言编程学习,双辽学c语言编程哪个好,双辽学c语言编程自学好还是报班好 首页 > 软件 > 双辽c语言编程学习 作者:镀金池 发布时间:2017-12-07 05:48 一个C语 ...
- c语言程序设计需要学多久,九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会...
九江c语言编程学习,九江学c语言编程报班,九江学c语言编程一般要多久才能学会 首页 > C语言 > 九江c语言编程学习 作者:镀金池 发布时间:2017-10-18 14:11 据ID ...
- c语言编程学多久,丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会...
丰城c语言编程学习,丰城学c语言编程的学校,丰城学c语言编程一般要多久才能学会 首页 > 软件 > 丰城c语言编程学习 作者:镀金池 发布时间:2018-04-09 16:40 在之后 ...
- 江门C语言培训,江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样...
江门c语言编程学习,江门学c语言编程培训,江门学c语言编程效果怎么样 首页 > C语言 > 江门c语言编程学习 作者:镀金池 发布时间:2017-10-18 09:25 在初期的C语言 ...
- C语言报名里面培训怎么填,庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样...
庄河c语言编程学习,庄河学c语言编程培训,庄河学c语言编程报个培训班怎么样 首页 > 软件 > 庄河c语言编程学习 作者:镀金池 发布时间:2017-11-29 11:13 明天利用时 ...
- 罗定c语言,罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费...
罗定学c语言编程,罗定学c语言编程培训,罗定学c语言编程一般怎么收费 首页 > 软件 > 罗定学c语言编程 作者:镀金池 发布时间:2018-10-04 23:40 依照c语言的法则, ...
- 安庆师范大学c语言程序设计,安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资...
安庆c语言编程学习,安庆学c语言编程培训,安庆学c语言编程一般能拿多少工资 首页 > C语言 > 安庆c语言编程学习 作者:镀金池 发布时间:2017-10-18 15:20 假定我们 ...
最新文章
- 用Construct 2制作入门小游戏~
- FastThreadLocal吞吐量居然是ThreadLocal的3倍
- linux欢迎界面设计,Ubuntu 18.04 LTS新增欢迎界面--方便用户快速上手新系统
- android studio 7200u,超惊艳的设计!微软正式将Surface Studio和Surface Laptop带进中国:设计师们都看哭了...
- 向spark standalone集群提交任务
- 标准化工作导则2020_最新版 GB/T 1.12020 标准化工作导则 第 1 部分:标准化文件的结构和起草规则标准解读...
- 线程互斥与同步 在c#中用mutex类实现线程的互斥_Golang 并发编程与同步原语
- 对 Redis 中的有序集合SortedSet的理解
- 在集设|参透海报设计中提取排版设计灵感
- MLOps- 吴恩达Andrew Ng Data Definition and Baseline Week3 实验作业
- L3HCTF bypass出题人视角
- 串口调试助手fx2n_安信可串口调试助手
- Google Earth Engine(GEE)——使用Combining reducers计算均值和标准差
- 2022杭电多校 第三场 B题 Boss Rush
- 手把手教你开发一款简单的AR软件
- C. 点和圆 (类与对象)
- 第六周作业--需求建模
- 发布版,浏览器端隐藏代码
- dux修改index.php,[mcj]Dux大前端主题增加网站顶端公告模块
- i.MX6ULL终结者MPU6050 六轴传感器例程原理分析