资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

老虎棒子鸡java代码 老虎棒子鸡java代码是多少

求大神解决,用java程序回答。。

CardPlayer.java(出牌类)

创新互联是一家专业提供揭东企业网站建设,专注与网站设计、成都网站制作、HTML5、小程序制作等业务。10年已为揭东众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

public class CardPlayer {

public int XSXchoose = (int)(Math.random()*3+1);

public String XSXCPName;

//显示出的牌

public String XSXcard(int XSXcard){

if (XSXcard==1) {

return "老虎";

}else if(XSXcard==2){

return "棒子";

}else if(XSXcard==3){

return "虫子";

}else if(XSXcard==4){

return "鸡";

}

return "";

}

public void XSXplayer(String XSXPname,String XSXCName,int XSXplayerA,int XSXplayerB){

if ((XSXplayerA==1XSXplayerB==3)||(XSXplayerA==1XSXplayerB==4)

||(XSXplayerA==2XSXplayerB==1)||(XSXplayerA==2XSXplayerB==4)

||(XSXplayerA==3XSXplayerB==2)||(XSXplayerA==4XSXplayerB==3)) {

System.out.println("玩家"+XSXPname+"赢了!");

}else if((XSXplayerA==1XSXplayerB==2)||(XSXplayerA==2XSXplayerB==3)

||(XSXplayerA==3XSXplayerB==1)||(XSXplayerA==3XSXplayerB==4)

||(XSXplayerA==4XSXplayerB==1)||(XSXplayerA==4XSXplayerB==2)){

System.out.println("电脑"+XSXCName+"赢了!");

}else{

System.out.println("电脑"+XSXCName+"和玩家"+XSXPname+"打平了! ");

}

}

}

player.java(玩家类)

public class player {

public String XSXPlaerMame;

}

Test.java(主类)

import java.util.Scanner;

public class Test {

private static CardPlayer cp = new CardPlayer();

private static player p = new player();

private static void XSXPlayerInput(){

String SXSCPayerName = "BaShenAn"; //设置电脑名字

cp.XSXCPName = SXSCPayerName;

String SXSPlayer = "LiXiaoyao"; //设置玩家名字

p.XSXPlaerMame = SXSPlayer;

System.out.println("请输入你的选择:");

System.out.print("1.老虎 2.棒子 3.虫子 4.鸡(输入1-4之间的数进行选择!)");

String SXSInput=new Scanner(System.in).next();

if(SXSInput.equalsIgnoreCase("1")||SXSInput.equalsIgnoreCase("2")

||SXSInput.equalsIgnoreCase("3")||SXSInput.equalsIgnoreCase("4")){

int XSXChoose=cp.XSXchoose;

System.out.println("电脑"+cp.XSXCPName+"出的是:"+cp.XSXcard(XSXChoose));

System.out.println("玩家"+p.XSXPlaerMame+"出的是:"+cp.XSXcard(Integer.parseInt(SXSInput)));

cp.XSXplayer(p.XSXPlaerMame, cp.XSXCPName, Integer.parseInt(SXSInput), XSXChoose);

}else{

System.out.println("你的输入不正确,请重新输入!\n");

XSXPlayerInput();

}

}

private static void playGame(){

System.out.print("是否继续游戏(y/n)!");

String XSXChoose=new Scanner(System.in).next();

if (XSXChoose.equalsIgnoreCase("y")) {

System.out.print("\n");

XSXPlayerInput();

playGame();

}else if(XSXChoose.equalsIgnoreCase("n")){

System.out.println("游戏结束!");

}else{

System.out.println("你的输入不正确,请重新输入!\n");

playGame();

}

}

public static void main(String[] args) {

XSXPlayerInput();

playGame();

}

}

老虎棒子鸡游戏规则

一个克制一个

老虎吃鸡

鸡吃虫子

虫子蛀杠子

杠子打老虎

形成一个完美循环

无克制类别的直接地平不分胜负

比如

老虎和虫子

杠子和鸡

都是平局

