📄 russiabox.java
字号:
try
{
Thread.sleep(time);
}
catch (InterruptedException e)
{
}
}
public void run()
{
while (timer != null)
{
judge();
cool.reset(0,15);
repaint();
sleep(level);
draw_string(getGraphics());
if(candown)
{
judge();
cool.reset(0,15);
}
repaint();
sleep(level);
draw_string(getGraphics());
if(candown)
{
judge();
cool.reset(0,15);
}
repaint();
sleep(level);
draw_string(getGraphics());
repaint();
}
timer = null;
}
public void judge_line()
{
int bb=0;
for(int i=0;i<back_height/15;i++)
{
int totle= 0;
for(int j=0;j<back_width/15;j++)
{
totle+=save_h[i].pos[j];
if(save_h[0].pos[j]== 1)
{
timer= null;
restart= true;
GameOver= true;
break;
}
}
if(totle== 22)
{
save_h[i].clear();
change(i);
score+= 10;
bb++;
}
}
if(bb>1)
score+=bb*15;
aa.setText("Your score:"+score);
}
public void change(int index_i)
{
for(int i= index_i;i>0;i--)
{
save_h[i]= save_h[i-1];
}
save_h[0].clear();
}
public boolean judge()
{
boolean real2= false;
boolean real= false;
for(int j=0;j<cool.totle;j++)
{
if(((cool.rect[j].y/15)< 23)&&((cool.rect[j].x/15)<22))
if(save_h[(cool.rect[j].y/15+1)].pos[(cool.rect[j].x/15)]==1)
real= true;
if(cool.rect[j].y+15>=back_height)
real2= true;
}
if(real2||real)
{
candown= false;
save_img(real);
judge_line();
turn_i=0;
int type;
int cu_x;
Random r= new Random();
type= Math.abs(r.nextInt()%7);
cu_x= Math.abs(r.nextInt()%22);
cu_x*= 15;
if(cu_x<back_width/2)
cu_x+=30;
else
cu_x-=30;
cool= null;
cool= new Style(type,cu_x);
repaint();
judge();
real=false;
return true;
}
return false;
}
public void save_img(boolean real)
{
for(int j=0;j<cool.totle;j++)
{
save_h[(cool.rect[j].y/15)].pos[(cool.rect[j].x/15)]=1;
}
sleep(2*level);
}
public void draw_string(Graphics g)
{
g.setFont(f);
int x, y;
phase--;
if (phase < 0)
phase=strlen-1;
for(int i=0;i<strlen;i++)
{
x = charOffsets[i];
g.setColor(colors[(phase+i)%strlen]);
g.drawChars(theChars,i,1,x,yOffset);
}
}
public void update(Graphics g)
{
if(GameOver)
{
g.setColor(Color.black);
g.fillRect(0,0,back_width,back_height);
g.setFont(new Font("ITALIC",Font.PLAIN+Font.BOLD,18));
g.setColor(Color.yellow);
g.drawString("Sorry! Game over!",80,100);
g.drawString("Please push 'Begin' button",40,130);
}else
{
offscrean_g.setColor(Color.green);
offscrean_g.fillRect(0,0,back_width,back_height);
cool.paint(offscrean_g);
for(int j=0;j<back_height/15;j++)
{
for(int i=0;i<back_width/15;i++)
{
if(save_h[j].pos[i]==1)
draw_one(offscrean_g,i*15,j*15);
}
}
g.drawImage(offscrean_image,0,0,this);
g.setColor(Color.darkGray);
g.drawRect(back_width,0,468-back_width-2,360-2);
g.setColor(Color.white);
g.drawLine(back_width+1,1,back_width+1,360-3);
g.drawLine(back_width+1,1,470-3,1);
g.drawLine(back_width,360-1,470-1,360-1);
g.drawLine(470-1,0,470-1,360-1);
}
draw_string(g);
}
public void draw_one(Graphics g,int x,int y)
{
int width= 15;
int height= 15;
Color color = Color.red;
g.setColor(color);
g.fillRect(x,y,width,height);
g.setColor(Color.lightGray);
g.drawLine(x,y,x+width-1,y);
g.drawLine(x+1,y+1,x+width-2,y+1);
g.drawLine(x,y,x,y+height-1);
g.drawLine(x+1,y+1,x+1,y+height-2);
g.setColor(color.darker());
g.drawLine(x+width-1,y,x+width-1,y+height-1);
g.drawLine(x+width-2,y+1,x+width-2,y+height-2);
g.drawLine(x+1,y+height-2,x+width-2,y+height-2);
g.drawLine(x,y+height-1,x+width-1,y+height-1);
}
public void paint(Graphics g)
{
showStatus("HELJ made");
update(g);
}
public boolean handleEvent(Event evt)
{
if(evt.id== Event.KEY_ACTION_RELEASE)
candown= false;
if(evt.id == Event.KEY_ACTION)
{
switch (evt.key)
{
case Event.UP:
boolean dox= false;
Style testx= new Style(cool.style,30);
for(int j=0;j<testx.totle;j++)
{
testx.rect[j].x=cool.rect[j].x;
testx.rect[j].y= cool.rect[j].y;
}
testx.turn(turn_i%testx.rect_turn);
for(int j=0;j<testx.totle;j++)
{
if(((testx.rect[j].x/15)<=0)||(testx.rect[j].x>=back_width)||((testx.rect[j].y/15)>=23))
dox= true;
}
if(!dox)
{
cool= testx;
turn_i++;
}
break;
case Event.DOWN:
candown= true;
break;
case Event.RIGHT:
for(int j=0;j<cool.totle;j++)
{
if(((cool.rect[j].y/15)< 23)&&((cool.rect[j].x/15)<22))
if(save_h[(cool.rect[j].y/15)].pos[(cool.rect[j].x/15)+1]==1)
return true;
if(cool.rect[j].x+15>= back_width)
return true;
}
cool.reset(15,0);
repaint();
break;
case Event.LEFT:
for(int j=0;j<cool.totle;j++)
{
if((cool.rect[j].x/15)>0)
if(save_h[(cool.rect[j].y/15)].pos[(cool.rect[j].x/15)-1]==1)
return true;
if(cool.rect[j].x<=0)
return true;
}
cool.reset(-15,0);
repaint();
break;
}
return true;
}
if(evt.id == Event.ACTION_EVENT)
{
if(evt.target instanceof Choice)
{
if(evt.arg=="Level")
level= 100;
if(evt.arg=="Level1")
level= 85;
if(evt.arg=="Level2")
level= 70;
if(evt.arg=="Level3")
level= 50;
if(evt.arg=="Level4")
level= 25;
}
if(evt.target instanceof Button)
{
if(evt.arg=="Begin")
{
//if(GaveOver)
for(int k=0;k<back_height/15;k++)
save_h[k].clear();
score= 0;
aa.setText("Your score:"+score);
repaint();
if(timer== null)
{
GameOver= false;
timer = new Thread(this);
timer.start();
}
if(restart)
{
timer.resume();
restart= false;
}
return true;
}
if(evt.arg== "Stop")
{
timer.suspend();
restart= true;
return true;
}
}
}
return super.handleEvent( evt );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -