亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

菜鳥寫的撲克牌游戲求大神指點

菜鳥寫的撲克牌游戲求大神指點

一個什么樣的人 2015-11-18 17:23:39
package pukeGame;import java.util.ArrayList;import java.util.List;import java.util.Random;import java.util.Scanner;public class Player { Scanner input = new Scanner(System.in);//輸入類 List<Puke> Pukecontainer = new ArrayList<Puke>();//相當于玩家手的拿牌的功能 int Id;//玩家的Id String name;//玩家的姓名 public Player(String name, int Id) { this.name = name; this.Id = Id; } public Player() {//構造方法 } public Puke takePoker(List<Puke> l) {//模擬的發牌功能,玩家摸牌 Random random = new Random(); int i = random.nextInt(l.size()); Puke p = l.get(i); l.remove(i);//移出已經抽出去的撲克牌 Pukecontainer.add(p); return p; } public Puke PickMaxPoker() {// 挑選出玩家手上最大的撲克牌 Puke MaxPoker = null; Puke poker[] = new Puke[Pukecontainer.size()];// 取出手上牌并存放在poker數組中 for (Puke Poker : Pukecontainer) { int i = 0; while (i < Pukecontainer.size()) { poker[i] = Poker;// Pukecontainer.get(i); i++; } } for (int j = 0; j < poker.length; j++) { MaxPoker = poker[0]; if (poker[j].shunxu > MaxPoker.shunxu) MaxPoker = poker[j]; } return MaxPoker; }}package pukeGame;import java.util.ArrayList;import java.util.List;public class Puke {//撲克類賦予colorline(花色序列屬性)以及數字大小numline屬性用來區別撲克牌的大小List<String> colorline=new ArrayList<String>();List<String> numline=new ArrayList<String>();@Override public String toString() { return color + num; }String color;String num;int shunxu;public Puke(String color,String num,int shunxu){ this.color=color; this.num=num; this.shunxu=shunxu;}public Puke(){}public void compare(){ }}package pukeGame;import java.util.ArrayList;import java.util.InputMismatchException;import java.util.List;import java.util.Random;import java.util.Scanner;public class Test { List<Puke> container = new ArrayList<Puke>(); List<Integer> pukelocation = new ArrayList<Integer>(); List<Puke> washedpuke = new ArrayList<Puke>();//static Player p1;//static Player p2; public static void main(String[] args) { // TODO Auto-generated method stub Test t = new Test(); List<Puke> originalpuke = t.PukeCreate(); System.out.println(originalpuke); System.out.println("--------撲克牌創建成功---------"); System.out.println("--------開始洗牌---------"); List<Puke> washedpoker = t.PukeWash(originalpuke); System.out.println("--------洗牌成功---------"); System.out.println(washedpoker); System.out.println("創建第一個玩家");Player p1=joinPlayer();// Player p1 = fuzhu();//在這使用fuzhu()函數的時候出現的NullPointException //System.out.println("請輸入整形id和String類型姓名"); System.out.println("創建第二個玩家");Player p2=joinPlayer();// Player p2 = fuzhu(); System.out.println("玩家1抽到" + p1.takePoker(washedpoker));//System.out.println(washedpoker.size()); System.out.println("玩家2抽到" + p2.takePoker(washedpoker));//System.out.println(washedpoker.size()); System.out.println("玩家1抽到" + p1.takePoker(washedpoker));//System.out.println(washedpoker.size()); System.out.println("玩家2抽到" + p2.takePoker(washedpoker));//System.out.println(washedpoker.size()); System.out.println("玩家" + p1.name + "手上的牌是" + p1.Pukecontainer); System.out.println("玩家" + p2.name + "手上的牌是" + p2.Pukecontainer); Puke p1Maxpoker = p1.PickMaxPoker(); Puke p2Maxpoker = p2.PickMaxPoker(); if (p1Maxpoker.shunxu > p2Maxpoker.shunxu) {? System.out.println(p1.name + "贏了!??!"); }else{System.out.println(p2.name+"贏了?。。?);} } public List<Puke> PukeCreate() {// 創建一副有序的撲克牌 String color[] = { "紅桃", "梅花", "方片", "黑桃" }; String num[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { Puke p = new Puke(color[i], num[j], i * 13 + j); container.add(p); } } return container; } public List<Puke> PukeWash(List<Puke> p) {//將有序的撲克牌洗成無序的 // int location; int count = 0; Random random = new Random(); // List washedpuke = new Puke[51]; while (count < 52) { boolean flag = pukelocation.add(random.nextInt(52)); if (flag) count++; } for (int j = 0; j < 52; j++) { Puke poker = p.get(pukelocation.get(j)); washedpuke.add(poker); } return washedpuke; } public static Player joinPlayer(){//加入玩家的函數,執行一次加入一個玩家 int ?id=0; Scanner input = new Scanner(System.in); System.out.println("請輸入玩家Id"); try{id = input.nextInt();} catch(InputMismatchException I) { System.out.println("請輸入整型Id?。?!"); joinPlayer(); } System.out.println("請輸入玩家姓名"); String name = input.next(); // input.close();//不能關閉input因為還需要創建第二個玩家關閉了就會出現異常 Player p1 = new Player(name, id); return p1; }/*?* *?* 沒什么用主要是為了解決輸入不匹配異常的時候瞎想出來的函數,使用的時候老是提示什么NullPionterException?* public static Player fuzhu() {Player p=null; try{p=joinPlayer();} catch(InputMismatchException I) { System.out.println("請輸入整形id和String類型的名字"); fuzhu(); } return p; }*/}
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 1612 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號