亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jmine.java

?? 用JAVA做了一個小游戲
?? JAVA
字號:
/**
 * This program is written by Jerry Shen(Shen Ji Feng)
 * use the technology of SWING GUI and the OO design
 *
 * @author Jerry Shen(jerry.shen@cognizant.com)
 * Distributed under the licience of GPLv3
 * all rights reserved.
 */ 
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

class JMine extends JFrame implements MouseListener, ActionListener {
	private JMineArth mine;
	private JMineButton [][] mineButton;
    private GridBagConstraints constraints;
   	private JPanel pane;
    private GridBagLayout gridbag;
	private boolean gameStarted;
	private JCounter mineCounter;
	private JCounter timeCounter;

	private TimeCounterThread timerThread;
	public int numMine;
	public int numFlaged;

	private JMenuBar mb;
	private JMenu mGame;
	private JMenuItem miEasy;
	private JMenuItem miMiddle;
	private JMenuItem miHard;
	private JMenuItem miExit;
	private JMenu mHelp;
	private JMenuItem miAbout;
	private JPanel controlPane;
	private JButton bTest;
	
	private AboutFrame about;



	private ImageIcon [] mineNumIcon = { new ImageIcon("0.gif"), new ImageIcon("1.gif"),
					     new ImageIcon("2.gif"), new ImageIcon("3.gif"),
					     new ImageIcon("4.gif"), new ImageIcon("5.gif"),
					     new ImageIcon("6.gif"), new ImageIcon("7.gif"),
					     new ImageIcon("8.gif"), new ImageIcon("9.gif"),
					};
	private ImageIcon[] mineStatus = { new ImageIcon("0.gif"), new ImageIcon("flag.gif"), 
						new ImageIcon("question.gif") };
	private ImageIcon[] mineBombStatus = { new ImageIcon("0.gif"), new ImageIcon("mine.gif"), 
						new ImageIcon("wrongmine.gif"), new ImageIcon("bomb.gif") };
	private ImageIcon[] faceIcon = { new ImageIcon("smile.gif"), new ImageIcon("Ooo.gif")};
	
