C语言编写简单游戏:剪刀、石头、布

作者: 游氏手游网 发布时间: 2025-07-25 14:30

一、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岁的宝宝,怎样开发智力
下一篇:没有了
手游推荐
蛋仔派对蛋仔派对 迷你世界迷你世界 钢琴音乐大师钢琴音乐大师 开心消消乐开心消消乐
最新游戏
绿茵信仰绿茵信仰 NBA篮球大师NBA篮球大师 艾特足球艾特足球 豪门足球风云豪门足球风云
最新专题
王者教学

王者教学

帕鲁指南

帕鲁指南