首页 > 电脑 > JAVA求一个含有登陆注册的猜拳游戏代码

JAVA求一个含有登陆注册的猜拳游戏代码

电脑 2023-04-21

用java编写一个猜拳游戏

importjava.util.Scanner;
publicclassGame{
privateScannerscan=newScanner(System.in);
privateStringrule[]={"","剪刀","石头","布"};
privateStringrole[]={"","刘备","孙权","曹操"};
privateComputercomputer;
privateUseruser;
privateintroundCount;
privateGame(){
roundCount=0;
}
publicstaticvoidmain(String[]args){
Gamegame=newGame();
game.start();
}
publicvoidstart(){
computer=newComputer();
System.out.println("--欢迎进入游戏世界--");
System.out.println("********************");
System.out.println("**猜拳,开始**");
System.out.println("********************");
System.out.println();
System.out.println("出拳规则:1.剪刀2.石头3.布");
System.out.print("请选择角色(1:刘备2.孙权3.曹操)");
intuserRole=scan.nextInt();
if(userRole>=1&&userRole<=3){
user=newUser(role[userRole]);
System.out.println();
System.out.print("要开始吗?(y/n)");
Stringstart=scan.next();
if(start.equals("y")){
round();
}
elseif(start.equals("n")){

}
}
}
privatevoidround(){
roundCount++;
System.out.println();
System.out.print("请出拳:1.剪刀2.石头3.布(输入相应数字):");
intuserRule=user.round();
if(userRule>=1&&userRule<=3){
intcomputerRule=computer.round();
judge(userRule,computerRule);
System.out.println();
System.out.print("是否开始下一轮(y/n):");
Stringnext=scan.next();
if(next.equals("y")){
round();
}
elseif(next.equals("n")){
end();
}
}
}
privatevoidjudge(intur,intcr){
System.out.println("你出拳:"+rule[ur]);
System.out.println("电脑出拳:"+rule[cr]);
if(ur==cr){
System.out.println("结果:和局,真衰!嘿嘿,等着瞧吧!");
}
elseif((ur==1&&cr==3)||
(ur==2&&cr==1)||
(ur==3&&cr==2)){
System.out.println("结果:你赢了!");
user.win();
}
else{
System.out.println("结果:你输了!");
computer.win();
}
}
privatevoidend(){
System.out.println("--------------------------------------");
System.out.println(user.getName()+"VS"+computer.getName());
System.out.println("对战次数:"+roundCount);
if(computer.getWin()==user.getWin()){
System.out.println("结果:打成平手,下次再和你一分高下!");
}
elseif(computer.getWin()>user.getWin()){
System.out.println("结果:你输了!电脑赢了"+computer.getWin()+"次!");
}
else{
System.out.println("结果:你赢了!你赢了"+user.getWin()+"次!");
}
System.out.println("--------------------------------------");
}
classComputer{
privateintwin;
privateStringname;
publicComputer(){
win=0;
name="匿名";
}
publicintround(){

return(int)(System.currentTimeMillis()%3)+1;//随机返回1、2、3
}
publicStringgetName(){
returnname;
}
publicvoidwin(){
win++;
}
publicintgetWin(){
returnwin;
}
}
classUser{
privateintwin;
privateStringname="";
publicUser(Stringname){
this.name=name;
win=0;
}
publicintround(){
returnscan.nextInt();
}
publicStringgetName(){
returnname;
}
publicvoidwin(){
win++;
}
publicintgetWin(){
returnwin;
}
}
}

刚刚写好的,应该满足你的题目要求。赢了和输了的提示信息题目里没有是我自己随便写的。

