⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myeluosi.java

📁 完全自己做的俄罗斯方块
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				x3 = fourpoint3.getX();
				y4 = fourpoint4.getY();
				x4 = fourpoint4.getX();
				
				while( y<600&&y2<600&&y3<600&&y4<600&&
						c.getComponentAt(x,y+60).isEnabled()&&
						c.getComponentAt(x2,y2+60).isEnabled()&&
						c.getComponentAt(x3,y3+60).isEnabled()&&
						c.getComponentAt(x4,y4+60).isEnabled() ){
					x = fourpoint1.getX(); y = fourpoint1.getY()+60;
					x2 = fourpoint2.getX(); y2 = fourpoint2.getY()+60;
					x3 = fourpoint3.getX(); y3 = fourpoint3.getY()+60;
					x4 = fourpoint4.getX(); y4 = fourpoint4.getY()+60;
        			try{
            			Thread.sleep(slep);
            			fourpoint1.setLocation(x,y);
            			fourpoint2.setLocation(x2,y2);
            			fourpoint3.setLocation(x3,y3);
            			fourpoint4.setLocation(x4,y4);
        			}catch(InterruptedException e){}      
        		}
        		//当方块遇到障碍物时不可再用
                int foury1 = fourpoint1.getY()+60;
                int fourx1 = fourpoint1.getX();
                int foury2 = fourpoint2.getY()+60;
                int fourx2 = fourpoint2.getX();
                int foury3 = fourpoint3.getY()+60;
                int fourx3 = fourpoint3.getX();
                int foury4 = fourpoint4.getY()+60;
                int fourx4 = fourpoint4.getX();
                
                if(foury1==660||!c.getComponentAt(fourx1,foury1).isEnabled()){
                	fourpoint1.setBackground(Color.magenta);
                	fourpoint2.setBackground(Color.magenta);
                	fourpoint3.setBackground(Color.magenta);
                	fourpoint4.setBackground(Color.magenta);
                	fourpoint1.setEnabled(false);
                	fourpoint2.setEnabled(false);
                	fourpoint3.setEnabled(false);
                	fourpoint4.setEnabled(false);
                	ClearRows();
                	getRandomDiamonds();
                }
                else if(foury2==660||!c.getComponentAt(fourx2,foury2).isEnabled()){
                	fourpoint1.setBackground(Color.magenta);
                	fourpoint2.setBackground(Color.magenta);
                	fourpoint3.setBackground(Color.magenta);
                	fourpoint4.setBackground(Color.magenta);
                	fourpoint1.setEnabled(false);
                	fourpoint2.setEnabled(false);
                	fourpoint3.setEnabled(false);
                	fourpoint4.setEnabled(false);
                	ClearRows();
                	getRandomDiamonds();
                }
                else if(foury3==660||!c.getComponentAt(fourx3,foury3).isEnabled()){
                	fourpoint1.setBackground(Color.magenta);
                	fourpoint2.setBackground(Color.magenta);
                	fourpoint3.setBackground(Color.magenta);
                	fourpoint4.setBackground(Color.magenta);
                	fourpoint1.setEnabled(false);
                	fourpoint2.setEnabled(false);
                	fourpoint3.setEnabled(false);
                	fourpoint4.setEnabled(false);
                	ClearRows();
                	getRandomDiamonds();
                }
                else if(foury4==660||!c.getComponentAt(fourx4,foury4).isEnabled()){
                	fourpoint1.setBackground(Color.magenta);
                	fourpoint2.setBackground(Color.magenta);
                	fourpoint3.setBackground(Color.magenta);
                	fourpoint4.setBackground(Color.magenta);
                	fourpoint1.setEnabled(false);
                	fourpoint2.setEnabled(false);
                	fourpoint3.setEnabled(false);
                	fourpoint4.setEnabled(false);
                	ClearRows();
                	getRandomDiamonds();
                }
                
                DefineOver();
			}
		};
		thread.start();
		
    	KeyAdapter k;
    	
    	fourpoint1.addKeyListener(k = new KeyAdapter(){
            public void keyPressed(KeyEvent e){
                int key = e.getKeyCode();
                x = fourpoint1.getX();y = fourpoint1.getY();
                x2 = fourpoint2.getX();y2 = fourpoint2.getY();
                x3 = fourpoint3.getX();y3 = fourpoint3.getY();
                x4 = fourpoint4.getX();y4 = fourpoint4.getY();
    			int xx2,yy2,xx3,yy3,xx4,yy4;
                
                //使twopoint相应移动
                if(e.getKeyText(key).equals("Right")){
                	xx4 = x4;
                	xx3 = x3;
                	xx2 = x2;
                	xx = x;
                	x+=60;
                	x2+=60;
                	x3+=60;
                	x4+=60;
                	int foury1 = fourpoint1.getY();
                	int fourx1 = fourpoint1.getX()+60;
                	int foury2 = fourpoint2.getY();
                	int fourx2 = fourpoint2.getX()+60;  
                	int foury3 = fourpoint3.getY();
                	int fourx3 = fourpoint3.getX()+60;
                	int foury4 = fourpoint4.getY();
                	int fourx4 = fourpoint4.getX()+60;
                	
                	if(x>=0&&x<=600&&x2>=0&&x2<=600&&x3>=0&&
                		x3<=600&&x4>=0&&x4<=600&&
                		c.getComponentAt(fourx1,foury1).isEnabled()&&
                		c.getComponentAt(fourx2,foury2).isEnabled()&&
                		c.getComponentAt(fourx3,foury3).isEnabled()&&
                		c.getComponentAt(fourx4,foury4).isEnabled())
                		{
                		fourpoint1.setLocation(x,y);
                		fourpoint2.setLocation(x2,y2);
                		fourpoint3.setLocation(x3,y3);
                		fourpoint4.setLocation(x4,y4);
                	}
                	else{
                		x = xx;
                		x2 = xx2;
                		x3 = xx3;
                		x4 = xx4;
                	}
                }
                else if(e.getKeyText(key).equals("Left")){
                	xx4 = x4;
                	xx3 = x3;
                	xx2 = x2;
                	xx = x;
                	x-=60;
                	x2-=60;
                	x3-=60;
                	x4-=60;
                	int foury1 = fourpoint1.getY();
                	int fourx1 = fourpoint1.getX()-60;
                	int foury2 = fourpoint2.getY();
                	int fourx2 = fourpoint2.getX()-60;  
                	int foury3 = fourpoint3.getY();
                	int fourx3 = fourpoint3.getX()-60;
                	int foury4 = fourpoint4.getY();
                	int fourx4 = fourpoint4.getX()-60;
                	
                	if(x>=0&&x<=600&&x2>=0&&x2<=600&&x3>=0&&
                		x3<=600&&x4>=0&&x4<=600&&
                		c.getComponentAt(fourx1,foury1).isEnabled()&&
                		c.getComponentAt(fourx2,foury2).isEnabled()&&
                		c.getComponentAt(fourx3,foury3).isEnabled()&&
                		c.getComponentAt(fourx4,foury4).isEnabled())
                		{
                		fourpoint1.setLocation(x,y);
                		fourpoint2.setLocation(x2,y2);
                		fourpoint3.setLocation(x3,y3);
                		fourpoint4.setLocation(x4,y4);
                	}
                	else{
                		x = xx;
                		x2 = xx2;
                		x3 = xx3;
                		x4 = xx4;
                	}
                }
                else if(e.getKeyText(key).equals("Down")){
                	yy4 = y4;
                	yy3 = y3;
                	yy2 = y2;
                	yy = y;
                	y+=60;
                	y2+=60;
                	y3+=60;
                	y4+=60;
                	if(y<=600&&y2<=600&&y3<=600&&y4<=600){
                		fourpoint1.setLocation(x,y);
                		fourpoint2.setLocation(x2,y2);
                		fourpoint3.setLocation(x3,y3);
                		fourpoint4.setLocation(x4,y4);
                	}
                	else{
                		y = yy;
                		y2 = yy2;
                		y3 = yy3;
                		y4 = yy4;
                	}
                }
                //快速下降
                else if(e.getKeyText(key).equals("F")){
                	int fourx1 = fourpoint1.getX();
                	int foury1 = fourpoint1.getY();
                	int fourx2 = fourpoint2.getX();
                	int foury2 = fourpoint2.getY();
                	int fourx3 = fourpoint3.getX();
                	int foury3 = fourpoint3.getY();
                	int fourx4 = fourpoint4.getX();
                	int foury4 = fourpoint4.getY();
                	
                	while(c.getComponentAt(fourx1,foury1+60).isEnabled()&&
                			c.getComponentAt(fourx2,foury2+60).isEnabled()&&
                			c.getComponentAt(fourx3,foury3+60).isEnabled()&&
                			c.getComponentAt(fourx4,foury4+60).isEnabled()&&
                			foury1<600&&foury2<600&&foury3<600&&foury4<600){
                		foury1+=60;foury2+=60;foury3+=60;foury4+=60;
                	}
                	fourpoint1.setLocation(fourx1,foury1);
                	fourpoint2.setLocation(fourx2,foury2);
                	fourpoint3.setLocation(fourx3,foury3);
                	fourpoint4.setLocation(fourx4,foury4);
                	x = fourx1; y = foury1;x2 = fourx2; y2 = foury2;
                	x3 = fourx3; y3 = foury3;x4 = fourx4; y4 = foury4;
                }
                //找一下正方区域进行变形
                else if(e.getKeyText(key).equals("Space")){
                	int[] xx = new int[5];
                	int[] yy = new int[5];
                	xx[1] = fourpoint1.getX();
                	xx[2] = fourpoint2.getX();
                	xx[3] = fourpoint3.getX();
                	xx[4] = fourpoint4.getX();
                	yy[1] = fourpoint1.getY();
                	yy[2] = fourpoint2.getY();
                	yy[3] = fourpoint3.getY();
                	yy[4] = fourpoint4.getY();
                	
                	int left = xx[1]<xx[2] ? xx[1]:xx[2];
                	left = left<xx[3] ? left:xx[3];
                	left = left<xx[4] ? left:xx[4];
                	
                	int right = xx[1]>xx[2] ? xx[1]:xx[2];
                	right = right>xx[3] ? right:xx[3];
                	right = right>xx[4] ? right:xx[4];
                	
                	int top = yy[1]<yy[2] ? yy[1]:yy[2];
                	top = top<yy[3] ? top:yy[3];
                	top = top<yy[4] ? top:yy[4];
                	
                	int bottom = yy[1]>yy[2] ? yy[1]:yy[2];
                	bottom = bottom>yy[3] ? bottom:yy[3];
                	bottom = bottom>yy[4] ? bottom:yy[4];
                	
                	int max = (bottom-top)>(right-left) ? (bottom-top):(right-left);
                	
                	//判断是否可以变形
                	if(left>=0&&bottom<=600&&bottom>=max&&(
                		(right==left+60&&right<600)||
                		(right==left&&left>0&&right<540)||
                		(top==bottom&&right<=600)||
                		(right==left+120&&right<=600)
                		)){
						if(xx[1]==left&&yy[1]==bottom-max&&max!=180){
                			fourpoint1.setLocation(left,bottom);
                			x = left; y = bottom;
                		}
                		else if(xx[1]==left&&yy[1]==bottom&&max!=180){
                			fourpoint1.setLocation(left+max,bottom);
                			x = left+max; y = bottom;
                		}
                		else if(xx[1]==left+max&&yy[1]==bottom&&max!=180){
                			fourpoint1.setLocation(left+max,bottom-max);
                			x = left+max; y = bottom-max;
                		}
                		else if(xx[1]==left+max&&yy[1]==bottom-max&&max!=180){
                			fourpoint1.setLocation(left,bottom-max);
                			x = left; y = bottom-max;
                		}
                		else if(max==120&&xx[1]==left&&yy[1]==bottom-60){
                			fourpoint1.setLocation(left+60,bottom);
                			x = left+60; y = bottom;
                		}
                		else if(max==120&&xx[1]==left+60&&yy[1]==bottom){
                			fourpoint1.setLocation(left+max,bottom-60);
                			x = left+max; y = bottom-60;
                		}
                		else if(max==120&&xx[1]==left+max&&yy[1]==bottom-60){
                			fourpoint1.setLocation(left+60,bottom-max);
                			x = left+60; y = bottom-max;
                		}
                		else if(max==120&&xx[1]==left+60&&yy[1]==bottom-max){
                			fourpoint1.setLocation(left,bottom-60);
                			x = left; y = bottom-60;
                		}
                		else if(max==180&&top==bottom){
                			fourpoint1.setLocation(left+60,bottom);
                			fourpoint2.setLocation(left+60,bottom-60);
                			fourpoint3.setLocation(left+60,bottom-120);
                			fourpoint4.setLocation(left+60,bottom-180);
                			x = left+60; y = bottom;
                			x2 = left+60; y2 = bottom-60;
                			x3 = left+60; y3 = bottom-120;
                			x4 = left+60; y4 = bottom-180;
                		}
                		else if(max==180&&left==right){
                			fourpoint1.setLocation(left-60,bottom);
                			fourpoint2.setLocation(left,bottom);
                			fourpoint3.setLocation(left+60,bottom);
                			fourpoint4.setLocation(left+120,bottom);
                			x = left-60; y = bottom;
                			x2 = left; y2 = bottom;
                			x3 = left+60; y3 = bottom;
                			x4 = left+120; y4 = bottom;
                		}
                		
                		if(xx[2]==left&&yy[2]==bottom-max&&max!=180){
                			fourpoint2.setLocation(left,bottom);
                			x2 = left; y2 = bottom;
                		}
                		else if(xx[2]==left&&yy[2]==bottom&&max!=180){
                			fourpoint2.setLocation(left+max,bottom);
                			x2 = left+max; y2 = bottom;
                		}
                		else if(xx[2]==left+max&&yy[2]==bottom&&max!=180){
                			fourpoint2.setLocation(left+max,bottom-max);
                			x2 = left+max; y2 = bottom-max;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -