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

📄 maze.java

📁 学习数据结构的最好辅助工具,快速帮助你熟悉数据结构的相关技术
💻 JAVA
字号:
import java.awt.*;
public class Maze extends Canvas
{
	char data[][] = {{'#','#','#','#','#','#','#','#','#','#'},
					 {'#','*',' ','#',' ',' ',' ','#',' ','#'},
					 {'#',' ',' ','#',' ',' ',' ','#',' ','#'},
					 {'#',' ',' ',' ',' ','#','#',' ',' ','#'},
					 {'#',' ','#','#','#',' ',' ',' ','#','#'},
					 {'#',' ',' ',' ','#',' ',' ',' ','#','#'},
					 {'#',' ','#',' ',' ',' ','#',' ',' ','#'},
					 {'#','#','#','#','#',' ','#','#',' ','#'},
					 {'#',' ',' ',' ',' ',' ',' ',' ','@','#'},
					 {'#','#','#','#','#','#','#','#','#','#'}};
	boolean editable = true, m_flash = false;
	int m_flashX, m_flashY, m_counter;
	char m_tmp;
	
	public void reset()
	{
		for(int i=0;i<10;i++) for(int j=0;j<10;j++)
			if(data[i][j]!='#' && data[i][j]!='*' && data[i][j]!='@')
				data[i][j]=' ';
	}
	
	public void flash(int x, int y)
	{
		m_flashX = x;
		m_flashY = y;
		m_flash = true;
		m_counter = 6;
		m_tmp = data[y][x];
		repaint(31+x*20, 21+y*20, 18, 18);
	}
	
	public void footprint(int x, int y)
	{
		m_flash = false;
		if(data[y][x]!='*' && data[y][x]!='@')
		{
			data[y][x] = '+';
			repaint(31+x*20, 21+y*20, 18, 18);
		}
	}
	
	public void markPrint(int x, int y)
	{
		m_flash = false;
		data[y][x] = '$';
		repaint(31+x*20, 21+y*20, 18, 18);
	}
	
	public void paint(Graphics p1)
	{
		for(int i=0; i<11; i++) p1.drawLine(30, 20 + 20*i, 30+10*20, 20 + 20*i);
		for(int i=0; i<11; i++) p1.drawLine(30 + i*20, 20, 30+ i*20, 20+10*20);
		for(int i=0; i<10; i++) for(int j=0; j<10; j++) p1.drawChars(data[i], j, 1, 36+j*20, 32+i*20);
		if(editable) p1.drawString("请点击迷宫中相应位置修改地图", 48, 242);
		if(m_flash)
		{
			if(m_counter%2==0) data[m_flashY][m_flashX] = ' ';
			else data[m_flashY][m_flashX] = m_tmp;
			m_counter--;
			if(m_counter<=0) m_flash = false;
			try			{
				Thread.sleep( 200 );
			}
			catch(InterruptedException e){}			repaint(31+m_flashX*20, 21+m_flashY*20, 18, 18);
		}
	}

	public boolean mouseDown(Event p1, int p2, int p3)
	{
		if(editable)
		{
			int j = (p2-30)/20, i = (p3-20)/20;
			if ( i>0 && i<9 && j>0 && i<9 && !(i==1&&j==1) && !(i==8&&j==8) )
			{
				if ( data[i][j] ==' ' ) data[i][j] = '#';
				else data[i][j] = ' ';
			}
			repaint(31+j*20, 21+i*20, 18, 18);
		}
		return true;
	}
}

⌨️ 快捷键说明

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