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

📄 centerjpanel.java

📁 五子连珠游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		    		if(form[loctionx][loctiony]==1)
		    			generate();
		    		color=next[i].getcolor();
		    		colorAll[color]++;
		    		form[loctionx][loctiony]=1;
		    		deal(loctionx,loctiony,color);
		    		formpicture[loctionx][loctiony].alterColor(color);
		    		ballAll++;
		    		//System.out.println("endcolor4 "+formpicture[endx][endy].getcolor());
		    		if(ballAll>=81)
		    		{
		    			String inputValue = JOptionPane.showInputDialog("Please input your name!");
		    		    int score;
		    		    String name1;
		    		    int key=0;
		    			for(int j=0;i<5;i++)
		    			{
		    				if(scoreNow>=name[j].getScore())
		    				{
		    						key=1;
		    						name1=name[j].getName();
		    						name[j].alterName(inputValue);
		    						inputValue=name1;
		    						score=name[j].getScore();
		    						name[j].alterScore(scoreNow);
		    						scoreNow=score;		    					
		    				}
		    			}
		    			if(key==1)
		    			{
		    				try{
		    					
		    					outputFile();//throws ClassNotFoundException,IOException
		    				}catch(IOException e){
		    					System.out.println("11yichang");
		    				
		    				}catch (ClassNotFoundException e){}
		    			}
		    			else
		    		   {
		    			JOptionPane.showMessageDialog(null,
	                           "Game over!Thank you!",
	                            "Goodbye",
	                                   JOptionPane.OK_OPTION);
		    		    }
		    		    System.exit(0);
		    	    }
		    	}
		    	//System.out.println("endcolor "+formpicture[endx][endy].getcolor());
		    	for(int i=0;i<3;i++)                                     //nextcolor 
				{
					generate();
					next[i].setjform(loctionx,loctiony,color);
					//next[i]=new jform(loctionx,loctiony);
					//System.out.println(loctionx+" "+loctiony+" "+color);
					
					//next[i].alterColor(color);
					if(menukey)
					deal(i,color);
				    //next[i].setSize(10,10);无效,取决于图的大小?	    
				}
		    	showscores.alter(colorAll,colorCleared);
				showscores.show(showkey);
				//System.out.println(ballAll+" ");
		    }
		    	
		    //System.out.println(endx+"eowie");		//
		}
		
	}
	
	//排行榜的保存,保存于文件scores.txt
	public  void outputFile() throws ClassNotFoundException,IOException
	{
	    File outFile=new File("scores.txt");
	    FileOutputStream outFileStream=new FileOutputStream(outFile);
	    ObjectOutputStream outObjectStream=new ObjectOutputStream(outFileStream);
        for(int i=0;i<5;i++)
        {
        	outObjectStream.writeObject(name[i]);
        }
        outObjectStream.close();
	}
	
	
	JLabel beforePicture,nowPicture;//用于改变主类两侧的图像
	public void clearUp(int endx,int endy)
	{
		int colorend=formpicture[endx][endy].getcolor();int MAX=3,key=0;
		int count=0,i,j;int upNum=0,downNum=0,upDownNum=0;
		//上下
		for(i=1;i+endx<9;i++)
			if(form[endx+i][endy]==1&&formpicture[endx+i][endy].getcolor()==colorend)
			{
				count++;
				upNum++;
			}
			else break;
		for(j=1;endx-j>-1;j++)
			if(form[endx-j][endy]==1&&formpicture[endx-j][endy].getcolor()==colorend)
			{
				count++;
				downNum++;
			}
			else break;
		if(count>MAX)
		{
			key=1;
			upDownNum=count;
			for(i=1;i<=upNum;i++)
			{
				form[endx+i][endy]=0;
				deal(endx+i,endy,7);
				formpicture[endx+i][endy].alterColor(7);
			}
			for(j=1;j<=downNum;j++)
			{
				form[endx-j][endy]=0;
				deal(endx-j,endy,7);
				formpicture[endx-j][endy].alterColor(7);
			}
		}
		//左右
		count=0;int rightNum=0,leftNum=0,rightLeftNum=0;
		for(i=1;i+endy<9;i++)
			if(form[endx][endy+i]==1&&formpicture[endx][endy+i].getcolor()==colorend)
			{
				count++;
				rightNum++;
			}
			else
				break;
		for(j=1;endy-j>-1;j++)
			if(form[endx][endy-j]==1&&formpicture[endx][endy-j].getcolor()==colorend)
			{
				count++;
				leftNum++;
			}
			else
				break;
		if(count>MAX)
		{
			key=1;
			rightLeftNum=count;
			for(i=1;i<=rightNum;i++)
			{
				form[endx][endy+i]=0;
				deal(endx,endy+i,7);
				formpicture[endx][endy+i].alterColor(7);
			}
			for(j=1;j<=leftNum;j++)
			{
				form[endx][endy-j]=0;
				deal(endx,endy-j,7);
				formpicture[endx][endy-j].alterColor(7);
			}
		}
		//右斜上
		count=0;int rightUp=0,leftDown=0,rightUpNum=0;
		for(i=1;i+endy<9&&endx-i>-1;i++)
			if(form[endx-i][endy+i]==1&&formpicture[endx-i][endy+i].getcolor()==colorend)
			{
				count++;
				rightUp++;
			}
			else
				break;
		for(j=1;endy-j>-1&&endx+j<9;j++)
			if(form[endx+j][endy-j]==1&&formpicture[endx+j][endy-j].getcolor()==colorend)
			{
				count++;
				leftDown++;
			}
			else
				break;
		if(count>MAX)
		{
			key=1;
			rightUpNum=count;
			for(i=1;i<=rightUp;i++)
			{
				formpicture[endx-i][endy+i].alterColor(7);
				form[endx-i][endy+i]=0;
				deal(endx-i,endy+i,7);
			}

			for(j=1;j<=leftDown;j++)
			{
				formpicture[endx+j][endy-j].alterColor(7);
				form[endx+j][endy-j]=0;
				deal(endx+j,endy-j,7);
			}
		}
		//左斜上
		count=0;int leftUp=0,rightDown=0,leftUpNum=0;
		for(i=1;i+endx<9&&endy+i<9;i++)
			if(form[endx+i][endy+i]==1&&formpicture[endx+i][endy+i].getcolor()==colorend)
			{
				count++;
				leftUp++;
			}
			else
				break;
		for(j=1;endx-j>-1&&endy-j>-1;j++)
			if(form[endx-j][endy-j]==1&&formpicture[endx-j][endy-j].getcolor()==colorend)
			{
				count++;
				rightDown++;
			}
			else
				break;
		if(count>MAX)
		{
			key=1;
			leftUpNum=count;

			for(i=1;i<=leftUp;i++)
			{
				formpicture[endx+i][endy+i].alterColor(7);
				form[endx+i][endy+i]=0;
				deal(endx+i,endy+i,7);
			}
			for(j=1;j<=rightDown;j++)
			{
				formpicture[endx-j][endy-j].alterColor(7);
				form[endx-j][endy-j]=0;
				deal(endx-j,endy-j,7);
			}
			
		}
		if(key==1)
		{
			System.out.println("key="+key);
			form[endx][endy]=0;
		    deal(endx,endy,7);
		    formpicture[endx][endy].alterColor(7);
		    this.scoreNow=this.scoreNow+(upDownNum+rightLeftNum+rightUpNum+leftUpNum+1)*2;
		    colorCleared[colorend]=colorCleared[colorend]+upDownNum+rightLeftNum+rightUpNum+leftUpNum+1;
		    colorAll[colorend]-=(upDownNum+rightLeftNum+rightUpNum+leftUpNum+1);
		    ballAll-=(upDownNum+rightLeftNum+rightUpNum+leftUpNum+1);
		}
		if(scoreNow>scoreBefore)
		{
			beforePicture.setIcon(new ImageIcon("king2.gif"));	
			nowPicture.setIcon(new ImageIcon("client10.gif"));	
		}
		scorenow=""+scoreNow;
		textField2.setText(scorenow); 
		
		//showscores.alter(colorAll,colorCleared);
		//showscores.show(showkey);
		
		//text2Jpanel.add(textField2);

	    //System.out.println(scorenow);
	}
	/*public void show()
	{
		int i;String scoreNum;JLabel number;Container content;
		showwindow=new JFrame();
		content=showwindow.getContentPane();
		content.setLayout(new GridLayout(8,3));  
		content.setBackground(Color.black); 
		//showwindow.setBackground(new Color(0,0,0));
		//showwindow.setLayout();	
		for(i=0;i<7;i++)
		{
			colorShow[i]=new jform();
			colorShow[i].setcon(i);
			content.add(colorShow[i].con);
			scoreNum=""+colorCleared[i];
			number=new JLabel(scoreNum);
			content.add(number);
			scoreNum="del"+colorCleared[i];
			content.add(number);	
		}
		setVisible(true);
		//showwindow.setDefaultCloseOperation(HIDE_ON_CLOSE);	
	
	}*/
		
	public void mouseReleased(MouseEvent event){}
	


