『壹』 java猜拳游戲程序設計怎麼做啊
importjava.util.Random;
classDianNao{
publicStringchuQuan(){
Randomrand=newRandom();
inti=rand.nextInt(3);
Stringstr="";
if(i==0){
str="石頭";
}
if(i==1){
str="剪刀";
}
if(i==2){
str="布";
}
returnstr;
}
}
classCaiPan{
publicStringcaiJue(Stringstr1,Stringstr2){
Stringstr="輸";
if(str1.equals("石頭")&&str2.equals("剪刀")){
str="贏";
}
if(str1.equals("石頭")&&str2.equals("布")){
str="輸";
}
if(str1.equals("石頭")&&str2.equals("石頭")){
str="平";
}
if(str1.equals("剪刀")&&str2.equals("石頭")){
str="輸";
}
if(str1.equals("剪刀")&&str2.equals("布")){
str="贏";
}
if(str1.equals("剪刀")&&str2.equals("剪刀")){
str="平";
}
if(str1.equals("布")&&str2.equals("石頭")){
str="贏";
}
if(str1.equals("布")&&str2.equals("剪刀")){
str="輸";
}
if(str1.equals("布")&&str2.equals("布")){
str="平";
}
returnstr;
}
}
publicclassShiTouJianBu{
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
CaiPancp=newCaiPan();
DianNaodn1=newDianNao();
DianNaodn2=newDianNao();
Stringstr1=dn1.chuQuan();
Stringstr2=dn2.chuQuan();
Stringresult=cp.caiJue(str1,str2);
System.out.println(str1);
System.out.println(str2);
System.out.println(result);
}
}
就幫你到這吧
『貳』 C語言 怎麼用C語言設計一個猜拳游戲 剪刀石頭布用1.2.3代替 要玩5局3勝,
#include <stdio.h>
#include <time.h>
int main()
{
int a,b,i,m=0,n=0;
srand(time(NULL));
for(i=0;i<10;i++)
{
a=rand()%3+1;
printf("%d",a);
b=rand()%3+1;
printf("%d\n",b);
if(a>b) m++;
else if(a<b) n++;
if(m>3)
{
printf("a is the winner");
break;
}
if(n>3)
{
printf("b is the winner");
break;
}
}
return 0;
}
『叄』 求Flash製作猜拳游戲的詳細教程
主要過程:
第一楨代碼:
pla = 0;
com = 0;
totalplay = 0;
//以上是初始化變數
第五楨代碼:
if (pla>com) {//當玩家獲勝次數多於電腦的時候,跳到第六楨,下面兩句解釋類似
gotoAndStop(6);
} else if (pla<com) {
gotoAndStop(7);
}
if (pla == com) {
gotoAndStop(8);
}
下面是按鈕上的代碼:
on (press) {//當按下的時候
totalplay = totalplay+1;//總數加1
if (totalplay == 30) {//當總數等於30的時候跳轉到第五楨
gotoAndStop(5);
} else if (totalplay<30) {//當小於30的時候
a = random(3)+2;//得到一個隨機數
if (a == 4) {
com = com+1;//當電腦獲勝的時候,電腦獲勝次數加1
}
if (a == 3) {
pla = pla+1;//當玩家獲勝的時候,玩家獲勝次數加1
//上面這些就是游戲規則,當剪刀遇到錘子的時候,錘子獲勝,也就是電腦獲勝
}
_root.computer.gotoAndStop(a);//電腦那一邊顯示
_root.player.gotoAndStop(2);//玩家這一邊顯示你出的內容
}
}
}
其他兩個按鈕上的代碼和上面的解釋類似,大家看看就會明白
on (press) {
totalplay = totalplay+1;
if (totalplay == 30) {
gotoAndStop(5);
} else {
a = random(3)+2;
if (a == 2) {
com = com+1;
}
if (a == 4) {
pla = pla+1;
}
_root.computer.gotoAndStop(a);
_root.player.gotoAndStop(3);
}
}
on (press) {
totalplay = totalplay+1;
if (totalplay == 30) {
gotoAndStop(5);
} else {
a = random(3)+2;
if (a == 3) {
com = com+1;
}
if (a == 2) {
pla = pla+1;
}
_root.computer.gotoAndStop(a);
_root.player.gotoAndStop(4);
}
}
//其餘的就是很簡單的按鈕控制,我就不必說了,只要懂一點AS就明白 ^_^
附加:
教程:http://www.pconline.com.cn/pce/specialtopic/flashvtut/71/713.zip
源文件:http://www.pconline.com.cn/pce/specialtopic/flashvtut/71/7.1src.zip
參考:http://www.zmke.com/article/182/185/2007/2007050710013.html
http://www.elook.net.cn/cms/Site/Article/cyshj104/wyzhz115/flash117/yxzhz124/30669.html
『肆』 C# 設計網路小游戲猜拳代碼。
這個好做!你要是不介意可以讓我給你試一試, 我做了一個udp的五子棋,你可以參考一下 可以給我郵件 [email protected] 還有一個是和timer有關的,你要是想要我都可以給你。
『伍』 關於猜拳游戲的c語言課程設計報告怎麼寫啊
題目,分析題目,然後寫設計思路,然後編寫代碼,分析代碼,然後測試代碼,可以寫很多的,一般對寫代碼的報告就寫那麼多久夠了
『陸』 用C語言編寫一個有趣的猜拳游戲
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#define maxn 10001
char p1[]="rock";
char p2[]="scissors";
char p3[]="cloth";
char *h[4];
void init(void)
{
h[1]=p1;
h[2]=p2;
h[3]=p3;
}
void begin(void)
{
char your[maxn];
long com;
char p[maxn];
srand(time(NULL));
for(;;)
{
printf("input your order ?( 1:rock 2:scissors 3:cloth )\n");
scanf("%s",your);
com=strlen(your);
if( your[0]>'3' || your[0]<'1' || com!=1)
{
printf("wrong order! please choose in(1~3);\n");
getchar();
continue;
}
printf("your order is %s!\n",h[your[0]-'0']);
getchar();
getchar();
com=rand()%3+1;
printf("The computer's order is %s!\n",h[com]);
getchar();
switch(com-your[0]+'0')
{
case 0:printf("draw game!\n");break;
case 1:
case -2:
printf("You wins!\n");break;
case -1:
case 2:
printf("The computer wins!\n");break;
}
com=1;
for(;com==1;)
{
printf("continue?(Y/N)\n");
scanf("%s",p);
com=0;
switch(p[0])
{
case 'Y':break;
case 'N':
printf("press any key to continue.\n");getchar();getchar();return ;
default:
printf("wrong order!\n");com=1;break;
}
}
}
}
main(void)
{
init();
begin();
return 0;
}
『柒』 C語言課程設計:猜拳游戲。
int fun(int X,int Y)
{
srand((unsigned)time(NULL)); /*隨機種子*/
n=rand()%(Y-X+1)+X; /*n為X~Y之間的隨機數*/
return n;
}
main()
{
int a=0;
int x = 0;
int b[3] = {1,2,3};
do{
x = fun(0,3);
if((a == 3 && b[x] == 1) ||(b[x]-a == 1))
{
printf("lose ")
}
else if((b[x] == 3 && a == 1) ||(a-b[x] == 1))
{
printf("win");
}
else
{
printf("retry ");
}
}while(true)
}
『捌』 匯編語言猜拳程序設計
猜拳游戲 有點就是取隨機數 匯編的隨機數可以這樣取 你可以打開定時器 在需要取隨機數的時候把定時器計的數取出來對1個數求余就成了~
『玖』 怎樣用C語言編寫一個猜拳游戲
/*至摟主:本游戲系統可支持多個用戶游戲,一次只能登錄一個用戶,運行此程序會生成一個文件來存儲用戶信息,本程序允許承載的用戶個數為1000個,為使游戲更有趣味,程序特意為不同的玩家分數設計了不同的等級,程序初始化時,會生成一個只含有5個系統玩家的文件。游戲過程中,文件會不斷刷新,如果玩家要刪除一切曾經的游戲記錄,只需將存儲文件刪除,存儲記錄的文件名為'sunyi',如果摟主想與我們聯系,請加QQ好友865363864。(加好友時請摟主註明身份)。
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#define NULL 0
/**************************************************************************************************************************/
struct computer //定義系統玩家結構體
{
char player[30];
int score;
int times;
int time;
}cpt[1000]={"player1",100,1,1,"player2",100,1,1,"player3",100,1,1,"player4",100,1,1,"player5",100,1,1,};
FILE *in; //生成記錄玩家信息的文件的指針
int number,rool; //rool:玩家所在數組位置的角標.number:數組元素的個數.
/****************************************************************************************************************************/
int h() //生成一個隨機數(1,2或3);
{
int k,n;
n=rand()%3;
return n+1;
}
/****************************************************************************************************************************/
int str_to_num(char a[]) //引入函數str_to_num:使字元串(string)轉化為整數數形式(int)!
{
int i=strlen(a)-1,num=0,time=1;
for(;i>=0;i--)
{
num=num+(a[i]-'0')*time;
time=time*10;
}
return(num);
}
/*****************************************************************************************************************************/
void b(int n)
{
switch((int)(n/20))
{
case(0):printf("等級:江湖渣子");break;
case(1):
case(2):printf("等級:初入江湖");break;
case(3):
case(4):
case(5):printf("等級:江湖浪子");break;
case(6):
case(7):
case(8):
case(9):printf("等級:江湖俠客");break;
case(10):
case(11):
case(12):
case(13):
case(14):
case(15):
case(16):
case(17):
case(18):
case(19):printf("等級:一派掌門");break;
default:
{
switch((int)(n/1000))
{
case(0):printf("等級:武林盟主");break;
case(1):
case(2):
case(3):
case(4):printf("等級:江湖奇俠");break;
case(5):
case(6):
case(7):
case(8):
case(9):printf("等級:孤獨求敗");break;
default:printf("等級:不死之身");break;
}
}
}
}
/*****************************************************************************************************************************/
int readfile(void) //讀文件
{
int i,number=5;
if((in=fopen("sunyi.txt","rb"))!=NULL)
{
fread(&number,sizeof(int),1,in);
for(i=0;i<number;i++)
{
fread(&cpt[i],sizeof(struct computer),1,in);
}
fclose(in);
}
return(number);
}
/******************************************************************************************************************************/
void writefile() //寫文件
{
int i;
in=fopen("sunyi.txt","wb");
fwrite(&number,sizeof(int),1,in);
for(i=0;i<number;i++)
{
fwrite(&cpt[i],sizeof(struct computer),1,in);
}
fclose(in);
}
/*******************************************************************************************************************************/
void rule() //規則函數
{
printf(" 猜拳游戲\n");
printf("規則:\n");
printf(" 輸入「N」或「n」查看積分,第一次游戲時,會免費贈送玩家100枚金幣,每局游戲都會");
printf("提示您輸入押金,押金必須大於1枚金幣!(含1枚),提示游戲開始後,輸入一個1~3");
printf("之間的值;1表示石頭,2表示剪刀,3表示布。同時,系統也將出拳,按照通俗規則,贏者");
printf("將得到押金,否則扣除,當積分小於5分時,您有五次機會得到系統免費贈送的30分,");
printf("當玩家金幣數為零時(又用完5次得到30金幣的機會), 系統將提示玩家游戲結束。並刪");
printf("除用戶。\n");
printf(" #本系統會自動生成5個系統玩家輪流與您游戲,游戲前,玩家需要登錄來調出自己");
printf("的游戲記錄,如果是第一次游戲,請輸入「register」,再輸入新用戶名注冊,如果以前");
printf("進行過游戲,請輸入「entry」再輸入「用戶名」登錄.\n(註:本系統允許存儲本記錄多個用戶的信息。)\n\n");
}
/*********************************************************************************************************************************/
int registe() //開始游戲前的登錄和注冊.
{
char ch[30];
int i;
loop4:
printf("\n第一次玩游戲?請輸入「register」注冊!\n登錄?請輸入「entry」登錄\n");
loop3:
scanf("%s",ch);
if(strcmp("register",ch)==0)
{
loop2:
printf("請輸入新用戶名:(長度小於30個字元)");
scanf("%s",ch);
for(i=5;i<number;i++)
{
if(strcmp(cpt[i].player,ch)==0)
{
printf("這個用戶已被注冊過!注冊失敗!請重新注冊!\n");
goto loop2;
}
}
strcpy(cpt[number].player,ch);
cpt[number].score=100;
cpt[number].time=cpt[number].times=1;
number+=1;
writefile();
printf("注冊成功!請登錄並在您的用戶下進行游戲!:");
goto loop4;
}
else if(strcmp("entry",ch)==0)
{
printf("請輸入用戶名登錄:");
scanf("%s",ch);
for(i=5;i<number;i++)
{
if(strcmp(cpt[i].player,ch)==0)
{
printf("登錄成功!\n");
printf("您將在您的用戶下進行游戲。!");
break;
}
}
if(i==number)
{
printf("輸入錯誤或沒有注冊或該用戶由於輸光金幣已被系統刪除!\n請重新輸入用戶名登錄!");
goto loop4;
}
}
else
{
printf("您輸入的不是「register」也不是「entry」,系統無法執行您的命令,請重新輸入:\n");
goto loop3;
}
return(i);
}
/*********************************************************************************************************************************/
void game() //游戲和查詢的主體函數
{
int o,p;
char a[10],wether[1];
if(cpt[rool].time==1)printf("本局游戲系統將免費贈予您100枚金幣。\n");
if(cpt[rool].score<5&&cpt[rool].times<=5)
{
if(cpt[rool].times<5)
{
printf("您的積分已少於5分,系統第%d次贈送你30枚金幣\n",cpt[rool].times);
}
else
{
printf("您的積分已少於5分,系統最後一次贈送你30枚金幣!\n");
}
cpt[rool].score+=30;
cpt[rool].times+=1;
game();
}
if(cpt[rool].score==0)
{
int q;
printf("您不能在沒有積分的狀態下游戲!你的用戶將被刪除,如果您還想繼續游戲,請重新申請用戶\nGAME OVER!\n");
for(q=rool;q<number-1;q++)
{
strcpy(cpt[q].player,cpt[q+1].player);
cpt[q].time=cpt[q+1].time;
cpt[q].times=cpt[q+1].times;
cpt[q].score=cpt[q+1].score;
}
number-=1;
writefile();
return;
}
else
{
printf("是否繼續游戲,輸入『y』或『Y』繼續游戲\n");
scanf("%s",wether);
if(strcmp("y",wether)!=0 && strcmp("Y",wether)!=0)
{
printf("GAME STOP");
return;
}
else
{
loop1:
printf("請輸入你對本局游戲的押金或輸入'N'或『n』查詢積分排名\n");
loop5:
scanf("%s",a);
/****************************************************************************************************************************************************/
if(a[0]=='n'||a[0]=='N') //查尋排名
{
int i[5]={-1,-1,-1,-1,-1},j,k,d=0,e=0,line=-1;
for(k=1;k<=5;k++)
{
for(d=0;d<5;d++)
{
if(d!=i[0]&&d!=i[1]&&d!=i[2]&&d!=i[3]&&d!=i[4])break;
}
for(j=0;j<number;j++)
{
if(cpt[j].score>=cpt[d].score&&j!=i[0]&&j!=i[1]&&j!=i[2]&&j!=i[3]&&j!=i[4])d=j;
}
i[k-1]=d;
if(d==rool)
{
line=k;
}
printf("\n玩家:%10s,金幣數:%4d,",cpt[d].player,cpt[d].score);
b(cpt[d].score);
}
if(line!=-1)
{
printf("\n\n您目前的積分為:%d,\n排名為:%d,\n",cpt[rool].score,line);
b(cpt[rool].score);
printf("\n\n");
}
else
{
printf("\n\n您目前的積分為:%d,\n沒有進入前5名\n",cpt[rool].score);
b(cpt[rool].score);
printf("\n\n");
}
game();
}
/*****************************************************************************************************************************************************/
else //玩游戲
{
int g=0,le=strlen(a);
for(;g<le;g++)
{
if(!(a[g]>='0'&&a[g]<='9'))
{
printf("你輸入了游戲系統無法識別的字元,請重新輸入:");
break;
}
}
if(g<le)
{
goto loop5;
}
int money=str_to_num(a);
if(money==0)
{
printf("押金不能為『0』,請重新輸入:");
goto loop5;
}
if(money<0)
{
printf("押金不能為負數,請重新輸入:");
goto loop5;
}
printf("和您進行本輪游戲的是系統玩家player%d。\n",(cpt[rool].time-1)%5+1);
if(cpt[(cpt[rool].time-1)%5].score<5)
{
cpt[(cpt[rool].time-1)%5].score+=50;
printf("你的對手的金幣小於5個,系統贈送你的對手50枚金幣\n");
}
printf("您設定的押金為%d\n",money);
if(money>cpt[rool].score)
{
printf("抱歉,您的金幣不足!請重新輸入!\n");
goto loop1;
}
if(money>cpt[(cpt[rool].time-1)%5].score)
{
printf("抱歉,您的對手金幣不足!請重新輸入!\n");
goto loop1;
}
if(1>0)
{
printf("游戲開始,請出拳!(1表示石頭,2表示剪刀,3表示布)");
scanf("%d",&o);
p=h();
switch(o)
{
case 1:
{
printf("玩家出拳:石頭\n");
break;
}
case 2:
{
printf("玩家出拳:剪子\n");
break;
}
case 3:
{
printf("玩家出拳:布\n");
break;
}
}
switch(p)
{
case 1:
{
printf("系統出拳:石頭\n");
break;
}
case 2:
{
printf("系統出拳:剪子\n");
break;
}
case 3:
{
printf("系統出拳:布\n");
break;
}
}
switch(o-p)
{
case 0 :
{
printf("平局!系統將不改變你的金幣數量,你的余額為:%d\n",cpt[rool].score);
break;
}
case 1 :
case -2:
{
printf("你輸了,系統將扣除你%d個金幣,你的余額為:%d\n",money,cpt[rool].score-money);
cpt[rool].score-=money;
cpt[(cpt[rool].time-1)%5].score=cpt[(cpt[rool].time-1)%5].score+money;
break;
}
case -1:
case 2 :
{
printf("你贏了,系統將給予你%d個金幣,你的余額為:%d\n",money,cpt[rool].score+money);
cpt[rool].score+=money;
cpt[(cpt[rool].time-1)%5].score=cpt[(cpt[rool].time-1)%5].score-money;
break;
}
}
cpt[rool].time+=1;
writefile();
}
game();
}
}
}
}
main() //主函數
{
srand( (unsigned)time(0) );
number=readfile();
rule();
rool=registe();
game();
}
『拾』 編寫猜拳游戲
這個可以了吧!呵呵,應該夠詳細了
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int random(int maxlim);
int judgewin(char h1,char h2);
void disphand(char h);
void main()
{
char man,computer;
char wantplay;
//重置隨機數序列
srand( (unsigned)time( NULL ) );
printf("-----------猜 拳--------------\n");
do
{
//您出拳
while(1)
{
printf("您出什麼拳?(1--石頭 2--剪子 3--布):");
man=getche();
if(man<'1'||man>'3')
printf("您出的不是拳!\n");
else
break;
}
//顯示您出的拳
printf("\n您出的是");
disphand(man);
printf("\n");
//電腦出拳
computer=random(3) + '1';
//顯示電腦出的拳
printf("我出的是");
disphand(computer);
printf("\n");
//判斷勝負
switch(judgewin(man,computer))
{
case 0://平
printf("不分勝負\n");
break;
case 1://您贏
printf("唉! 我輸了。\n");
break;
case -1://電腦贏
printf("哈哈! 我贏了。\n");
break;
}
printf("還玩嗎?(Y/N)");
wantplay=getche();
printf("\n\n");
}while(wantplay=='y'||wantplay=='Y');
}
//產生0到maxlim之間的隨機數
int random(int maxlim)
{
float number;
number=((float)rand()/RAND_MAX)*maxlim;
return((int)number);
}
//判斷h1和h2的勝負
int judgewin(char h1,char h2)
{
if(h1==h2)
return 0;//peace
else if( (h1=='1'&&h2=='2') // h1出石頭,h2出剪子
||(h1=='2'&&h2=='3') //或者h1出剪子,h2出布
||(h1=='3'&&h2=='1') ) //或者h1出布 ,h2出石頭
return 1;//h1 win
else
return -1;//h2 win
}
//根據h的值顯示"石頭"、"剪子"、"布"
void disphand(char h)
{
switch(h)
{
case '1':
printf("石頭");
break;
case '2':
printf("剪子");
break;
case '3':
printf("布");
break;
}
}