-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
101 lines (84 loc) · 3.22 KB
/
Card.java
File metadata and controls
101 lines (84 loc) · 3.22 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
96
97
98
99
100
101
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
class Card {
private String image;
private boolean isFaceUp;
private int peopleCount;
private int treeCount;
private int animalCount;
public Card(String image, boolean isFaceUp, int peopleCount, int treeCount, int animalCount) {
this.image = image;
this.isFaceUp = isFaceUp;
this.peopleCount = peopleCount;
this.animalCount = animalCount;
this.treeCount = treeCount;
}
public String getImage() {
return image;
}
public boolean isFaceUp() {
return isFaceUp;
}
public int getPeopleCount() {
return peopleCount;
}
public int getTreeCount(){
return treeCount;
}
public int getAnimalCount(){
return animalCount;
}
public int getCount(String theme){
if(theme.equals("사람")){
return peopleCount;
}
else if(theme.equals("동물")){
return animalCount;
}
else if(theme.equals("나무")){
return treeCount;
}
else{
return 0;
}
}
public String getImageName() {
File file = new File(image);
return file.getName();
}
public static List<Card> insert_card() {
File folder1 = new File("./image/나무");
File folder2 = new File("./image/동물");
File folder3 = new File("./image/사람");
File[][] listOfFiles = {folder1.listFiles(), folder2.listFiles(), folder3.listFiles()};
if (listOfFiles[0] == null || listOfFiles[1] == null || listOfFiles[2] == null) {
System.out.println("Cannot find directory ./image/나무 or ./image/동물 or ./image/사람");
return null;
}
List<Card> deck = new ArrayList<>();
Random rand = new Random();
// 각 폴더에서 뽑을 이미지의 인덱스를 저장할 배열
int[] selectedIndexes = {0, 0, 0};
for (int i = 0; i < 9; i++) {
// 랜덤하게 폴더 선택 (0: 풍경, 1: 동물, 2: 사람)
int selectedFolderIndex = rand.nextInt(3);
// 선택된 폴더에서 이미지 선택
File[] chosenFolder = listOfFiles[selectedFolderIndex];
File file = chosenFolder[selectedIndexes[selectedFolderIndex]];
if (file.isFile()) {
String fileNameWithoutExtension = file.getName().substring(0, file.getName().lastIndexOf("."));
String[] counts = fileNameWithoutExtension.split("_"); // 파일 이름을 '_'로 분리
int peopleCount = Integer.parseInt(counts[1]);
int animalCount = Integer.parseInt(counts[2]);
int treeCount = Integer.parseInt(counts[3]);
System.out.println("peopleCount: " + "animalCount: " + animalCount + ", treeCount: " + treeCount);
deck.add(new Card(file.getPath(), false, peopleCount, treeCount, animalCount));
}
// 해당 폴더에서 다음에 뽑을 이미지의 인덱스 증가
selectedIndexes[selectedFolderIndex]++;
}
return deck;
}
}