基於Swing的連連看小遊戲

 

class LianLianKanJPanel extends JPanel implements ActionListener,ItemListener {

	private static final long serialVersionUID = 1L;//序列化時爲了保持版本的兼容性,即在版本升級時反序列化仍保持對象的唯一性。
		private int[][] map = new int[8][8];//8*8的正方形
		private int kind, randomx, randomy, randomx1, randomy1; // 種類,隨機x
		private int coordinatex, coordinatey, coordinatex1, coordinatey1; // 座標X
		private Point lineStart = new Point(0, 0);
		private int clicktimes;
		private int jishushengyu;//計數剩餘
		private int Kinds = 4;
		private int score;
		private int guanshu;//關數

		
		loudou ld = new loudou();// 漏斗
		

		JButton BlockButton[][] = new JButton[8][8];//
		Choice difficultChoice = new Choice();
		JButton newgameButton = new JButton("重新開始");
		JButton reLoad = new JButton("刷新");

		ImageIcon ii = new ImageIcon("src/im/bk.jpg");

		ImageIcon aIcon = new ImageIcon("src/im/1.gif");
		ImageIcon bIcon = new ImageIcon("src/im/2.gif");
		ImageIcon cIcon = new ImageIcon("src/im/3.gif");
		ImageIcon dIcon = new ImageIcon("src/im/4.gif");
		ImageIcon eIcon = new ImageIcon("src/im/5.gif");
		ImageIcon fIcon = new ImageIcon("src/im/6.gif");
		ImageIcon gIcon = new ImageIcon("src/im/7.gif");
		ImageIcon hIcon = new ImageIcon("src/im/8.gif");
		ImageIcon iIcon = new ImageIcon("src/im/9.gif");
		ImageIcon jIcon = new ImageIcon("src/im/10.gif");
		ImageIcon kIcon = new ImageIcon("src/im/11.gif");
		ImageIcon lIcon = new ImageIcon("src/im/12.gif");
		ImageIcon mIcon = new ImageIcon("src/im/13.gif");
		ImageIcon nIcon = new ImageIcon("src/im/14.gif");
		ImageIcon oIcon = new ImageIcon("src/im/15.gif");

		public LianLianKanJPanel() {

			this.setLayout(null);

			newMap();
			for (int i = 0; i < 8; i++) {
				for (int j = 0; j < 8; j++) {
					BlockButton[i][j] = new JButton();
					add(BlockButton[i][j]);
					BlockButton[i][j].addActionListener(this);//監聽器
					BlockButton[i][j].setBounds(30 + j * 40, 30 + i * 40, 31,34);
				//	BlockButton[i][j].setBorderPainted(false);
				//  BlockButton[i][j].setVisible(true);
				}
			}
			difficultChoice.add("簡單");
			difficultChoice.add("中等");
			difficultChoice.add("困難");
			difficultChoice.add("變態");

			newgameButton.setBounds(map[0].length * 40 + 80, 40, 100, 20);
			newgameButton.setBackground(Color.white);
			newgameButton.setBorderPainted(false); //去邊框
			reLoad.setBounds(map[0].length * 40 + 100, 80, 60, 20);
			reLoad.setBackground(Color.white);
			reLoad.setBorderPainted(false);
			difficultChoice.setBounds(map[0].length * 40 + 100, 120, 60, 20);
			difficultChoice.addItemListener(this);
			newgameButton.addActionListener(this);
			reLoad.addActionListener(this);

			this.add(newgameButton);
			this.add(reLoad);
			this.add(difficultChoice);

			// /-------------------------漏斗
			ld.setBounds(map[0].length * 40 + 100, 200, 70, 150);// 漏斗
			ld.setBackground(Color.black);
			this.add(ld);
	

		}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章