-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
67 lines (47 loc) · 1.37 KB
/
Deck.java
File metadata and controls
67 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class Deck {
//Deckは日本語で山札
private int[] deck = new int[13*4];
private int cardN = 0;
Deck(){
FirstSet();
//Test();
Shuffle();
//Test();
}
private void FirstSet(){
for(int i = 0; i<4;i++){
for(int j=0;j<13;j++){
deck[cardN] = j+1;
cardN++;
}
}
cardN = 0;
}
//山札のカードを全て出力させるテスト用の関数
/*private void Test(){
for(int i = 0; i<13*4;i++){
System.out.println(deck[i]);
}
}*/
public void Shuffle() {
Random r = ThreadLocalRandom.current();
for (int i = deck.length - 1; i > 0; i--) {
int index = r.nextInt(i + 1);
//swap
int tmp = deck[index];
deck[index] = deck[i];
deck[i] = tmp;
}
}
public int DrawACard(){
cardN++;//次のカードを指し示すようにする
if(cardN>= 13*4){
System.out.println("山札のカードがすべてなくなりました。");
return -1;
}else{
return deck[cardN-1];
}
}
}