继续出直到胜负位置

值得一提的是

这是个俩人之间对抗的游戏

超出就无法定出胜负了

“老虎棒子鸡”是怎么个玩法?

1、全名:棒打老虎鸡吃虫

2、玩法:棒打老虎鸡吃虫是一种趣味游戏,两人进行该游戏,边敲打棍子,一边按照敲打棍子的节奏,边喊“棒打老虎鸡吃虫”,喊完后,两个人稍微大力的敲著对方的棍子,然后喊出虫、棒子、老虎、鸡其中一项。

3、输赢判断方法如下:

(1)虫可以蛀棒子,也就是虫赢棒子;棒子可以打老虎,也就是棒子赢老虎;老虎可以吃鸡,也就是老虎赢鸡;鸡可以吃虫,也就是鸡赢虫。

(2)如果双方同时喊出一样的动物或物品,或者是非上述的致胜关键,则判定双方平局,还要再喊一次。例如A方喊棒子,B方喊鸡,平局并再重复一次固定台词,并再猜。

/iknow-pic.cdn.bcebos.com/d31b0ef41bd5ad6eabf305208dcb39dbb7fd3cf5"target="_blank"title="点击查看大图"class="ikqb_img_alink"/iknow-pic.cdn.bcebos.com/d31b0ef41bd5ad6eabf305208dcb39dbb7fd3cf5?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto"esrc=""/

拓展知识:

1、在我国的西北等地区,在酒桌上也有用此类方法来划拳,裁定方法为棒子打老虎,老虎吃鸡,鸡吃虫子,虫子会蛀棒,通常为两人进行,比如一方喊老虎,另一方喊棒子。则喊老虎的人喝酒,如果另一方喊鸡的话那就得喝酒,流传于我国西北地区,酒桌上的一种即兴划拳法。

2、棒打老虎、老虎吃鸡、鸡吃虫、虫吃棒的游戏类似于剪刀石头布。

到底什么是老虎棒子鸡?

跟石头剪子布一样,老虎吃鸡,鸡吃虫子,虫子琢棒子,棒子打老虎。玩的时候两人先同时说老虎老虎然后再说出自己要说的选项,然后根据规则看谁赢了。

求棒子老虎鸡的编程,只要java的,新人刚学,不要太难了

import java.util.Scanner;

/**

* 2015年9月16日下午1:20:36

* @author cs12110 TODO 建立老虎棒子鸡的游戏

*/

public class EatGeam {

/*

 * 声明控制台输入对象

 */

private static Scanner input = new Scanner(System.in);

/*

 * 初始化手法

 */

private static String[] actor = { "老虎", "鸡", "虫子", "棒子" };

/**

 * 根据下标获取出的手法

 * 

 * @param index

 *            手法下标

 * @return 返回手法

 */

public static String getOrder(int index) {

return index = 0  index  actor.length ? actor[index] : actor[0];

}

/**

 * 判断出手双方的结果

 * 

 * @param yourAttack

 *            你的出手

 * @param computerAttack

 *            电脑的出手

 * @return 返回相关信息

 */

public static String isYouWin(int yourAttack, int computerAttack) {

if (3 == computerAttack  0 == yourAttack) {

return "您输了";

}

if (yourAttack == computerAttack - 1) {

return "您赢了";

}

return "双方平局";

}

public static void main(String[] args) {

System.out.println("\n-----------现在轮到您出手了----------\n");

System.out.print("0: 老虎  1:鸡 2:虫子 3:棒子\nInput: ");

int yourindex = input.nextInt();

int computerIndex = (int) (Math.random() * actor.length);// 电脑随机出手

String result = isYouWin(yourindex, computerIndex);

System.out.println("\n结果: 你的出手: " + getOrder(yourindex) + "  电脑出手: "

+ getOrder(computerIndex) + "\n" + result);

}

}


分享文章:老虎棒子鸡java代码 老虎棒子鸡java代码是多少
本文来源:http://cdkjz.cn/article/doopcpj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220