public void showNum(boolean key)
{
	showkey=key;
	showscores.showKey(key);
	
}
/*public void showNum {
	private static final int WIDTH=100;
	private static final int HEIGHT=310;
	JFrame window=new JFrame();
	int i;String scoreNum;JLabel number1[]=new JLabel[8];Container content;jform colorShow[]=new jform[8];
	//showwindow=new JFrame();
	JLabel number2[]=new JLabel[8];
	public void initShow(centerJPanel centerjpanel)
	{
		int otherAll=0;
	content=window.getContentPane();
	content.setLayout(new GridLayout(8,3));  
	content.setBackground(Color.gray); 
	//showwindow.setBackground(new Color(0,0,0));
	//showwindow.setLayout();	
	for(i=0;i<7;i++)
	{
		setSize (WIDTH,HEIGHT);
		colorShow[i]=new jform();
		colorShow[i].setcon(i);
		content.add(colorShow[i].con);
		scoreNum=""+centerjpanel.colorAll[i];
		otherAll+=centerjpanel.colorAll[i];
		number1[i]=new JLabel(scoreNum);
		content.add(number1[i]);
		scoreNum="del"+centerjpanel.colorCleared[i];
		number2[i]=new JLabel(scoreNum);
		content.add(number2[i]);	
	}
	colorShow[i]=new jform();
	colorShow[i].setcon(i);
	content.add(colorShow[i].con);
	scoreNum=""+(81-otherAll);
	number1[i]=new JLabel(scoreNum);
	content.add(number1[i]);
	//scoreNum="del"+centerjpanel.colorCleared[i];
	//number=new JLabel(scoreNum);
	//content.add(number1[i]);
	
	setDefaultCloseOperation(HIDE_ON_CLOSE);	
	setVisible(true);
	}
	public showNum(int colorAll[],int colorCleared[])
	{
		int i=0,otherAll=0;
		for(;i<7;i++)
		{
			otherAll+=colorAll[i];
			scoreNum=""+colorAll[i];
			number1[i].setText(scoreNum);
			scoreNum="del"+colorCleared[i];
			number2[i].setText(scoreNum);
		}
		scoreNum=""+(81-otherAll);
		number1[i].setText(scoreNum);
		
	}*/

}

⌨️ 快捷键说明

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