Skip to content

Commit 3bbdd98

Browse files
Monday's Set work
1 parent 5773758 commit 3bbdd98

5 files changed

Lines changed: 89 additions & 26 deletions

File tree

‎.vscode/settings.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"build": true
88
},
99
"java.configuration.updateBuildConfiguration": "automatic",
10-
"java.debug.settings.onBuildFailureProceed": true
10+
"java.debug.settings.onBuildFailureProceed": true,
11+
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
1112
}

‎res/SetGame/setOutline.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
1. addCards()
5959
3. remove any null cards
6060

61-
## Cards
61+
## Card
6262

6363
### Instance Variables
6464
- priv `List<Int>` cardColors = [1, 2, 3]

‎src/SetGame/Card.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public class Card {
6+
import edu.macalester.graphics.GraphicsGroup;
7+
import edu.macalester.graphics.Rectangle;
8+
9+
public class Card extends GraphicsGroup {
710
private int color;
811
private int num;
912
private int shape;
1013
private int fill;
1114

15+
private static final int CARD_WIDTH = 30;
16+
private static final int CARD_HEIGHT = 45;
17+
1218
public Card(int color, int num, int shape, int fill) {
1319
this.color = color;
1420
this.num = num;

‎src/SetGame/SetGameMain.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package SetGame;
22

33
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import java.awt.Color;
47

58
public class SetGameMain {
69
// Instance Variables
710
private SetUI gameUI;
811
private ArrayList<Card> deck;
912

13+
public static final int NUMBER_OF_TRAIT_VARIANTS = 3;
1014

1115
// Instance Methods
1216

@@ -34,11 +38,11 @@ else if (!(cardA.getTrait(t) == cardB.getTrait(t)) &&
3438

3539
public void createDeck() {
3640
deck = new ArrayList<>();
37-
for (int c = 0; c < 3; c++) {
38-
for (int n = 0; n < 3; n++) {
39-
for (int s = 0; s < 3; s++) {
40-
for (int f = 0; f < 3; f++) {
41-
deck.add(new Card(c, n, s, f));
41+
for (int color = 0; color < NUMBER_OF_TRAIT_VARIANTS; color++) {
42+
for (int number = 0; number < NUMBER_OF_TRAIT_VARIANTS; number++) {
43+
for (int shape = 0; shape < NUMBER_OF_TRAIT_VARIANTS; shape++) {
44+
for (int fill = 0; fill < NUMBER_OF_TRAIT_VARIANTS; fill++) {
45+
deck.add(new Card(color, number, shape, fill));
4246
}
4347
}
4448
}

‎src/SetGame/SetUI.java‎

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,27 @@
55
import java.util.Random;
66
import edu.macalester.graphics.*;
77

8+
import java.awt.Color;
89

9-
public class SetUI {
10+
11+
public class SetUI extends GraphicsGroup {
1012
public ArrayList<Card> board;
1113
private ArrayList<Card> deck;
1214

1315
private Random rand = new Random();
1416

17+
private final List<Color> colors = List.of(
18+
Color.RED,
19+
Color.GREEN,
20+
Color.BLUE
21+
);
22+
23+
private final List<Color> halfColors = List.of(
24+
new Color(255, 127, 127),
25+
new Color(127, 255, 127),
26+
new Color(127, 127, 255)
27+
);
28+
1529
public SetUI(ArrayList<Card> deck) {
1630
this.deck = deck;
1731
}
@@ -42,40 +56,78 @@ void checkBoard() {
4256

4357
// Create Cards
4458
void createCard(Card card){
45-
for (int i = 0; i < card.getTrait(1); i++){
59+
// trait 1 is number of
60+
for (int i = 0; i < card.getTrait(1); i++) {
61+
// trait 2 is shape
4662
switch (card.getTrait(2)) {
63+
// trait 0 is color, trait 3 is fill
4764
case 0:
48-
createSquiggle(card.getTrait(0), card.getTrait(3));
65+
add(createTriangle(card.getTrait(0), card.getTrait(3)));
66+
break;
4967
case 1:
50-
createDiamond(card.getTrait(0), card.getTrait(3));
68+
add(createDiamond(card.getTrait(0), card.getTrait(3)));
69+
break;
5170
case 2:
52-
createOval(card.getTrait(0), card.getTrait(3));
71+
add(createRectangle(card.getTrait(0), card.getTrait(3)));
72+
break;
5373
default:
54-
createSquiggle(card.getTrait(0), card.getTrait(3));
74+
add(createTriangle(card.getTrait(0), card.getTrait(3)));
75+
break;
5576
}
5677
}
5778
}
5879

80+
81+
private Color getColorFromInt(int colorInt, int fillInt) {
82+
if (fillInt == 1) {
83+
return halfColors.get(colorInt);
84+
} else if (fillInt == 2) {
85+
return colors.get(colorInt);
86+
} else {
87+
return Color.WHITE;
88+
}
89+
}
90+
5991
// createShapes
60-
void createSquiggle(int color, int fill){
92+
private Path createTriangle(int color, int fill){
6193
// crying
62-
94+
Path triangle = Path.makeTriangle(
95+
0, 0,
96+
10, 10,
97+
20, 0
98+
);
99+
100+
triangle.setFillColor(getColorFromInt(color, fill));
101+
triangle.setStrokeColor(colors.get(color));
102+
103+
return triangle;
63104
}
64105

65-
void createDiamond(int color, int fill){
106+
private Path createDiamond(int color, int fill){
66107
// more crying
67-
Rectangle diamond
108+
Path diamond = new Path(List.of(
109+
new Point(0, 5),
110+
new Point(10, 10),
111+
new Point(20, 5),
112+
new Point(10, 0)
113+
));
114+
115+
diamond.setFillColor(getColorFromInt(color, fill));
116+
diamond.setStrokeColor(colors.get(color));
117+
118+
return diamond;
68119
}
69120

70-
void createOval(int color, int fill){
121+
private Rectangle createRectangle(int color, int fill){
71122
// even more crying
72-
Ellipse oval = new Ellipse(x, y, 30, 10);
73-
switch (fill) {
74-
case 0:
75-
oval.setFillColor(fillColor);
123+
Rectangle rect = new Rectangle(
124+
0, 0,
125+
20, 10
126+
);
76127

77-
default:
78-
break;
79-
}
128+
rect.setFillColor(getColorFromInt(color, fill));
129+
rect.setStrokeColor(colors.get(color));
130+
131+
return rect;
80132
}
81133
}

0 commit comments

Comments
 (0)