求大神解决,用java程序回答 。。CardPlayer.java(出牌类)
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();
}
}
谁用java做过麻将简单的说一下,页面这个没问题 。swing 。
就是业务逻辑方面的,
业务逻辑我感觉一步一步的来,也不会太难 。
首先,分牌,这个设个list链表,里面包含麻将所有的对象,随机分配 。
第二出牌,一人一张,设个标记位,4个线程,一个出牌之后改标记位让下一个线程运行 。
第三判断,手下判断是否胡了,然后再判断是否杠上,然后判断 。。。。。
当然,实际做的过程中会很多未知的问题,慢慢做吧 。
其实解决这些未知的问题才是收获最大的地方 。
高分急求java扑克出牌代码我不知道电脑出牌为什么要进行大小比较以及删牌操作? 我的是52张牌若干玩家,随机发牌给玩家,玩家收到电脑发的牌 。
这个是定义52张牌:Card.java
package com.etc.week4.day03;
public class Card {
//点数3---04112211 A13 小王 14 大王
【java出牌代码 纸牌游戏java代码】public int rank;
public final static int THREE = 0;
public final static int FOUR = 1;
public final static int FIVE = 2;
public final static int SIX = 3;
public final static int SEVEN = 4;
public final static int EIGHT = 5;
public final static int NINE = 6;
public final static int TEN = 7;
public final static int JACK = 8;//J
public final static int QUEEN = 9;//Q
public final static int KING = 10;//K
public final static int ACE = 11;//A
public final static int DEUCE = 12; //2
public final static int BLACK = 13; //小王
public final static int COLOR = 14;//大王
//花色(suit=0suit=4)
private int suit;
public final static int CLUB = 0; //梅花
public static final int DIAMOND = 1; //方块(钻石)
public static final int HEART = 2; //红桃(红心)
public static final int SPADE = 3; //黑桃(花锄)
public static final int JOKER = 4; //王
public Card(int suit,int rank){
this.setSuit(suit);
this.setRank(rank);
}
public Card(){}
public int getRank() {
return rank;
}
public void setRank(int rank) {
if(rankCard.THREE||rankCard.COLOR){
throw new RuntimeException();
}
this.rank = rank;
}
public int getSuit() {
return suit;
}
public void setSuit(int suit) {
if(suitCard.CLUB || suitCard.JOKER){
thrownew RuntimeException();
}
this.suit = suit;
}
// 点数对应 名称
public final static String[] RANK_NAMES={
"3","4","5","6","7","8","9","10","J","Q",
"K","A","2","小王","大王"};
public final static String[] SUIT_NAMES={
"梅花","方块","红桃","黑桃",""};
@Override
public String toString() {
return SUIT_NAMES[this.suit] RANK_NAMES[this.rank];
}
public static void main(String[] args) {
Cardc=new Card(HEART, ACE);
System.out.println(c);
}
}
这个是定义若干玩家Player.java
package com.etc.week4.day03;
import java.util.Arrays;
public class Player {
String id;
String name;
Card cards[] ={};
public void addCards(Card card ){
// 每个玩家获取的牌
cards = Arrays.copyOf(cards, cards.length 1);
cards[cards.length-1] = card;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Card[] getCards() {
return cards;
}
public void setCards(Card[] cards) {
this.cards = cards;
}
public Player(String id, String name) {
this.id = id;
this.name = name;
}
public Player() {
super();
}
@Override
public String toString() {
return "Player:" name "cards="
Arrays.toString(cards)"]";
}
}
这个是电脑随机发牌给玩家 , 玩家收到电脑发的牌PlayDemo.java
package com.etc.week4.day03;
import java.util.Arrays;
import java.util.Random;
public class PlayerDemo {
public static void main(String[] args) {
//创建一副扑克牌
//方块:13张(THREE~DEUCE)
//梅花:13张(THREE~DEUCE)
//黑桃:13张(THREE~DEUCE)
//红桃:13张(THREE~DEUCE)
//王: BLACK COLOR
Card [] cards = new Card[54];
int i=0;
//构造52张普通的牌
for(int rank=Card.THREE;rank=Card.DEUCE;rank){
cards[i] = new Card(Card.DIAMOND, rank);
cards[i] = new Card(Card.CLUB, rank);
cards[i] = new Card(Card.SPADE, rank);
cards[i] = new Card(Card.HEART, rank);
}
// 添加 大小王
cards[i] = new Card(Card.JOKER, Card.BLACK);
cards[i] = new Card(Card.JOKER, Card.COLOR);
//将数组 变成集合 List
//List arr= Arrays.asList(cards);
//将集合里面的元素打乱...洗牌
//Collections.shuffle(arr);
//洗牌//
for(int n=cards.length-1;n=1;n--){
Random rd = new Random();
int index =rd.nextInt(n); //10
Card t = cards[n];
cards[n] = cards[index];
cards[index] = t;
}
// System.out.println("=====测试洗牌.....\n" Arrays.toString(cards));
// 组建玩家团队
Player[] players = new Player[4];
players[0]= new Player("1010", "张柏芝");
players[1]= new Player("1011", "曾志伟");
players[2]= new Player("1012", "谭咏麟");
// players[3]= new Player("1013", "郭德纲");
//发牌.....
for(int j =0;jcards.length;j){
players[j%players.length].addCards(cards[j]);
}
//显示各个玩家的牌
for(int m=0;mplayers.length;m){
System.out.println(players[m]);
}
}
}
java21点有没有好心人 , 可以在这段代码后面加一些注释啊 。包week01;
进口java.awt.color;
进口java.awt.font;
进口java.awt.event.actionevent;
进口java.awt.event.actionlistener;
进口javax.swing.jbutton;
进口javax.swing.jframe;
进口javax.swing.jlabel;
进口javax.swing.joptionpane;
进口javax.swing.swingconstants;
进口javax.swing.border.lineborder;
公共课game21扩展JFrame {
私人JLabel label_2;
私有变量数;
私有变量和;
最后的JLabel标签=新jlabel();
最后label_1 =新jlabel() JLabel;
public static void main(String [] args){
新的game21();
}
公共game21() {
超(21点?!”);
getcontentpane() setLayout(null);
这个setdefaultcloseoperation(JFrame 。exit_on_close);
最后jbutton() JButton按钮=新;
按钮 。addactionlistener(新actionlistener() {
public void actionPerformed(最终ActionEvent arg0){
onclick();
}
});
按钮设置(“出牌”);
按钮 。窗口(170,350,106,28);
getcontentpane()添加(按钮);
标签 。setborder(新lineborder(color.blue,1,假));
标签 。sethorizontalalignment(swingconstants 。中心);
标签 。设置字体(新字体(“” , font.bold,26));
标签设置(“背面”);
标签窗口(158,81,137,153);
getcontentpane()添加(标签);
label_1 。setText(“你已经拥有的牌:”);
label_1 。窗口(109,22,270,45);
getcontentpane()添加(label_1);
这个窗口(200,300,501,528);
这个show(真的);
getcontentpane()添加(getlabel_2());
}
公共randnumber() { int
尝试{
线程 。睡眠(10);
} catch(InterruptedException e){
E. printstacktrace();
}
返回(int)(数学 。()* 101);
}
onclick() { public void
这randnumber()数量=;
this.sum=数量;
标签设置(“ 号);
字符串strtemp =这 。label_1 。gettext();
strtemp=” 数字 ”;
label_1 setText(strtemp);
字符串=“合计:” 笔;
label_2 setText(温度);
iswin();
}
iswin() { public void
如果(总和 21){
showmessagedialog JOptionPane 。(这个,”你输了”);
clear();
返回;
}如果(和= 21)
showmessagedialog JOptionPane 。(这个,”你赢了”);
clear();
返回;
其他{ }
int i = JOptionPane 。showoptiondialog(这个 , ”是否继续?”、“提示”,
joptionpane.ok_cancel_option,
joptionpane.information_message,空 , 空,空的);
如果(我= = JOptionPane 。ok_option){
onclick();
}其他
返回;
}
}
clear() { private void
label_2 。setText(“合计:”);
总和= 0;
号码= 0;
label_1 。setText(“你已经拥有的牌:”);
}
/ * *
*归
* /
保护带getlabel_2() {
如果(label_2 = = null){
label_2 =新jlabel();
label_2 。setText(“合计:”);
label_2 。窗口(313 , 35,66,18);
}
返回label_2;
}
}
直接翻译的 。
java出牌代码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于纸牌游戏java代码、java出牌代码的信息别忘了在本站进行查找喔 。
推荐阅读
- flutter上传图片到django,flutter 上传文件
- flutter监听页面显示,flutter 监听返回
- 怎么mysql服务器配置 mysql server配置
- 下载图片怎么导入电脑硬盘,如何下载图片到电脑桌面
- SQLServer中数据库设置多个主健,sql server设置两个主键
- 直播伴侣导播,直播伴侣导播怎么连主播
- php数据文件太大 php 文件数量
- 如何看待京东品牌营销,京东营销策略分析优缺点及对策
- 广告拍摄用什么手法,广告拍摄要点