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

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

簡易撲克牌游戲代碼


public class MainClass {
?? ?
?? ?public static void main(String[] args) {
?? ??? ?Game game = Game.newInstance();
?? ??? ?game.initUser(2);
?? ??? ?game.dealCards(3);
?? ??? ?game.playCards();
?? ?}
}

public class Game {
?? ?private List<Cards> mCaraList;
?? ?private List<User> mUserList;

?? ?private Game() {
?? ??? ?if(mCaraList==null) {
?? ??? ??? ?mCaraList = new ArrayList<>();
?? ??? ?}
?? ??? ?if(mUserList==null) {
?? ??? ??? ?mUserList = new ArrayList<>();
?? ??? ?}
?? ??? ?initCards();
?? ??? ?shuffleCards();
?? ?}

?? ?public static Game newInstance() {
?? ??? ?return new Game();
?? ?}

?? ?private void initCards() {
?? ??? ?System.out.println("-----------創(chuàng)建撲克牌--------------");
?? ??? ?mCaraList.clear();
?? ??? ?for (String colour : Constant.ARRAY_COLOUR) {
?? ??? ??? ?for (String point : Constant.ARRAY_POINT) {
?? ??? ??? ??? ?mCaraList.add(new Cards(colour, point));
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("-----------撲克牌創(chuàng)建成功!--------------");
?? ?}

?? ?private void shuffleCards() {
?? ??? ?System.out.println("-----------開始洗牌!--------------");
?? ??? ?Collections.shuffle(mCaraList);
?? ??? ?Collections.shuffle(mCaraList);
?? ??? ?System.out.println("-----------洗牌結(jié)束!--------------");
?? ?}

?? ?/**
?? ? *
?? ? * @param userCount? 玩家數(shù)量
?? ? */
?? ?public void initUser(int userCount) {
?? ??? ?Scanner scannerIn = new Scanner(System.in);
?? ??? ?int i = 1;
?? ??? ?do {
?? ??? ??? ?System.out.println("請(qǐng)輸入第" + i + "位玩家的ID和姓名:");
?? ??? ??? ?while (true) {
?? ??? ??? ??? ?try {
?? ??? ??? ??? ??? ?System.out.println("請(qǐng)輸入ID:");
?? ??? ??? ??? ??? ?Integer id = scannerIn.nextInt();

?? ??? ??? ??? ??? ?User user = new User(id);
?? ??? ??? ??? ??? ?if (mUserList.contains(user)) {
?? ??? ??? ??? ??? ??? ?throw new Exception();
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?user = null;
?? ??? ??? ??? ??? ?System.out.println("請(qǐng)輸入姓名:");
?? ??? ??? ??? ??? ?String name = scannerIn.next();
?? ??? ??? ??? ??? ?mUserList.add(new User(id, name));
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?} catch (InputMismatchException e) {
?? ??? ??? ??? ??? ?scannerIn = new Scanner(System.in);
?? ??? ??? ??? ??? ?System.out.println("請(qǐng)輸入整數(shù)類型的ID!");
?? ??? ??? ??? ?} catch (Exception e) {
?? ??? ??? ??? ??? ?System.out.println("該ID已存在,請(qǐng)重新輸入!");
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?i++;
?? ??? ?} while (i <= userCount&&userCount<=4);
?? ??? ?scannerIn.close();
?? ??? ?scannerIn = null;

?? ??? ?for (User user : mUserList) {
?? ??? ??? ?if (user != null) {
?? ??? ??? ??? ?System.out.println("---歡迎玩家:" + user.getName());
?? ??? ??? ?}
?? ??? ?}
?? ?}

?? ?/**
?? ? *
?? ? * @param cardCount? 每人發(fā)幾張牌
?? ? */
?? ?public void dealCards(int cardCount) {
?? ??? ?System.out.println("-----------開始發(fā)牌!--------------");

?? ??? ?for (int i = 0; i < cardCount; i++) {
?? ??? ??? ?int size = mUserList.size();
?? ??? ??? ?for (User user : mUserList) {
?? ??? ??? ??? ?if (user != null) {
?? ??? ??? ??? ??? ?Cards cards = mCaraList.get(0);
?? ??? ??? ??? ??? ?user.addCardsToList(cards);
?? ??? ??? ??? ??? ?mCaraList.remove(0);
?? ??? ??? ??? ??? ?System.out.println("---玩家" + user.getName() + "---拿牌---"+cards);
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("-----------發(fā)牌結(jié)束!--------------");
?? ?}

?? ?
?? ?public void playCards() {
?? ??? ?System.out.println("-----------游戲開始!--------------");
?? ??? ?int size = mUserList.size();

?? ??? ?Cards maxCards = null;
?? ??? ?User winUser = null;
?? ??? ?for(User user:mUserList) {
?? ??? ??? ?List<Cards> list = user.getList();
?? ??? ??? ?Collections.sort(list);
?? ??? ??? ?Cards cards = list.get(0);
?? ??? ??? ?if (maxCards == null) {
?? ??? ??? ??? ?maxCards = cards;
?? ??? ??? ??? ?winUser = user;
?? ??? ??? ?} else {
?? ??? ??? ??? ?int win = maxCards.compareTo(cards);
?? ??? ??? ??? ?if (win > 0) {
?? ??? ??? ??? ??? ?maxCards = cards;
?? ??? ??? ??? ??? ?winUser = user;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?System.out.println("玩家:" + winUser.getName() + "? 最大的手牌為" + maxCards);
?? ??? ?}
?? ??? ?System.out.println("-----------玩家:" + winUser + "獲勝!--------------");
?? ?}
}

public class Cards implements Comparable<Cards> {
?? ?private String colour;
?? ?private String point;

?? ?public Cards(String colour, String point) {
?? ??? ?super();
?? ??? ?this.colour = colour;
?? ??? ?this.point = point;
?? ?}

?? ?@Override
?? ?public int compareTo(Cards card) {//用于將 Cards對(duì)象與方法的參數(shù)進(jìn)行比較
?? ??? ?int pointPosition1 = card.getPointPosition();
?? ??? ?int pointPosition2 = this.getPointPosition();
?? ??? ?if(pointPosition1==pointPosition2) {
?? ??? ??? ?int colourPosition1 = card.getColourPosition();
?? ??? ??? ?int colourPosition2 = this.getColourPosition();
?? ??? ??? ?return colourPosition1-colourPosition2;
?? ??? ?}
?? ??? ?return pointPosition1-pointPosition2;
?? ?}

?? ?private int getPointPosition() {
?? ??? ?String point = getPoint();
?? ??? ?int length = Constant.ARRAY_POINT.length;
?? ??? ?for (int i = 0; i < length; i++) {
?? ??? ??? ?if (point.equals( Constant.ARRAY_POINT[i])) {
?? ??? ??? ??? ?return i;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return length - 1;
?? ?}

?? ?private int getColourPosition() {
?? ??? ?String colour = getColour();
?? ??? ?int length =? Constant.ARRAY_COLOUR.length;
?? ??? ?for (int i = 0; i < length; i++) {
?? ??? ??? ?if (colour.equals( Constant.ARRAY_COLOUR[i])) {
?? ??? ??? ??? ?return i;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return length - 1;
?? ?}

?? ?public String getColour() {
?? ??? ?return colour == null ?? Constant.ARRAY_COLOUR[3] : colour;
?? ?}

?? ?public String getPoint() {
?? ??? ?return point == null ?? Constant.ARRAY_POINT[0] : point;
?? ?}

?? ?public void setColour(String colour) {
?? ??? ?this.colour = colour;
?? ?}

?? ?public void setPoint(String point) {
?? ??? ?this.point = point;
?? ?}

?? ?@Override
?? ?public String toString() {
?? ??? ?return colour+point;
?? ?}???
}


package com.itedu.www.entity;

import java.util.ArrayList;
import java.util.List;

public class User {
?? ?private int id;
?? ?private String name;
?? ?private List<Cards> list;
?? ?public User(int id, String name) {
?? ??? ?super();
?? ??? ?this.id = id;
?? ??? ?this.name = name;
?? ??? ?this.list = new ArrayList<>();
?? ?}
?? ?
?? ?public User(int id) {
?? ??? ?super();
?? ??? ?this.id = id;
?? ?}


?? ?@Override
?? ?public String toString() {
?? ??? ?return "昵稱:? " + name;
?? ?}
?? ?public int getId() {
?? ??? ?return id;
?? ?}
?? ?public String getName() {
?? ??? ?return name;
?? ?}
?? ?public List<Cards> getList() {
?? ??? ?return list;
?? ?}
?? ?
?? ?public void addCardsToList(Cards c) {
?? ??? ?list.add(c);
?? ?}

?? ?public void clearList() {
?? ??? ?list.clear();;
?? ?}


?? ?@Override
?? ?public int hashCode() {
?? ??? ?final int prime = 31;
?? ??? ?int result = 1;
?? ??? ?result = prime * result + id;
?? ??? ?return result;
?? ?}




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

public class Constant {
?? ?public static final String[] ARRAY_COLOUR = {"方片",? "梅花","紅桃","黑桃"};//從小到大排序
?? ?public static final String[] ARRAY_POINT = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };

}


正在回答

4 回答

for (String colour : Constant.ARRAY_COLOUR) {
?? ??? ??? ?for (String point : Constant.ARRAY_POINT) {

constant 這兒地方顯示錯(cuò)誤怎么搞


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

五月NING 提問者

什么錯(cuò),只要寫對(duì)了就不會(huì)
2018-07-20 回復(fù) 有任何疑惑可以回復(fù)我~
#2

五月NING 提問者

補(bǔ)上了
2018-07-20 回復(fù) 有任何疑惑可以回復(fù)我~

謝謝大佬

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

老哥強(qiáng)


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

6666

1 回復(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)