求java 猜拳游戏代码!

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; public class FingerGuessing { private String[] op = new String[] { "布", "剪刀", "石头" }; Random r = new Random(); private int wj = 0; private int dn = 0; private int count = 0; private

java代码猜拳游戏相关代码请教

comp是电脑产生的随机数字(电脑出的拳),people 是人出的拳。 因为剪刀石头布只有 1 2 3 。如果电脑的数字比的你刚好大1,就是它比你的大。 如2>1,3>2对应就是(石头大于剪刀,布大于石头)。 但也有可能是剪刀大于布 。 那么剪刀的位子是1 ,布的位子是3. 所以当电脑数字减你的数字等于2时 就是(电脑出的布 ,你出的石头这样的情况了)。 所以是if((comp-people)==-1||(comp-people)==2) 这两者结合就是你赢的时候

在学习java期间如何利用java制作一个简单的猜拳游戏编程?

importjava.util.Scanner;

publicclassGame{
privateScannerscan=newScanner(System.in);
privateStringrule[]={"","剪刀","石头","布"};
privateStringrole[]={"","刘备","孙权","曹操"};
privateComputercomputer;
privateUseruser;
privateintroundCount;
privateGame(){
roundCount=0;
}
publicstaticvoidmain(String[]args){
Gamegame=newGame();
game.start();
}
publicvoidstart(){
computer=newComputer();
System.out.println("--欢迎进入游戏世界--");
System.out.println("********************");
System.out.println("**猜拳,开始**");
System.out.println("********************");
System.out.println();
System.out.println("出拳规则:1.剪刀2.石头3.布");
System.out.print("请选择角色(1:刘备2.孙权3.曹操)");
intuserRole=scan.nextInt();
if(userRole>=1&&userRole<=3){
user=newUser(role[userRole]);
System.out.println();
System.out.print("要开始吗?(y/n)");
Stringstart=scan.next();
if(start.equals("y")){
round();
}
elseif(start.equals("n")){

}
}
}
privatevoidround(){
roundCount++;
System.out.println();
System.out.print("请出拳:1.剪刀2.石头3.布(输入相应数字):");
intuserRule=user.round();
if(userRule>=1&&userRule<=3){
intcomputerRule=computer.round();
judge(userRule,computerRule);
System.out.println();
System.out.print("是否开始下一轮(y/n):");
Stringnext=scan.next();
if(next.equals("y")){
round();
}
elseif(next.equals("n")){
end();
}
}
}
privatevoidjudge(intur,intcr){
System.out.println("你出拳:"+rule[ur]);
System.out.println("电脑出拳:"+rule[cr]);
if(ur==cr){
System.out.println("结果:和局,真衰!嘿嘿,等着瞧吧!");
}
elseif((ur==1&&cr==3)||
(ur==2&&cr==1)||
(ur==3&&cr==2)){
System.out.println("结果:你赢了!");
user.win();
}
else{
System.out.println("结果:你输了!");
computer.win();
}
}
privatevoidend(){
System.out.println("--------------------------------------");
System.out.println(user.getName()+"VS"+computer.getName());
System.out.println("对战次数:"+roundCount);
if(computer.getWin()==user.getWin()){
System.out.println("结果:打成平手,下次再和你一分高下!");
}
elseif(computer.getWin()>user.getWin()){
System.out.println("结果:你输了!电脑赢了"+computer.getWin()+"次!");
}
else{
System.out.println("结果:你赢了!你赢了"+user.getWin()+"次!");
}
System.out.println("--------------------------------------");
}
classComputer{
privateintwin;
privateStringname;
publicComputer(){
win=0;
name="匿名";
}
publicintround(){

return(int)(System.currentTimeMillis()%3)+1;//随机返回1、2、3
}
publicStringgetName(){
returnname;
}
publicvoidwin(){
win++;
}
publicintgetWin(){
returnwin;
}
}
classUser{
privateintwin;
privateStringname="";
publicUser(Stringname){
this.name=name;
win=0;
}
publicintround(){
returnscan.nextInt();
}
publicStringgetName(){
returnname;
}
publicvoidwin(){
win++;
}
publicintgetWin(){
returnwin;
}
}
}

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;
}
}
publicclassShiTouJiandaoBu{
/**
*@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);
}
}

就帮你到这吧


标签:信息技术 编程 Java编程 Java 猜拳

大明白知识网 Copyright © 2020-2022 www.wangpan131.com. Some Rights Reserved. 京ICP备11019930号-18