-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
95 lines (86 loc) · 2.14 KB
/
Card.java
File metadata and controls
95 lines (86 loc) · 2.14 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package state;
import java.util.Random;
public class Card {
private Random rm = new Random();
private int[][] card = new int[5][5];
private String[][] debugCard = new String[5][5];
// カード作成
public Card() {
int fix = 1;
Already al = new Already();
for (int i = 0; i < 5; i++) {
re: for (int j = 0; j < 5; j++) {
int num = rm.nextInt(15) + fix;
// 既出は再帰呼びだし
if (al.already(num)) {
--j;
continue re;
} else {
card[i][j] = num;
debugCard[i][j] = Integer.valueOf(num).toString();
}
if (i == 2 && j == 2) {
card[2][2] = 0;
debugCard[2][2] = "0";
}
}
fix += 15;
}
}
// カード出力 0は(■)で出力
public void printCard() {
System.out.println("+________________________+");
for (int i = 0; i < 5; i++) {
System.out.print("|");
for (int j = 0; j < 5; j++) {
if (getCard()[i][j] == 0) {
System.out.print(" (■)|");
} else if (getCard()[i][j] < 10) {
// 一桁
System.out.print(" " + getCard()[i][j] + " |");
} else {
// 二桁
System.out.print(" " + getCard()[i][j] + " |");
}
// 改行
if (j == 4)
System.out.println();
}
}
System.out.println("+________________________+");
}
// Debug用のプリント。()付きで数字を表示
public void printDebug() {
System.out.println("+________________________+");
for (int i = 0; i < 5; i++) {
System.out.print("|");
for (int j = 0; j < 5; j++) {
// フォーマット合わせ
if (getCard()[i][j] == 0) {
String now = debugCard[i][j];
if (Integer.parseInt(now) < 10) {
// 一桁
System.out.print(" (" + now + ")|");
} else {
// 二桁
System.out.print("(" + now + ")|");
}
} else if (getCard()[i][j] < 10) {
System.out.print(" " + getCard()[i][j] + " |");
} else {
System.out.print(" " + getCard()[i][j] + " |");
}
// 改行
if (j == 4)
System.out.println();
}
}
System.out.println("+________________________+");
}
public int[][] getCard() {
return this.card;
}
public void setCard(int num, int x, int y) {
this.card[x][y] = num;
}
}