	// You lose
	private void bomb(int row, int col){
		//System.out.println("Bomb!");
		timerThread.stop();
		
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				mineButton[i][j].setIcon(mineBombStatus[0]);
				int toShow;
        		toShow = mine.mine[i][j]!=9? 0: 1;
				mineButton[i][j].setClickFlag(true);
 				if ( toShow == 1 && (i!=row || j!= col)) {
					mineButton[i][j].setIcon(mineBombStatus[toShow]);
					mineButton[i][j].setClickFlag(true);
				}
				else if (toShow == 1 && (i == row && j== col)) {
					mineButton[i][j].setIcon(mineBombStatus[3]);
					mineButton[i][j].setClickFlag(true);
				}
				else if (toShow == 0 && mineButton[i][j].getFlag() != 1) {
					mineButton[i][j].setEnabled(false); 
				}
				else if ( toShow == 0 && mineButton[i][j].getFlag() == 1) {
					mineButton[i][j].setIcon(mineBombStatus[2]);
					mineButton[i][j].setClickFlag(true);
				}
			}
		}
	}
	
	// check if you win() {
	private boolean isWin() {
		int minesCount=0;
		for (int i = 0; i < 10; i++) {
			for (int j=0; j <10; j++) {
				if(mine.mine[i][j]==9 && mineButton[i][j].getFlag() != 1) {
					return(false);
				}
				if(mine.mine[i][j]!=9 && mineButton[i][j].getFlag() == 1) {
					return(false);
				}
				if(mine.mine[i][j]!=9 && mineButton[i][j].getClickFlag() == false) {
					return(false);
				}				
			}
		}
		return(true);
	}
	
	// You Win
	private void win(){
		timerThread.stop();
		RestartRunner r = new RestartRunner();
		r.setMine(this);
		r.setTimer(timerThread);
		Thread t = new Thread(r);
		t.start();
		
	}
	
	// Constructor of the game 
	public JMine() {
		super("JMine Game");
		setSize(250, 350);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		Insets space = new Insets(0,0,0,0);
		
		// Game vars
		gameStarted = false;
		numMine = 12;
		numFlaged = 0;
		
		ImageIcon myIcon = new ImageIcon("0.gif");
		gridbag = new GridBagLayout();
		constraints = new GridBagConstraints();
		pane = new JPanel();
		pane.setLayout(gridbag);
		constraints.fill = GridBagConstraints.BOTH;
		constraints.anchor = GridBagConstraints.CENTER;


		// Begin Menu Set
		mb = new JMenuBar();
		mGame = new JMenu("Game");
		miEasy = new JMenuItem("Easy");
		miEasy.addActionListener(this);
		miMiddle = new JMenuItem("Middle");
		miMiddle.addActionListener(this);
		miHard = new JMenuItem("Hard");
		miHard.addActionListener(this);
		miExit = new JMenuItem("Exit");
		miExit.addActionListener(this);
		mGame.add(miEasy);
		mGame.add(miMiddle);
		mGame.add(miHard);
		mGame.addSeparator();
		mGame.add(miExit);
		mb.add(mGame);

		mHelp = new JMenu("Help");
		miAbout = new JMenuItem("About...");
		mHelp.add(miAbout);
		miAbout.addActionListener(this);
		mb.add(mHelp);
		this.setJMenuBar(mb);
		// end of Menu Set

		// Control Panel
		controlPane = new JPanel();
		bTest = new JButton(faceIcon[0]);
		bTest.setSize(26, 27);
		bTest.setMargin(space);
		bTest.addMouseListener(this);
		bTest.setPressedIcon(faceIcon[1]);
	
		mineCounter = new JCounter(numMine);
		timeCounter = new JCounter();
		controlPane.add(mineCounter);
		controlPane.add(bTest);
		controlPane.add(timeCounter);
		buildConstraints(constraints, 0, 0, 10, 2, 100, 100);
		gridbag.setConstraints(controlPane, constraints);
		pane.add(controlPane);
			
		// Bottons
		mineButton = new JMineButton[10][10];		
		for (int i=0; i <10; i++) {
			for (int j=0; j < 10; j++) {
				mineButton[i][j] = new JMineButton(i,j, myIcon);
				mineButton[i][j].addMouseListener(this);
				mineButton[i][j].setMargin(space);
				buildConstraints(constraints, j, i+3, 1, 1, 100, 100);
				gridbag.setConstraints(mineButton[i][j], constraints);
				pane.add(mineButton[i][j]);
			}
		}

		// Content Pane
		setContentPane(pane);
		setLocation(200, 150);
		setVisible(true);
		
		// About Frame
		about = new AboutFrame("JMine About");
	}
	
	// Set the GUI objects positions
	void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) {
		gbc.gridx = gx;
		gbc.gridy = gy;
		gbc.gridwidth = gw;
		gbc.gridheight = gh;
		gbc.weightx = wx;
		gbc.weighty = wy;
	}
	
	// the methods to check if there were mines, to be nested
	void checkMine(int row, int col) {
		int i,j;
		i=row<0?0:row;
		i=i>9?9:i;
		j=col<0?0:col;
		j=j>9?9:j;
		//System.out.println("Check Mine row:"+i + ",col:" +j);
		if (mine.mine[i][j] == 9) {
			bomb(i,j);
		}
		else if (mine.mine[i][j] == 0 && mineButton[i][j].getClickFlag() == false) {
			mineButton[i][j].setClickFlag(true);
            		showLabel(i,j);
			for (int ii= i -1; ii <= i+1; ii++)
				for (int jj = j-1; jj <= j+1; jj++)
					checkMine(ii,jj);
			
		}
		else {
			showLabel(i,j);
			mineButton[i][j].setClickFlag(true);
		}
		if (isWin()) {
			win();
		}
	}

	private void clearAll(int row, int col) {
		int top,bottom, left, right, count=0;
		top=row-1>0?row-1:0;
		bottom=row+1<10?row+1:9;
		left=col-1>0?col-1:0;
		right=col+1<10?col+1:9;
		for (int i=top; i<=bottom; i++) {
			for(int j=left; j<= right; j++) {
				if (mineButton[i][j].getFlag()!=1) checkMine(i,j);
			}
		}

	}
	
	private void resetAll() {
		for (int i=0; i<10; i++) {
			for(int j=0; j< 10; j++) {
				mineButton[i][j].setFlag(0);
				mineButton[i][j].setClickFlag(false);
				mineButton[i][j].setIcon(mineStatus[0]);
				mineButton[i][j].setEnabled(true);
				mineButton[i][j].setVisible(true);
			}
		}
	}

	
	// to flag the mine you want to flag out
	void flagMine(int row, int col) {
		//System.out.println("Jerry Arrives here!");
		int i,j;
		i=row<0?0:row;
		i=i>9?9:i;
		j=col<0?0:col;
		j=j>9?9:j;
		if(mineButton[i][j].getFlag() == 0) {
			numFlaged++;
		} else if(mineButton[i][j].getFlag() == 1){
			numFlaged--;
		}
		mineCounter.resetCounter(numMine - numFlaged>=0?numMine - numFlaged:0);
		mineButton[i][j].setFlag((mineButton[i][j].getFlag() + 1) %3) ;
		showFlag(i,j);
		if (isWin()) {
			win();
		}	
	}

	// show the numbers of the nearby mines
	void showLabel(int row, int col) {
		//System.out.println("ShowLabel row:" + row + ",col:" + col);
        	int toShow;
        	toShow = mine.mine[row][col];
		if (toShow != 0) {
			mineButton[row][col].setIcon(mineNumIcon[toShow]);
			mineButton[row][col].setClickFlag(true);
			//mineButton[row][col].setEnabled(false);
		} 
		else {
			//mineButton[row][col].setIcon(mineNumIcon[0]);
			//mineButton[row][col].setClickFlag(true);
			mineButton[row][col].setEnabled(false);
		}
	}
	
	// circle the flag with blank, flaged, questioned
	void showFlag(int row, int col) {			
		mineButton[row][col].setIcon(mineStatus[mineButton[row][col].getFlag()]);
	}
	
	// the mouse events listener methods
	public void mouseEntered(MouseEvent e) {
		//System.out.println("Jerry Test");

	}
	
	// method to start the new game
	private void startNewGame(int num, int row, int col) {
		mine = new JMineArth(num, row, col);
		//mine.printMine();
		gameStarted = true;

		timerThread = new TimeCounterThread(timeCounter);
		timerThread.start(); 
	}
	
	public void setNewGame(int num){
		resetAll();
		numMine = num;
		numFlaged = 0;
		gameStarted = false;
		mineCounter.resetCounter(numMine);
		timeCounter.resetCounter(0);
		timerThread.stop();
	}

	// the event handle to deal with the mouse click
	public void mouseClicked(MouseEvent e) {
		if(e.getSource() == bTest) {
			setNewGame(numMine);
			return;
		}
		int  row,col;
		row=((JMineButton)e.getSource()).getRow();
		col=((JMineButton)e.getSource()).getCol();
		if (!gameStarted) {
			startNewGame(numMine, row, col);
		}

		if (e.getModifiers() == (InputEvent.BUTTON1_MASK+InputEvent.BUTTON3_MASK)) {
			//System.out.println("HA");
			clearAll(row, col);
		}
		if (!mineButton[row][col].getClickFlag()) {

			if (e.getModifiers() == InputEvent.BUTTON1_MASK) { 
				//System.out.println("LeftButton");
				if (mineButton[row][col].getFlag() == 1 ) { 
					return;
				}
				else {
					checkMine(row, col);
				}
			}
			else if (e.getModifiers() == InputEvent.BUTTON3_MASK){
				//System.out.println("RightButton");
				flagMine(row, col);
			} else {
				//System.out.println("MiddleButton");
			}
		}
	}
	public void mousePressed(MouseEvent e) {
		//System.out.println("Jerry Press");

	}
	public void mouseReleased(MouseEvent e) {
		//System.out.println("Jerry Release");
	}
	public void mouseExited(MouseEvent e) {
		//System.out.println("Jerry Exited");

	}
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == miEasy) {
			setNewGame(12);
			return;
		}
		if(e.getSource() == miMiddle) {
			setNewGame(24);
			return;
		}
		if(e.getSource() == miHard) {
			setNewGame(36 );
			return;
		}
		if(e.getSource() == miExit) {
			System.exit(0);
		}
		if(e.getSource() == miAbout) {
			about.setVisible(true);
		}
	}
}

