-
Notifications
You must be signed in to change notification settings - Fork 0
/
square.java
116 lines (99 loc) · 2 KB
/
square.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
package graphic;
import java.awt.Color;
import java.awt.Graphics;
public class square {
int x,y;
public boolean stopped = false;
private Color color = Color.black;
private Tetris1 tc;
public int fallSpeed = 30;
public int squareSize = 30;
public square(){}
public square(Color color, Tetris1 tc){
this.color = color;
this.tc = tc;
tc.ss.add(this);
}
public square(Color color){
this.color = color;
}
public square(int x, int y,Color color){
this.x = x;
this.y = y;
this.color = color;
}
public void drawSquare(Graphics g){
Color c = g.getColor();
g.setColor(color);
g.fillRect(x,y,squareSize,squareSize);
//Color c = g.getColor();
g.setColor(Color.black);
g.drawRect(x,y,squareSize,squareSize);
g.setColor(c);
}
public void drop(){
y+=fallSpeed;
}
public void changeStatus(){
//condition1
if(y+squareSize>=581){
stopped = true;
}
//condition2
if(isHit()){
stopped = true;
}
}
public boolean isHit() {
// TODO Auto-generated method stub
for(int i=0; i<tc.ss.size();i++){
square s = tc.ss.get(i);
if(x == s.getX() && y + s.squareSize == s.getY() && s.stopped){
return true;
}
}
return false;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public void moveRight() {
// TODO Auto-generated method stub
x+=squareSize;
}
public void moveLeft() {
// TODO Auto-generated method stub
x-=squareSize;
}
public boolean hitLeft() {
// TODO Auto-generated method stub
for(int i=0; i<tc.ss.size(); i++){
square s = tc.ss.get(i);
//if(s.getX()==x-s.squareSize && s.getY() == y && s.stopped){
if(x<=0){
return true;
}
}
return false;
}
public boolean hitRight() {
// TODO Auto-generated method stub
for(int i=0; i<tc.ss.size(); i++){
square s = tc.ss.get(i);
//if(s.getX()==x+s.squareSize && s.getY() == y && s.stopped){
if(x>=270){
return true;
}
}
return false;
}
}