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

📄 single.java

📁 java写的五子连游戏,有声音和优美的画面
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					outname.println(strname[0]);
					outscore.println(oldscore[0]);
				}
				else
				{
					
					String input=JOptionPane.showInputDialog("输入您的名字:");
					outname.println(strname[0]);
					outscore.println(oldscore[0]);
					outname.println(input);
					outscore.println(score);
				}
			}
			else
			{
				String input=JOptionPane.showInputDialog("输入您的名字:");
				outname.println(input);
				outscore.println(score);				
			}
			infile1.close();
			infile2.close();
			outname.close();
			outscore.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public boolean cleanBall() {
		//从左到右
		for(int x=0;x<9;x++)
			for(int y=0;y<6;y++)
			{  
				int i1=1;
				while(y+i1<9 && FACE[x][y]!=0 && FACE[x][y]==FACE[x][y+i1])
				{ i1++;}
		        if(i1>=5)
		        {
		        	cleanSound.play();
			        for(int k1=0;k1<i1;k1++)
			        {
			        	FACE[x][y+k1]=0;
			        	md.showMap(x, y+k1, 0);
			        	try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
			        }
			        score+=i1;
			        countScore();
			        return true;
		        }
		        else
		        	continue;
			}
		//从上到下
	    for(int y=0;y<9;y++)
	    	for(int x=0;x<6;x++)
	    	{   
	    		int i2=1;
	    		while(x+i2<9 && FACE[x][y]!=0 && FACE[x][y]==FACE[x+i2][y])
	    		        {i2++;}
	    		if(i2>=5)
	    		{
	    			cleanSound.play();
	    			for(int k2=0;k2<i2;k2++)
	    			{
	    				FACE[x+k2][y]=0;
	    				md.showMap(x+k2, y, 0);
	    				try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
	    			}
	    			score+=i2;
	    			countScore();
	    			return true;
	    		}
	    		else
	    			continue;
	    	}
	    //从左上到右下
	     for(int x=0;x<5;x++)
	        for(int y=0;y<5;y++)
	        {   
	        	int i3=1;
	    		while(x+i3<9 && y+i3<9 && FACE[x][y]!=0 && FACE[x][y]==FACE[x+i3][y+i3])
	    		        {i3++;}
	    		if(i3>=5)
	    		{
	    			cleanSound.play();
	    			for(int k3=0;k3<i3;k3++)
	    			{
	    				FACE[x+k3][y+k3]=0;
	    				md.showMap(x+k3, y+k3, 0);
	    				try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
	    			}
	    			score+=i3;
	    			countScore();
	    			return true;
	    		}
	    		else
	    			continue;
	    	}
	    	//从右上到左下
	    	 for(int x=8;x>3;x--)
	    	   for(int y=0;y<5;y++)
	    	   {   
	    		   int i4=1;
	    		   while(x-i4>=0 && y+i4<9 && FACE[x][y]!=0 && FACE[x][y]==FACE[x-i4][y+i4])
	    		        {i4++;}
	    		   if(i4>=5)
	    		   {
	    			   cleanSound.play();
	    			   for(int k4=0;k4<i4;k4++)
	    			   {
	    				FACE[x-k4][y+k4]=0;
	    				md.showMap(x-k4, y+k4, 0);
	    				try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
	    			   }
	    			  score+=i4;
	    			  countScore();
	    			  return true;
	    		   }
	    		else
	    			continue;
	    	  }
	    	 return false;
	}
	private void countScore() {
		md.showScore(score);
	    md.update();
	}
	public void randomShowThreeBall() {
		//在地图上显示下三个球
		int count=0;
		int i=0;
		for(int m=0;m<9;m++)
			for(int n=0;n<9;n++)
			{
				if(FACE[m][n]==0)
					count++;
			}
		if(count<3)
		{
			//JOptionPane.showMessageDialog(null, "YOU LOSE!", "提示",
			//		JOptionPane.ERROR_MESSAGE);
			gameoverSound.play();
			md.showGameOver();
			isGameOver=true;
			recordOrder();
			return;
		}
		
		do
		{
			randPosition();
			if(FACE[X][Y]==0)
			{
				md.showMap(X,Y,mode[i]);
				FACE[X][Y]=mode[i];
				i++;
				cleanBall();
			}
		}while(i<3);
	}

	public void randomNextThreeBall() {
		//随机产生下三个球的颜色,并在状态区显示 
		mode[0]=((int )(10*Math.random()))%7+1;
		mode[1]=((int )(10*Math.random())%7)+1;
		mode[2]=((int )(10*Math.random())%7)+1;
		md.shownextStatus(0, 0, mode[0]);
		md.shownextStatus(1, 0, mode[1]);
		md.shownextStatus(2, 0, mode[2]);
	}
	
	public void randPosition() {
		//随机产生球的位置
		X=((int)(10*Math.random()))%9;
		Y=((int)(10*Math.random()))%9;
	}
	
	public boolean checkPath(posType start,posType end) {
		
		Stack<sElemType> s=new Stack<sElemType>();
		sElemType e;
		posType curpos=start;
		int curstep=1;
		int i=0;
		do{
			if(pass(curpos))  //当前位置可以通过
			{
				footPrint(curpos);
				e=new sElemType(curstep,curpos,1);
				s.push(e);
				if(i==2)
				{
					System.out.println(curpos.X+"  "+curpos.Y);
					System.out.println(end.X+"  "+end.Y);
				}
				if(curpos.X==end.X && curpos.Y==end.Y)
				{
					return true;
				}
				curpos=nextPos(curpos,1);
				curstep++;
			}
			else              //当前位置不能通过
			{
				if(!s.empty())
				{
					e=s.pop();
					while(e.di==4 && !s.empty())
					{
						markPrint(e.seat);
						e=s.pop();
					}
					if(e.di<4)
					{
						e.di++;
						s.push(e);
						curpos=nextPos(e.seat,e.di);
					}
				}
			}
		}while(!s.empty());
		return false;
	}
	
	private void markPrint(posType seat) {
		if(seat.X>=0 && seat.X<9 && seat.Y<9 && seat.Y>=0 )
		{
			adr[seat.X][seat.Y]='#';
		}
		
	}
	private posType nextPos(posType curpos, int i) {
		switch(i)
		{
		case 1:
			return new posType((curpos.X)+1,curpos.Y); //下一位置为东
		case 2:
			return new posType(curpos.X,(curpos.Y)+1); //下一位置为南
		case 3:
			return new posType((curpos.X)-1,curpos.Y); //下一位置为西
		case 4:
			return new posType(curpos.X,(curpos.Y)-1); //下一位置为北
		}
		return null;
	}
	private void footPrint(posType curpos) {
		if(curpos.X>=0 && curpos.Y<9 && curpos.Y>=0 && curpos.X<9)
		{
			adr[curpos.X][curpos.Y]='*';
		}
		
	}
	
	private boolean pass(posType curpos) {
	
		if(curpos.X>=0 && curpos.Y<9 && curpos.Y>=0 && curpos.X<9)
		{
			if(adr[curpos.X][curpos.Y]==' ')
			{
				return true;
			}
			else
				return false;
		}
		else
			return false;
	}
	public void mouseEntered(MouseEvent e) {
		
	}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {
		m.setCursor(Cursor.HAND_CURSOR);
	}
	public void mouseReleased(MouseEvent e) {}
	
	public void run() {

		int x=MOUSE_X;
		int y=MOUSE_Y;
		while(true)
		{
			md.showMap(x, y, 0);
			md.update();
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			md.showMap(x, y, status);
			md.update();
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
	}
	public void mouseDragged(MouseEvent e) {}

	public void mouseMoved(MouseEvent e) {
		setMouseMenuPosition(e);
		if(((MENU_X==0 && MENU_Y==0)||(MENU_X==0 && MENU_Y==2)||(MENU_X==0 && MENU_Y==4)))    //开始菜单
		{  
				m.setCursor(Cursor.HAND_CURSOR);
		}
		else
		{
			m.setCursor(Cursor.DEFAULT_CURSOR);
		}
	}

}

⌨️ 快捷键说明

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