import java.util.Arrays
import java.util.Iterator
import java.util.LinkedList
import java.util.Random
public class Licensing {
public static void main(String[] args) {
LinkedList<Integer> card = new LinkedList<Integer>()
int max = 108
Random r = new Random()
/*下边的代码是定义一副牌*/
for(int i = 0i < 8++i)
for(int j = 1j <= 13++j)
card.add(j)
for(int k = 0k < 2++k){
card.add(14)
card.add(15)
}
Player[] p = new Player[6]//定义六个玩家
for(int i = 0i<6++i){
p[i] = new Player()
}
while(max > 0){//发牌
for(int m = 0m<6++m){
int index = r.nextInt(max)
max--
if(max < 0)
break
Integer a = card.get(index)
card.remove(a)
p[m].myCard.add(a)
}
}
int[] pp = new int[6]
for(int w = 0w<6++w)
pp[w] = p[w].pairs()
Arrays.sort(pp)
for(int e = 0e<6++e){
if(p[e].pairs()==pp[5])
System.out.println("第"+e+"位玩家获胜了")
}
}
}
class Player{
public LinkedList<Integer> myCard
public String name
public Player(){
myCard = new LinkedList<Integer>()
}
public int pairs(){
int sum = 0
if(myCard != null){
LinkedList<Integer> tempCard = myCard
Iterator<Integer> it = tempCard.iterator()
int in = 0
if(myCard != null){
while(it.hasNext()){
it.next()
++in
}
int c =-1
for(int i = 0i < in++i){
if(i == c)
continue
for(int j = i+1j<in++j){
if((int)tempCard.get(i) == (int)tempCard.get(j)){
++sum
c = j
break
}
}
}
}
}
return sum
}
}
DeckOfCards()构造函数里面,注释掉的//deck[count]=new Card(faces[count%13],suits[count/13])
是对的,下面那行除17是错的
另外,没有把大小王赋值到数组里
最后main函数里,打印方法错了。应该为,原本少了一个%-20s
System.out.printf("%-20s%-20s%-20s\n", myDeckOfCards.dealCard(), myDeckOfCards.dealCard(), myDeckOfCards.dealCard())
发牌完成以后剩下的3张牌就是保留的底牌
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)