class RestartRunner implements Runnable {
	private WinFrame win;
	private JMine mine;
	private boolean isMineSet;
	
	private TimeCounterThread timer;
	
	public void setMine(JMine mine) {
		this.mine = mine;
	}

	public void setTimer(TimeCounterThread timer) {
		this.timer = timer;
	}
	
	public void run(){
		isMineSet = false;
		win = new WinFrame("You win!");
		while (!this.win.getWinOk()||isMineSet) {
			//System.out.println("Not start!");
		}
		mine.numMine = win.getMineNum();
		mine.setNewGame(mine.numMine);
		timer.stop();
		win.setVisible(false);		
	}

}

class TimeCounterThread extends Thread {
	private JCounter timeCounter;

	TimeCounterThread (JCounter time) {
		timeCounter = time;
	}

	public void run() {
		while (true) {
			try {
				sleep(1000);
				timeCounter.resetCounter(timeCounter.getCounterNum() +1);
				//System.out.println("zzz");
			}
			catch(InterruptedException e) {}
		}	
	}
}





?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
丁香激情综合五月| 26uuu亚洲综合色欧美| 欧美一级高清大全免费观看| 国产视频一区二区在线| 亚洲一区二区三区影院| 国产一区美女在线| 欧美精品粉嫩高潮一区二区| 国产欧美日韩另类一区| 奇米影视一区二区三区| 欧美亚洲综合在线| 亚洲国产cao| 福利电影一区二区三区| 欧美一级理论性理论a| 亚洲国产精品一区二区www | 91精品国产免费久久综合| 中文字幕中文在线不卡住| 蜜桃视频在线观看一区| 欧美在线不卡一区| 一区在线观看免费| 成人小视频在线观看| 欧美电影免费观看完整版| 日韩经典一区二区| 在线电影欧美成精品| 亚洲一区二区三区美女| 欧美伊人久久久久久久久影院 | 国产一区日韩二区欧美三区| 91精品国产综合久久久蜜臀粉嫩| 亚洲日本在线视频观看| 粉嫩13p一区二区三区| 久久精品视频免费观看| 韩日av一区二区| 日韩欧美国产电影| 蜜臀精品一区二区三区在线观看 | 欧美日韩免费电影| 一区二区三区四区不卡视频| 91免费版pro下载短视频| 亚洲三级小视频| 色偷偷88欧美精品久久久| 成人免费在线观看入口| 色综合欧美在线视频区| 日韩伦理电影网| 色狠狠色噜噜噜综合网| 亚洲成人av一区二区| 欧美日韩国产中文| 日韩高清一区二区| 日韩欧美色综合网站| 国内久久精品视频| 国产精品丝袜黑色高跟| 99视频一区二区| 亚洲一区视频在线观看视频| 欧美性色综合网| 三级久久三级久久| 精品国产精品网麻豆系列| 国产suv一区二区三区88区| 精品国产3级a| 91在线一区二区三区| 亚洲无人区一区| 欧美电影免费观看高清完整版 | 国产目拍亚洲精品99久久精品| 国产福利一区二区三区| 亚洲欧洲精品一区二区三区不卡| 91丨porny丨户外露出| 日韩制服丝袜av| 国产亚洲va综合人人澡精品 | 欧美变态口味重另类| 国产不卡视频一区二区三区| 亚洲一区二区三区国产| 欧美不卡视频一区| 日本高清不卡视频| 激情综合色丁香一区二区| 综合欧美一区二区三区| 91精品国产欧美一区二区18| 波多野结衣精品在线| 亚洲v日本v欧美v久久精品| 国产亚洲1区2区3区| 中文字幕av在线一区二区三区| 亚洲男人的天堂在线观看| 国产精品一区免费在线观看| 亚洲精品一区二区三区四区高清| 91无套直看片红桃| 免费在线观看视频一区| 一区二区三区在线免费观看| 精品处破学生在线二十三| 欧美在线制服丝袜| 国产二区国产一区在线观看| 亚洲一区二区三区不卡国产欧美| 国产精品婷婷午夜在线观看| 91精品国产综合久久小美女| 99久久综合99久久综合网站| 国产乱码精品一区二区三区五月婷| 亚洲午夜在线观看视频在线| 欧美激情中文不卡| 精品日韩欧美一区二区| 欧美精品色一区二区三区| 99精品国产热久久91蜜凸| 精品中文字幕一区二区| 亚洲成av人片在www色猫咪| 国产精品日韩精品欧美在线| 欧美大白屁股肥臀xxxxxx| 欧美三级午夜理伦三级中视频| voyeur盗摄精品| 成人一区二区三区视频| 国产一区在线观看麻豆| 精品一区二区成人精品| 日韩不卡一区二区| 肉色丝袜一区二区| 亚洲伊人色欲综合网| 亚洲欧洲日本在线| 亚洲色图制服丝袜| 国产精品超碰97尤物18| 国产亚洲婷婷免费| 国产精品视频yy9299一区| 久久精品视频网| 久久精品日韩一区二区三区| 久久这里只有精品视频网| 日韩欧美一二三| 久久综合av免费| 中文字幕不卡在线观看| 精品久久99ma| 久久久久久一级片| 国产女同互慰高潮91漫画| 国产精品伦一区| 亚洲欧洲国产日韩| 亚洲黄网站在线观看| 亚洲第一精品在线| 强制捆绑调教一区二区| 九九在线精品视频| 国产成人精品aa毛片| 波多野结衣一区二区三区 | 久久精品国产网站| 国产一区二区三区黄视频| 国产福利不卡视频| 色综合久久88色综合天天6| 在线观看日韩av先锋影音电影院| 欧美视频在线一区二区三区 | 欧美日韩精品福利| 91精品国产手机| 26uuu久久综合| 亚洲视频免费在线观看| 亚洲在线视频一区| 久久精品国产一区二区三区免费看| 狠狠色丁香婷婷综合| 91视频国产资源| 日韩午夜电影av| 中文字幕一区二区三区在线观看| 亚洲综合一二三区| 久久精品国产亚洲高清剧情介绍| 顶级嫩模精品视频在线看| 在线一区二区三区四区五区 | 国产精品三级视频| 亚洲国产另类精品专区| 免费成人结看片| 波多野结衣亚洲一区| 欧美丰满少妇xxxbbb| 久久综合色之久久综合| 亚洲美女免费视频| 麻豆精品久久精品色综合| 成人白浆超碰人人人人| 8v天堂国产在线一区二区| 久久精品一区二区三区四区| 亚洲一二三四在线观看| 国产suv精品一区二区883| 欧美另类videos死尸| 国产精品久久久久久久久免费丝袜 | 欧美日韩亚洲综合在线 | 欧美日韩国产成人在线91| 欧美成人免费网站| 一区二区在线免费观看| 国内精品久久久久影院一蜜桃| 91网址在线看| 久久精品一区蜜桃臀影院| 天堂va蜜桃一区二区三区漫画版| 成人免费视频一区| 日韩欧美二区三区| 一区二区三区不卡视频在线观看| 国产成人精品三级麻豆| 日韩欧美国产一二三区| 亚洲成人动漫在线免费观看| 成人黄色大片在线观看| 精品国内二区三区| 免费av成人在线| 欧美性猛交xxxx黑人交| 中文字幕不卡在线播放| 国产在线国偷精品产拍免费yy| 欧美亚洲图片小说| 18欧美乱大交hd1984| 懂色一区二区三区免费观看| 日韩精品中文字幕一区二区三区 | 视频一区二区三区在线| 欧美制服丝袜第一页| 亚洲激情五月婷婷| 91亚洲男人天堂| 综合激情成人伊人| 91在线云播放| 一区二区三区中文字幕| 欧美在线不卡视频| 性做久久久久久免费观看| 精品1区2区3区| 日韩国产一二三区| 日韩一区和二区|