|
5 | 5 | import java.util.Random; |
6 | 6 | import edu.macalester.graphics.*; |
7 | 7 |
|
| 8 | +import java.awt.Color; |
8 | 9 |
|
9 | | -public class SetUI { |
| 10 | + |
| 11 | +public class SetUI extends GraphicsGroup { |
10 | 12 | public ArrayList<Card> board; |
11 | 13 | private ArrayList<Card> deck; |
12 | 14 |
|
13 | 15 | private Random rand = new Random(); |
14 | 16 |
|
| 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 | + |
15 | 29 | public SetUI(ArrayList<Card> deck) { |
16 | 30 | this.deck = deck; |
17 | 31 | } |
@@ -42,40 +56,78 @@ void checkBoard() { |
42 | 56 |
|
43 | 57 | // Create Cards |
44 | 58 | 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 |
46 | 62 | switch (card.getTrait(2)) { |
| 63 | + // trait 0 is color, trait 3 is fill |
47 | 64 | case 0: |
48 | | - createSquiggle(card.getTrait(0), card.getTrait(3)); |
| 65 | + add(createTriangle(card.getTrait(0), card.getTrait(3))); |
| 66 | + break; |
49 | 67 | case 1: |
50 | | - createDiamond(card.getTrait(0), card.getTrait(3)); |
| 68 | + add(createDiamond(card.getTrait(0), card.getTrait(3))); |
| 69 | + break; |
51 | 70 | case 2: |
52 | | - createOval(card.getTrait(0), card.getTrait(3)); |
| 71 | + add(createRectangle(card.getTrait(0), card.getTrait(3))); |
| 72 | + break; |
53 | 73 | default: |
54 | | - createSquiggle(card.getTrait(0), card.getTrait(3)); |
| 74 | + add(createTriangle(card.getTrait(0), card.getTrait(3))); |
| 75 | + break; |
55 | 76 | } |
56 | 77 | } |
57 | 78 | } |
58 | 79 |
|
| 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 | + |
59 | 91 | // createShapes |
60 | | - void createSquiggle(int color, int fill){ |
| 92 | + private Path createTriangle(int color, int fill){ |
61 | 93 | // 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; |
63 | 104 | } |
64 | 105 |
|
65 | | - void createDiamond(int color, int fill){ |
| 106 | + private Path createDiamond(int color, int fill){ |
66 | 107 | // 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; |
68 | 119 | } |
69 | 120 |
|
70 | | - void createOval(int color, int fill){ |
| 121 | + private Rectangle createRectangle(int color, int fill){ |
71 | 122 | // 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 | + ); |
76 | 127 |
|
77 | | - default: |
78 | | - break; |
79 | | - } |
| 128 | + rect.setFillColor(getColorFromInt(color, fill)); |
| 129 | + rect.setStrokeColor(colors.get(color)); |
| 130 | + |
| 131 | + return rect; |
80 | 132 | } |
81 | 133 | } |
0 commit comments