C语言编写简单游戏:剪刀、石头、布
一、C语言编写简单游戏:剪刀、石头、布
呵呵,这是我去年初学C语言时写的,当时水平低,高手就不要指责了~~~
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
char x,response;
int y,draw,win,loss;
void main()
{
c: draw = 0,win = 0,loss = 0;
d: system(cls);
printf(欢迎挑战\n\n);
printf(0:石头 1:剪子 2:布\n);
printf(\n请你出拳:);
if((x = getch()) == '0')
printf(石头);
else if(x == '1')
printf(剪子);
else if(x == '2')
printf(布);
else
{
printf(请按0-2\n按任意键继续\n);
getch();
goto d;
}
srand((unsigned)time(NULL));
y = rand()%3;
switch(y)
{
case 0:
printf(\n\n电脑出拳:石头\n\n);
break;
case 1:
printf(\n\n电脑出拳:剪子\n\n);
break;
case 2:
printf(\n\n电脑出拳:布\n\n);
break;
}
if(x == '0')
{
switch(y)
{
case 0:
printf(平局);
draw++;
break;
case 1:
printf(你赢了);
win++;
break;
case 2:
printf(你输了);
loss++;
break;
}
}
else if(x == '1')
{
switch(y)
{
case 0:
printf(你输了);
loss++;
break;
case 1:
printf(平局);
draw++;
break;
case 2:
printf(你赢了);
win++;
break;
}
}
else if(x == '2')
{
switch(y)
{
case 0:
printf(你赢了);
win++;
break;
case 1:
printf(你输了);
loss++;
break;
case 2:
printf(平局);
draw++;
break;
}
}
printf(\n\n你的战况:赢%d局 输%d局 平%d局, win, loss, draw);
if(win <= loss+draw)
{
printf(\n\n还不服气?\nY or N?\n);
response=getch();
if(response == 'Y' || response == 'y' || response == 13)
{
printf(\n战况清零?\nY or N?\n);
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
goto c;
}
goto d;
}
}
else
{
printf(\n\n厉害,继续?\nY or N?\n);
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
printf(\n战况清零?\nY or N?\n);
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
goto c;
}
goto d;
}
}
}
二、我下载的H5游戏源码搭建 代码什么的都上传好了 登录后台输入密码显示密码错误
你输入错误除了提示账号密码错误,其他没有是吧,还有你数据库信息填的对应不,密码加密方式对么,检查一下,还没搞好再找俺解决
三、JAVA 设计代码
/*
* 主类用与建立3个取款行为线程
*/
public class getMoney
{
public static void main(String args[])
{
card c=new card(100);
new Thread(c,ID-1).start();
new Thread(c,ID-2).start();
new Thread(c,ID-3).start();
System.out.println(3 ID using\t\t\t\t\t\t title 100$);
}
}
/*
* 实现RUNNABLE的银行卡类
*/
class card implements Runnable
{
private static int balance;
public card(int x)
{
this.balance=x;
}
public int view()
{
return balance;
}
public void get(int x)
{
this.balance=this.balance-x;
}
/*
* 同步方法块
*/
public synchronized void run()
{
int num=0;
while(this.view()>0)
{
System.out.println(操作时间:+num);
this.get(10);
System.out.println(Thread.currentThread().getName()+get 10$\t\t\t\t\t\t此时余额为+this.view());
num++;
}
if(this.view()<=0)
{
System.out.println(Thread.currentThread().getName()+取光了剩下所有的钱);
}
}
}
这个是银行取款的和受票类似,用了同步方法的方式
/*
* 主类用语建立3个售票窗口线程
*/
public class MyRun
{
public static void main(String args[])
{
My t=new My();
new Thread(t,t1).start();
new Thread(t,t2).start();
new Thread(t,t3).start();
System.out.println(开始售票..................);
}
}
/*
*实现RUNNABLE的售票窗口类
*/
class My implements Runnable
{
static int sum=20;
public void run()
{
synchronized(sldf)//同步语句块的方式
{
while(sum>0)
{
System.out.println(票号(+sum+)被卖掉了---------------------------------------售票窗口:+Thread.currentThread().getName());
sum--;
if(sum<=0)
{
System.out.println(售票窗口:+Thread.currentThread().getName()+的票卖完了!);
}
}
}
}
}
用了同步语句块的方式,你要4个窗口在主类多NEW一个线程就可以了
上一篇:2岁的宝宝,怎样开发智力
- 玩游戏时看网站发现了病毒!游戏号会丢吗?[07-25]
- C语言编写简单游戏:剪刀、石头、布[07-25]
- 2岁的宝宝,怎样开发智力[07-25]
- 贵港附近哪里好玩的呀电玩城动漫城游戏厅啊?.[07-25]
- 求一款红白机游戏,人物敲敲地面就会长出个树藤,收到什么东西时武器回先打出一个星星[07-25]
- 有什么好玩 有剧情的三维游戏?[07-24]
- 仙剑3隐藏古董都在什么地方?[07-24]
- 什么是赛尔号?[07-24]
- 沈阳夜场哪好玩?[07-24]
- 赛尔号王之哈莫,7星和4星,怎么一定能爆出来,求,急,快。[07-24]
-
绿茵信仰
2.9 Android
2024-04-13
-
NBA篮球大师
5 Android
2024-04-13
-
艾特足球
0.26 Android
2024-04-13
-
豪门足球风云
1 Android
2024-04-13
-
3D极限摩托
2.4 Android
2024-04-13
-
冠军台球
2 Android
2024-04-13
-
飞羽青春
1.1 Android
2024-04-13
-
超凡台球
1 Android
2024-04-13
-
最佳11人
5 Android
2024-04-13
-
网球传奇
2.23 Android
2024-04-13
-
狂奔的卡车
1.1 Android
2024-04-13
-
高尔夫挑战赛
1 Android
2024-04-13