?? panel.java~460~
字號:
for (int j = 0; j < 4; j++) {
if (i != j)
if (block[i].getI(this) == block[j].getI(this) &&
block[i].getJ(this) + 1 == block[j].getJ(this))
count = true;
}
}
if (count == false)
down = false;
if (top < block[i].getJ(this))
top = block[i].getJ(this);
// System.out.println(top);
}
if (down == true) {
for (int i = 0; i < 4; i++)
Fill[block[i].getI(this)][block[i].getJ(this)] = 0;
for (int i = 0; i < 4; i++)
{
block[i].y+=20;
Fill[block[i].getI(this)][block[i].getJ(this)] = block[i].color;
}
repaint();
reachBelow = false;
} else
if (top >5) {
// System.out.println("*");
for (int i = 0; i < 4; i++)
Fill[block[i].getI(this)][block[i].getJ(this)] = block[i].color;
repaint();
reachBelow = true;
} else
{
for (int i = 0; i < 4; i++)
Fill[block[i].getI(this)][block[i].getJ(this)] = block[i].color;
repaint();
lose = true;
}
}
public void start() {
int temp=level;
pause=false;
if(begin)
{
play.play();
isRun=true;
downThread = new DownThread();
this.format();
level=temp;
downThread.start();
}
// moveThread.start();
}
public void Pause() {
pause = true;
}
public void Stop()
{
try {
pause=true;
isRun=false;
this.format();
Thread.sleep(100);
downThread.interrupt();
downThread=null;
} catch (Exception ex) {
}
repaint();
begin=true;
}
public void WIN()
{
for (int j = 4; j < 16; j++)
for (int i = 1; i < 10; i++)
Fill[i][j] = 0;
int colo = 7;
Fill[3][5] = Fill[3][6] = Fill[5][5] = Fill[5][6] = colo;
Fill[7][5] = Fill[7][6] = colo;
Fill[4][7] = Fill[4][8] = Fill[6][7] = Fill[6][8] = colo; //W
Fill[5][9] = Fill[5][10] = Fill[5][11] = colo; //I
Fill[4][12] = Fill[4][13] = Fill[4][14] = Fill[6][12] = colo;
Fill[6][13] = Fill[6][14] = colo;
Fill[5][13] = colo; //N
repaint();
}
public class DownThread extends Thread {
public void formatBlock(int ID) {
for (int i = 0; i < 4; i++)
block[i].setBlock( shape[ID][i]);
}
public void NextView(int ID) {
if (ID == 0) {
FillSmall[1][1] = shape[0][0].color;
FillSmall[1][2] = shape[0][0].color;
FillSmall[2][1] = shape[0][0].color;
FillSmall[2][2] = shape[0][0].color;
}
else
if (ID == 1) {
FillSmall[1][0] = shape[1][0].color;
FillSmall[1][1] = shape[1][0].color;
FillSmall[1][2] = shape[1][0].color;
FillSmall[1][3] = shape[1][0].color;
}
else
if (ID == 2) {
FillSmall[1][3] = shape[2][0].color;
FillSmall[2][3] = shape[2][0].color;
FillSmall[2][2] = shape[2][0].color;
FillSmall[3][3] = shape[2][0].color;
}
else
if (ID == 3) {
FillSmall[1][2] = shape[3][0].color;
FillSmall[1][3] = shape[3][0].color;
FillSmall[2][2] = shape[3][0].color;
FillSmall[3][2] = shape[3][0].color;
}
else
if (ID == 4) {
FillSmall[1][2] = shape[4][0].color;
FillSmall[2][2] = shape[4][0].color;
FillSmall[3][2] = shape[4][0].color;
FillSmall[3][3] = shape[4][0].color;
}
else
if (ID == 5) {
FillSmall[1][1] = shape[5][0].color;
FillSmall[2][1] = shape[5][0].color;
FillSmall[2][2] = shape[5][0].color;
FillSmall[3][2] = shape[5][0].color;
}
else {
FillSmall[1][3] = shape[6][0].color;
FillSmall[2][3] = shape[6][0].color;
FillSmall[2][2] = shape[6][0].color;
FillSmall[3][2] = shape[6][0].color;
}
}
public void NextViewFormat()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
FillSmall[i][j]=0;
}
public DownThread() {}
public void run() {
int current,next;
current=2;
next=random.nextInt(7);
while (!lose&&isRun) {
if (reachBelow == true)
{
// play3.play();
Clear(panel2,player2);
downBelow = reachBelow;
NextViewFormat();
NextView(next);
// if (begin)
// NextViewFormat();
begin = false;
currentBlockID = current;
formatBlock(current);
// System.out.println("next:"+next);
// System.out.println("current:"+current);
current=next;
next=random.nextInt(7);
}
try {
Thread.sleep(1000/level);
} catch (InterruptedException e) {}
if(!pause)
blockDown(block);
downBelow=reachBelow;
}
if(lose)
{
// System.out.println("*"+player2);
if(player2)
{
// JOptionPane.showMessageDialog(null, "YOU LOSE!");
panel2.WIN();
panel2.Pause();
}
Dialogs dialog = new Dialogs();
if (dialog.TOP10(result) && result > 0) {
// System.out.println("*")
dialog.set();
dialog.setVisible(true);
dialog.setAlwaysOnTop(true);
dialog.InputResult(result);
}
play.play();
for (int j = 15; j >= 4; j--) {
for (int i = 1; i < 10; i++)
Fill[i][j] = 7;
repaint();
try {
Thread.sleep(200);
} catch (InterruptedException e) {}
}
for (int j = 4; j < 16; j++) {
Fill[i][j] = 0;
repaint();
try {
Thread.sleep(200);
} catch (InterruptedException e) {}
}
if ( result == 0 || !dialog.TOP10(result) ) {
int time = 20;
while (time-- > 0) {
for (int j = 4; j < 16; j++)
for (int i = 1; i < 10; i++)
Fill[i][j] = 0;
repaint();
try {
Thread.sleep(200);
} catch (InterruptedException e) {}
int colour = 3;
Fill[1][5] = colour;
Fill[1][6] = colour;
Fill[3][5] = colour;
Fill[3][6] = colour;
Fill[2][7] = colour;
Fill[2][8] = colour;
Fill[2][9] = colour; //Y
Fill[4][5] = colour + 1;
Fill[5][5] = colour + 1;
Fill[6][5] = colour + 1;
Fill[4][6] = colour + 1;
Fill[6][6] = colour + 1;
Fill[4][7] = colour + 1;
Fill[6][7] = colour + 1;
Fill[4][8] = colour + 1;
Fill[6][8] = colour + 1;
Fill[4][9] = colour + 1; ;
Fill[5][9] = colour + 1;
Fill[6][9] = colour + 1;
//O
Fill[7][5] = colour + 2;
Fill[9][5] = colour + 2;
Fill[7][6] = colour + 2;
Fill[9][6] = colour + 2;
Fill[9][7] = colour + 2;
Fill[7][7] = colour + 2;
Fill[9][8] = colour + 2;
Fill[7][8] = colour + 2;
Fill[7][9] = colour + 2; ;
Fill[9][9] = colour + 2;
Fill[8][9] = colour + 2;
Fill[8][9] = colour + 2; //U
Fill[1][10] = colour + 2;
Fill[1][11] = colour + 2;
Fill[1][12] = colour + 2;
Fill[1][13] = colour + 2;
Fill[1][14] = colour + 2;
Fill[2][14] = colour + 2;
//L
Fill[3][10] = colour + 3;
Fill[3][11] = colour + 3;
Fill[3][12] = colour + 3;
Fill[3][13] = colour + 3;
Fill[3][14] = colour + 3;
Fill[5][10] = colour + 3;
Fill[5][11] = colour + 3;
Fill[5][12] = colour + 3;
Fill[5][13] = colour + 3;
Fill[5][14] = colour + 3; ;
Fill[4][10] = colour + 3;
Fill[4][14] = colour + 3;
//O
Fill[6][10] = colour + 4;
Fill[6][11] = colour + 4;
Fill[6][12] = colour + 4;
Fill[6][14] = colour + 4;
Fill[7][10] = colour + 4;
Fill[7][12] = colour + 4;
Fill[7][13] = colour + 4;
Fill[7][14] = colour + 4; //S
Fill[8][10] = colour;
Fill[8][11] = colour;
Fill[8][12] = colour;
Fill[8][13] = colour;
Fill[8][14] = colour;
Fill[9][10] = colour;
Fill[9][12] = colour;
Fill[9][14] = colour; //E
repaint();
// System.out.println("*");
try {
Thread.sleep(200);
} catch (InterruptedException e) {}
}
// JOptionPane.showMessageDialog(null, "YOU LOSE!");
}
}
}
}
private void jbInit() throws Exception {
}
public void this_keyPressed(KeyEvent e) {
// System.out.println("player2"+player2);
if(!pause && !player2 && !lose)
{
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
blockUp(block);
break;
case KeyEvent.VK_UP:
blockUp(block);
break;
case KeyEvent.VK_LEFT:
blockLeft(block);
break;
case KeyEvent.VK_A:
blockLeft(block);
break;
case KeyEvent.VK_D:
blockRight(block);
break;
case KeyEvent.VK_RIGHT:
blockRight(block);
break;
case KeyEvent.VK_S:
blockDown(block);
break;
case KeyEvent.VK_DOWN:
blockDown(block);
break;
}
}
/* else
if(player2 && VSID==1)
switch (e.getKeyCode()) {
case KeyEvent.VK_W:
blockUp(block);
break;
case KeyEvent.VK_A:
blockLeft(block);
break;
case KeyEvent.VK_D:
blockRight(block);
break;
case KeyEvent.VK_S:
blockDown(block);
break;
}
else
if(player2 && VSID==2)
{
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
blockUp(block);
break;
case KeyEvent.VK_LEFT:
blockLeft(block);
break;
case KeyEvent.VK_RIGHT:
blockRight(block);
break;
case KeyEvent.VK_DOWN:
blockDown(block);
break;
}
}*/
}
public void Switch(Block old[],Block ne[],int center)
{
for (int i = 0; i < 4; i++) {
if(i!=center)
{
try{
ne[i].x = -old[i].y + old[center].y + old[center].x;
ne[i].y = old[i].x - old[center].x + old[center].y;
}catch (Exception ex){}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -