-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeMaker.java
149 lines (133 loc) · 2.95 KB
/
ShapeMaker.java
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package Tetris;
import java.awt.*;
/**
*The ShapeMaker class makes a Shape object that is chosen randomly out of the 7 possible shapes. This Shape object can then be accessed by other JPanel objects that require a shape.
*@author Shah Saad Alam and Phyo Aung Kyaw.
*/
public class ShapeMaker{
/**The Shape object created*/
public Shape shape;
/**Constructor*/
public ShapeMaker(){
int i = (int)(Math.random()*7) + 1;
switch(i){
case 1: shape = new IShape(); break;
case 2: shape = new JShape(); break;
case 3: shape = new LShape(); break;
case 4: shape = new OShape(); break;
case 5: shape = new SShape(); break;
case 6: shape = new TShape(); break;
case 7: shape = new ZShape(); break;
}
}
class IShape extends Shape{
IShape(){
int count = 3;
for(int i=0; i<4; i++){
super.cells[i][0] = 0;
super.cells[i][1] = count++;
}
super.color = Color.RED;
}
boolean isOShape(){
return false;
}
}
class JShape extends Shape{
JShape(){
int count = 4;
for(int i=0; i<3; i++){
super.cells[i][0] = 0;
super.cells[i][1] = count++;
}
super.cells[3][0] = 1;
super.cells[3][1] = 6;
super.color = Color.MAGENTA;
}
boolean isOShape(){
return false;
}
}
class LShape extends Shape{
LShape(){
int count = 4;
for(int i=0; i<3; i++){
super.cells[i][0] = 0;
super.cells[i][1] = count++;
}
super.cells[3][0] = 1;
super.cells[3][1] = 4;
super.color = Color.YELLOW;
}
boolean isOShape(){
return false;
}
}
class OShape extends Shape{
OShape(){
super.cells[0][0] = 0;
super.cells[0][1] = 4;
super.cells[1][0] = 0;
super.cells[1][1] = 5;
super.cells[2][0] = 1;
super.cells[2][1] = 4;
super.cells[3][0] = 1;
super.cells[3][1] = 5;
super.color = Color.CYAN;
}
boolean isOShape(){
return true;
}
}
class SShape extends Shape{
SShape(){
super.cells[0][0] = 0;
super.cells[0][1] = 6;
super.cells[1][0] = 0;
super.cells[1][1] = 5;
super.cells[2][0] = 1;
super.cells[2][1] = 4;
super.cells[3][0] = 1;
super.cells[3][1] = 5;
super.color = Color.BLUE;
}
boolean isOShape(){
return false;
}
/**@return Name of the type of this Shape.*/
public String toString(){
return "SShape";
}
}
class TShape extends Shape{
TShape(){
int count = 4;
for(int i=0; i<4; i++){
super.cells[i][0] = 0;
super.cells[i][1] = count++;
}
super.cells[3][0] = 1;
super.cells[3][1] = 5;
super.color = Color.DARK_GRAY;
}
boolean isOShape(){
return false;
}
}
class ZShape extends Shape{
ZShape(){
super.cells[0][0] = 0;
super.cells[0][1] = 4;
super.cells[1][0] = 0;
super.cells[1][1] = 5;
super.cells[2][0] = 1;
super.cells[2][1] = 5;
super.cells[3][0] = 1;
super.cells[3][1] = 6;
super.color = Color.GREEN;
}
boolean isOShape(){
return false;
}
}
}