第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

我的撲克牌代碼,不完整版

//創(chuàng)建卡牌對(duì)象類
public?class?Card?implements?Comparable<Card>?{
?
?private?String?shape;
?private?String?id;
?
?@Override
?public?int?hashCode()?{
??final?int?prime?=?31;
??int?result?=?1;
??result?=?prime?*?result?+?((id?==?null)???0?:?id.hashCode());
??return?result;
?}

?@Override
?public?boolean?equals(Object?obj)?{
??if?(this?==?obj)
???return?true;
??if?(obj?==?null)
???return?false;
??if?(getClass()?!=?obj.getClass())
???return?false;
??Card?other?=?(Card)?obj;
??if?(id?==?null)?{
???if?(other.id?!=?null)
????return?false;
??}?else?if?(!id.equals(other.id))
???return?false;
??return?true;
?}

?public?Card(){
??
?}
?
?public?Card(String?shape,?String?id)?{
??//super();
??this.shape?=?shape;
??this.id?=?id;
?}

?public?String?getShape()?{
??return?shape;
?}
?public?void?setShape(String?shape)?{
??this.shape?=?shape;
?}
?public?String?getId()?{
??return?id;
?}
?public?void?setId(String?id)?{
??this.id?=?id;
?}

?@Override//重寫了卡牌中花色與序號(hào)的排序方法
?public?int?compareTo(Card?o)?{
??//?TODO?Auto-generated?method?stub
??//return?o.getId().compareTo(this.getId());
??String[]?num?=?{"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
??String[]?color?=?{"黑桃","紅桃","梅花","方片"};
??int?n1?=?0,n2=0,o1=0,o2=0;
??for(int?i=0;i<num.length;i++){
??if(this.getId().equals(num[i]))
???n1=i;
??if(o.getId().equals(num[i]))
???n2=i;}
??for(int?i=0;i<color.length;i++){
???if(this.getShape().equals(color[i]))
????o1=i;
???if(o.getShape().equals(color[i]))
????o2=i;}
??
??if(n1>n2){
???return?1;}
???else?if(n1<n2){
????return?-1;
???}else{
????if(o1>o2){
?????return?-1;
????}else?if(o1<o2){
?????return?1;
????}else?
?????return?0;
???}
?}
?
?public?Card?getCards()?{
??//?TODO?Auto-generated?method?stub
??return?null;
?}
}
import?java.util.ArrayList;
import?java.util.List;


//創(chuàng)建玩家類
public?class?Player?{
?private?String?name?;
?private?List<Card>?cards;
?private?String?ID;
?
?public?void?Player(){
??
?}
?public?List<Card>?getCards()?{
??return?cards;
?}
?public?Player(String?name,?String?iD)?{
??//super();
??this.name?=?name;
??this.cards?=?new?ArrayList<Card>();
??
??ID?=?iD;
?}

?public?void?setCards(List<Card>?cards)?{
??this.cards?=?cards;
?}
?public?String?getName()?{
??return?name;
?}

?public?void?setName(String?name)?{
??this.name?=?name;
?}


?public?String?getID()?{
??return?ID;
?}

?public?void?setID(String?iD)?{
??ID?=?iD;
?}
}

import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.List;
import?java.util.Scanner;



public?class?PaiTest?{
?
?public?List<Card>?cardList;
?
?public?PaiTest(){
??
??this.cardList?=?new?ArrayList<Card>();
?}
?//創(chuàng)建撲克牌的方法
?public?void?purcard(){
??
??String[]?sh=?{"方片","黑桃","紅桃","梅花"};
??Card?cars?=?new?Card();
??//第一個(gè)循環(huán)是創(chuàng)建4個(gè)花色,第二個(gè)循環(huán)創(chuàng)建每種花色的大小
??for(int?i=0;i<4;i++){
???cars.setShape(sh[i]);
????for(?int?j=2;j<15;j++){
???if(j==11){
????cars.setId("J");
????cardList.add(new?Card(sh[i],"J"));
????System.out.println("添加了卡牌:"+cars.getShape()+cars.getId());
????continue;
???}
???if(j==12){
????cars.setId("Q");
????cardList.add(new?Card(sh[i],"Q"));
????System.out.println("添加了卡牌:"+cars.getShape()+cars.getId());
????continue;
???}
???if(j==13){
????cars.setId("K");
????cardList.add(new?Card(sh[i],"K"));
????System.out.println("添加了卡牌:"+cars.getShape()+cars.getId());
????continue;
???}
???if(j==14){
????cars.setId("A");
????cardList.add(new?Card(sh[i],"A"));
????System.out.println("添加了卡牌:"+cars.getShape()+cars.getId());
????continue;
???}
???cars.setId(j+"");
???System.out.println("添加了卡牌:"+cars.getShape()+cars.getId());
???cardList.add(new?Card(sh[i],j+""));
??}
??}
??System.out.println("卡牌創(chuàng)建成功--------------------");
??for(Card?card:cardList)
???System.out.println("輸出卡牌:"+cardList.size()+card.getShape()+"???"+card.getId());
?
?}
?public?void?fapai(){
??Scanner?sc?=?new?Scanner(System.in);
??System.out.println("請(qǐng)輸入玩家一的姓名:");
??String?p1?=?sc.next();
??Player?play1?=?new?Player(p1,?"1");
??System.out.println("玩家:"+p1+"成功進(jìn)入游戲");
??System.out.println("請(qǐng)輸入玩家二的姓名:");
??String?p2?=?sc.next();
??Player?play2?=?new?Player(p2,?"2");
??System.out.println("玩家:"+p2+"成功進(jìn)入游戲");
??Collections.shuffle(cardList);//打亂集合中的元素
??System.out.println(cardList.get(0).getShape()+cardList.get(0).getId());//打亂集合輸出的第一個(gè)元素
??play1.getCards().add(cardList.get(0));//依次給玩家發(fā)牌
??play2.getCards().add(cardList.get(1));
??play1.getCards().add(cardList.get(2));
??play2.getCards().add(cardList.get(3));
??Collections.sort(play1.getCards());//對(duì)玩家1的手牌排序
??Collections.sort(play2.getCards());//對(duì)玩家2的手牌排序
??for(Card?card:play1.getCards())
??System.out.println("玩家1的卡牌為:"+card.getShape()+card.getId());
??System.out.println("最大點(diǎn)數(shù)為:"+play1.getCards().get(1).getShape()+play1.getCards().get(1).getId());
??for(Card?card:play2.getCards())
???System.out.println("玩家2的卡牌為:"+card.getShape()+card.getId());
??System.out.println("最大點(diǎn)數(shù)為:"+play2.getCards().get(1).getShape()+play2.getCards().get(1).getId());
??//利用comparable排序
??List<Card>?newlist?=?new?ArrayList<Card>();//創(chuàng)建新的集合,把玩家1和2的手牌放入
??newlist.addAll(?play1.getCards());
??newlist.addAll(?play2.getCards());
??
??System.out.println("-----------------排序前:");
??for(Card?st:newlist)
???System.out.println("排序前:"+st.getShape()+st.getId());
??//Collections.sort(newlist,?new?PaiComparator());
??Collections.sort(newlist);
??System.out.println("-----------------排序后:");
??for(Card?st:newlist)
???System.out.println(st.getShape()+st.getId());
??//這里用equals方法記得要對(duì)卡片對(duì)象Card重寫
??if(newlist.get(3).equals(play1.getCards())){
???System.out.println("????玩家:??"+play1.getName()+"獲勝!?。∈峙茷椋?+newlist.get(3).getShape()+newlist.get(3).getId());
??}else?
???System.out.println("????玩家:??"+play2.getName()+"獲勝?。。∈峙茷椋?+newlist.get(3).getShape()+newlist.get(3).getId());
??
?}
?public?static?void?main(String[]?args)?{
??PaiTest?pt?=?new?PaiTest();
??pt.purcard();//創(chuàng)建撲克牌
??pt.fapai();//游戲過程
??
?}
}


正在回答

2 回答

package zc20170130;


/**

?* 創(chuàng)建撲克牌類

?* 顏色

?* 點(diǎn)數(shù)

?* @author Administrator

?*

?*/

public class Card {?


private String color;

private String number;

public Card(String color, String number) {

this.color = color;

this.number = number;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

}






package zc20170130;


import java.util.*;


/**

?* 玩家類、id,name,手牌

?* @author Administrator

?*

?*/

public class Player {


private int id;

private String name;

private ArrayList<Card> cards = new ArrayList<Card>();

public Player(){

}

public Player(int id, String name, ArrayList<Card> card) {

this.id = id;

this.name = name;

this.cards = card;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public ArrayList<Card> getCard() {

return cards;

}

public void addCard(Card card) {

cards.add(card);

}


}




package zc20170130;


import java.util.*;


public class GameRule {


/**

* 隨機(jī)生成一副撲克牌 發(fā)牌 判斷勝負(fù)

*/


private static ArrayList<Card> cards = new ArrayList<Card>(); // 一副牌2-10 J Q


public ArrayList<Card> getCards() {

return cards;

}


private void generateOneColor(String color) {// 生成單一色牌

Card c;

for (int i = 1; i <= 10; i++) {

if (i == 1)

c = new Card(color, "J");

else if (i == 2)

c = new Card(color, "Q");

else if (i == 3)

continue;

else

c = new Card(color, "" + i);

cards.add(c);

}

}


private void generateCard() {// 生成所有的牌

generateOneColor("黑桃");

generateOneColor("紅桃");

generateOneColor("梅花");

generateOneColor("方片");

cards.add(new Card("大王", "6"));

cards.add(new Card("小王", "3"));

}


public ArrayList<Card> randomCard() {// 隨機(jī)排序已有的牌

System.out.println("------------------洗牌!------------------");

generateCard();

Card temp, randomP;

for (int i = 0; i < cards.size(); i++) {

int suijishu = (int) (Math.random() * 10);

randomP = cards.get(suijishu);

temp = cards.get(i);

cards.set(i, randomP);

cards.set(suijishu, temp);

}

for (Card c : cards)

if (c.getColor().equals("大王") || c.getColor().equals("小王"))

System.out.print(c.getColor() + " ");

else

System.out.print(c.getColor() + c.getNumber() + " ");

System.out.println();

System.out.println("------------------洗牌完成!------------------");

return cards;

}


// 發(fā)牌

public void licensing(Player player) {

Card card = cards.get(0);

cards.remove(0);

// for (Card c : cards)

// System.out.print(c.getColor() + c.getNumber() + " ");

player.addCard(card);

}


/**

* 獲得一張牌的number

*?

* @param card

* @return

*/

private int getNumber(Card card) {

int x1;

if (card.getNumber().equals("J"))

x1 = 1;

else if (card.getNumber().equals("Q"))

x1 = 2;

else

x1 = Integer.parseInt(card.getNumber());

return x1;

}


/**

* winer

*?

* @param player1

* @param player2

* @return

*/

public Player winer(Player player1, Player player2) {


int x1, x2, y1, y2;

x1 = getNumber(player1.getCard().get(0));

x2 = getNumber(player1.getCard().get(1));

y1 = getNumber(player2.getCard().get(0));

y2 = getNumber(player2.getCard().get(1));


if ((x1 + x2) % 10 > (y1 + y2) % 10)

return player1;

else if ((x1 + x2) % 10 < (y1 + y2) % 10)

return player2;

else

return null;


}


/**

* 直到輸入整形的id

*/

public void inputSC() {

Scanner input = new Scanner(System.in);

int id = 0;

while (true) {

try {

id = input.nextInt();

} catch (Exception e) {

System.out.println("請(qǐng)輸入整數(shù)類型的id:");

inputSC();

}

break;

}

}


public Player createPlayer(String playerName) {


Scanner input1 = new Scanner(System.in);

System.out.println("" + playerName + ": id:");

int id = 0;

inputSC();

System.out.println(playerName + ": name:");

String name = input1.nextLine();

Player player = new Player();

player.setId(id);

player.setName(name);

System.out.println("玩家" + player.getName() + "創(chuàng)建成功!");

return player;

}


public void removeCard(Player player){

player.getCard().remove(0);

player.getCard().remove(0);

}

}





package zc20170130;


import java.util.*;


public class GameStart {


public static GameRule gr = new GameRule();


public static void main(String[] args) {


gr.randomCard();


System.out.println("------------------創(chuàng)建2位玩家:------------------");

Player player1 = gr.createPlayer("玩家1");

Player player2 = gr.createPlayer("玩家2");

int i = 1;

while (true) {

System.out.println("------------------第"+i+"輪發(fā)牌:------------------");

System.out.println("玩家1獲得第1張牌");

gr.licensing(player1);

System.out.println("玩家2獲得第1張牌");

gr.licensing(player2);

System.out.println("玩家1獲得第2張牌");

gr.licensing(player1);

System.out.println("玩家2獲得第2張牌");

gr.licensing(player2);


Player winer = gr.winer(player1, player2);

if (winer != null)

System.out.println("玩家" + winer.getName() + "獲勝?。?!");

else

System.out.println("平局");

System.out.println(player1.getName() + "手牌為:"

+ player1.getCard().get(0).getColor()

+ player1.getCard().get(0).getNumber() + "+"

+ player1.getCard().get(1).getColor()

+ player1.getCard().get(1).getNumber());

System.out.println(player2.getName() + "手牌為:"

+ player2.getCard().get(0).getColor()

+ player2.getCard().get(0).getNumber() + "+"

+ player2.getCard().get(1).getColor()

+ player2.getCard().get(1).getNumber());

gr.removeCard(player1);

gr.removeCard(player2);

i++;

if(gr.getCards().size()/4<=0)

break;

}

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

學(xué)習(xí)學(xué)習(xí)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409764    人
  • 解答問題       4543    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過的精彩,快來加入吧

進(jìn)入課程

我的撲克牌代碼,不完整版

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)