-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleft.java
181 lines (174 loc) · 4.09 KB
/
sleft.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package NetworkTetris;
import java.awt.*;
import java.applet.*;
public class sleft extends Block
{ /**The identifier for this piece is 3
**/
private final int ident=3;
/**The Color for this piece
**/
private Color c= new Color(0,0,200);
/**The Blocks used to make this piece
**/
private Block top,leftmid,rightmid,bottom;
/**The default starting Location is (1,5)
**/
private Location def=new Location (1,5);
private int rotation=1;
private Grid gr;
// private ShadowBlock sb;
/**
*adds a sleft to the player grid
**/
public sleft(Grid grd)
{
top=new Block(c,grd,def,ident);
rightmid=new Block(c,grd,top.getLoc().getDown(),ident);
leftmid=new Block(c,grd,rightmid.getLoc().getLeft(),ident);
bottom=new Block(c,grd,leftmid.getLoc().getDown(),ident);
gr=grd;
// sb=new ShadowBlock(grd,this);
}
/**
*adds a sleft to the a grid with the specified offsets
**/
public sleft(Grid grd,int x,int y)
{
top=new Block(c,grd,def,x,y,ident);
rightmid=new Block(c,grd,top.getLoc().getDown(),x,y,ident);
leftmid=new Block(c,grd,rightmid.getLoc().getLeft(),x,y,ident);
bottom=new Block(c,grd,leftmid.getLoc().getDown(),x,y,ident);
gr=grd;
}
/**
*Returns top Block
**/
public Block getTop()
{
return top;
}
/**
*Returns leftmid Block
**/
public Block getLeftMid()
{
return leftmid;
}
/**
*Returns rightmid Block
**/
public Block getRightMid()
{
return rightmid;
}
/**
*Returns bottom Block
**/
public Block getBottom()
{
return bottom;
}
/**
*checks all necessary conditions and moves this sleft piece left
**/
public void moveLeft()
{if(top.isLeftTrue() && rightmid.isLeftTrue() &&leftmid.isLeftTrue() && bottom.isLeftTrue())
{
top.moveLeft();
rightmid.moveLeft();
leftmid.moveLeft();
bottom.moveLeft();
}
}
/**
*checks all necessary conditions and moves this sleft piece right
**/
public void moveRight()
{if(top.isRightTrue() && rightmid.isRightTrue() && bottom.isRightTrue() && leftmid.isRightTrue())
{
top.moveRight();
rightmid.moveRight();
bottom.moveRight();
leftmid.moveRight();
}
}
/**
*checks all necessary conditions and moves this sleft piece down
**/
public void softDrop()
{if(bottom.isDownTrue() && top.isDownTrue() &&rightmid.isDownTrue()&&leftmid.isDownTrue())
{
top.softDrop();
rightmid.softDrop();
bottom.softDrop();
leftmid.softDrop();
}
else
{
top.stop();
leftmid.stop();
bottom.stop();
rightmid.stop();
}
}
/**
*returns if the sleft is moving
**/
public boolean getMoving()
{
if(top.getMoving())
return true;
return false;
}
/**
*moves the sleft as far down as possible and sets the moving to false
**/
public void hardDrop()
{
while(getMoving())
{
softDrop();
}
}
/**
*rotates the sleft piece
**/
public void rotate()
{
if(getMoving())
{
if(rotation%2==0)
{
Block test =new Block(c,gr, top.getLoc().getUp(),ident);
if(leftmid.isRightTrue()&&test.isUpTrue())
{
leftmid= new Block(c,gr, leftmid.getLoc(),ident);
bottom = new Block(c,gr, leftmid.getLoc().getDown(),ident);
rightmid = new Block(c,gr, leftmid.getLoc().getRight(),ident);
top=new Block(c,gr, rightmid.getLoc().getUp(),ident);
rotation++;
}
}
else if(rotation%2==1)
{ Block test= new Block(c,gr,rightmid.getLoc().getRight().getDown(),ident);
Block test2= new Block(c,gr,rightmid.getLoc().getRight(),ident);
if(leftmid.isLeftTrue()&&bottom.isRightTrue())
{
leftmid= new Block(c,gr, leftmid.getLoc(),ident);
bottom = new Block(c,gr, leftmid.getLoc().getLeft(),ident);
rightmid = new Block(c,gr, leftmid.getLoc().getDown(),ident);
top=new Block(c,gr, rightmid.getLoc().getRight(),ident);
rotation++;
}
else if(!leftmid.isLeftTrue()&&rightmid.isRightTrue()&& test.isRightTrue() && test2.isDownTrue())
{
bottom=new Block(c,gr,leftmid.getLoc(),ident);
leftmid=new Block(c,gr,bottom.getLoc().getRight(),ident);
rightmid=new Block(c,gr,leftmid.getLoc().getDown(),ident);
top=new Block(c,gr,rightmid.getLoc().getRight(),ident);
rotation++;
}
}
}
}
}