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

📄 piecesselect.java

📁 一个简单的Java Swing 游戏Blokus~方块圈地~Eclipse3.0 Project
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						game.repaint();
						finishP = true;	
						
					}else{
						setCanPut(false);
						finishP = false;
					}
				}
				//System.out.println("finishP=  " + finishP);
				if(finishP == true){
					if(turn == 1)
					{						
						if(blueC == true )
							autoRun(1);
						else{
							game.setYl(180);
							turn = 2;
							////System.out.println("blue");
						}
						game.repaint();
					}
					else if(turn == 2){						
						if(yellowC == true)
							if(skipY == false)
								autoRun(2);
							else
								turn = 3;
						else{
							game.setYl(360);
							turn = 3;
							//System.out.println("yellow");
						}
						game.repaint();
					}
					else if(turn == 3){						
						if(redC == true)
							autoRun(3);
						else{
							game.setYl(540);
							turn = 4;
							//System.out.println("red");
						}
						game.repaint();
					}
					else if(turn == 4){
						System.out.println("green1111");
						if(greenC == true)
							autoRun(4);
						else{
							game.setYl(0);
							turn = 1;
							//System.out.println("green");
						}
						game.repaint();
					}
				}
				
				finishP = false;
			}
		}//End 棋盘上的鼠标左键
		//鼠标中键
		else if(e.getClickCount() == 1 && e.getButton() == 2 && onMouse == true){
			int x1,y1;
			x1 = e.getX();
			y1 = e.getY();	
			Pieces t = this.temp;
			int[][] gr = t.getGrid();
			int s = t.getScore();
			int[][] tr = new int[s][s];
			for(int i = 0; i < s; i ++)
				for(int j = 0; j < s; j ++)
					tr[i][j] = 0;
			for(int i = 0; i < s; i ++)
				for(int j = 0; j < s; j ++)
					if(gr[i][j] == 1) 
						tr[i][s - 1 - j] = gr [i][j];
			t.setGrid(tr);
				
				//System.out.println();
			game.setPx(x1);
			game.setPy(y1);
			game.setTemp(t);
			game.setCir(1);
			game.repaint();
				
		}//End 鼠标中键
		
	}
	
	//提取选择的棋子类型
	private int selectedPieceType(int x0,int y0, int x, int y){
		int i = 0;
		
		if((x > x0 + 0 && x < x0 + 40 && y > y0 && y < y0 + 40) ||
			(x >= x0 + 20 && x < x0 + 20 && y > y0 && y < y0 + 20)){
			if(playMode >= 3){
				i = 4;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 60 && x < x0 + 120 && y > y0 && y < y0 + 20) ||
				(x > x0 + 80 && x < x0 + 100 && y >= y0 + 20 && y < y0 + 40)){
			if(playMode >= 4){
				i = 5;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 140 && x < x0 + 220 && y > y0 && y < y0 + 20) ||
				(x > x0 + 160 && x < x0 + 180 && y >= y0 + 20 && y < y0 + 40)){
			if(playMode >= 5){
				i = 17;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 240 && x < x0 + 280 && ((y > y0 && y < y0 + 20) || 
				(y >= y0 + 40 && y < y0 + 60))) ||
				(x > x0 + 260 && x < x0 + 280 && y >= y0 + 20 && y < y0 + 40)){
			if(playMode >= 5){
				i = 20;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 300 && x < x0 + 400 && y > y0 && y < y0 + 20){
			if(playMode >= 5){
				i = 11;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 40 && x < x0 + 60 && y > y0 + 20 && y < y0 + 60) ||
				(x > x0 + 20 && x < x0 + 40 && y > y0 + 40 && y < y0 + 80)){
			if(playMode >= 4){
			i = 6;
			setOnMouse(true);
			game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 120 && x < x0 + 140 && y > y0 + 20 && y < y0 + 100) ||
				(x > x0 + 100 && x < x0 + 160 && y > y0 + 60 && y < y0 + 80)){
			if(playMode >= 5){
				i = 15;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 220 && x < x0 + 240 && y > y0 + 20 && y < y0 + 40) {
			if(playMode >= 1){
				i = 1;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 180 && x < x0 + 220 && y > y0 + 40 && y < y0 + 60) ||
				(x > x0 + 200 && x < x0 + 220 && y > y0 + 40 && y < y0 + 100)){
			if(playMode >= 4){
				i = 9;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 300 && x < x0 + 360 && y > y0 + 40 && y < y0 + 60){
			if(playMode >= 3){
				i = 3;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 380 && x < x0 + 400 && y > y0 + 40 && y < y0 + 100){
			if(playMode >= 2){
				i = 2;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 60 && x < x0 + 100 && y > y0 + 60 && y < y0 + 80) ||
				(x > x0 + 80 && x < x0 + 100 && y > y0 + 60 && y < y0 + 120) ||
				(x > x0 + 80 && x < x0 + 120 && y > y0 + 100 && y < y0 + 120)){
			if(playMode >= 5){
				i = 19;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 160 && x < x0 + 180 && y > y0 + 60 && y < y0 + 120) ||
				(x > x0 + 120 && x < x0 + 180 && y > y0 + 80 && y < y0 + 100) ||
				(x > x0 + 160 && x < x0 + 200 && y > y0 + 100 && y < y0 + 120)){
			if(playMode >= 5){
				i = 16;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 280 && x < x0 + 300 && y > y0 + 60 && y < y0 + 120) ||
				(x > x0 + 240 && x < x0 + 300 && y > y0 + 80 && y < y0 + 100)){
			if(playMode >= 5){
				i = 12;
				System.out.println("Got it nubmer 12");
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 && x < x0 + 20 && y > y0 + 80 && y < y0 + 160) ||
				(x > x0 && x < x0 + 40 && y > y0 + 140 && y < y0 + 160)){
			if(playMode >= 5){
				i = 13;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 40 && x < x0 + 60 && y > y0 + 80 && y < y0 + 140) ||
				(x > x0 + 60 && x < x0 + 80 && y > y0 + 120 && y < y0 + 160)){
			if(playMode >= 5){
				i = 18;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 120 && x < x0 + 160 && y > y0 + 100 && y < y0 + 140) ||
				(x > x0 + 100 && x < x0 + 160 && y > y0 + 120 && y < y0 + 140)){
			if(playMode >= 5){
				i = 10;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 220 && x < x0 + 240 && y > y0 + 100 && y < y0 + 120) ||
				(x > x0 + 200 && x < x0 + 220 && y > y0 + 120 && y < y0 + 160) ||
				(x > x0 + 180 && x < x0 + 220 && y > y0 + 140 && y < y0 + 160)){
			if( playMode >= 5){
				i = 21;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 240 && x < x0 + 320 && y > y0 + 140 && y < y0 + 160){
			if(playMode >= 4){
				i = 8;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if(x > x0 + 320 && x < x0 + 360 && y > y0 + 80 && y < y0 + 120){
			if(playMode >= 4){
				i = 7;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		else if((x > x0 + 380 && x < x0 + 400 && y > y0 + 100 && y < y0 + 160) ||
				(x > x0 + 340 && x < x0 + 400 && y > y0 + 140 && y < y0 + 160)){
			if(playMode >= 5){
				i = 14;
				setOnMouse(true);
				game.setPOnMouse(true);
			}
		}
		//System.out.println("PlayMode:" + playMode);
		return i;
	}

	//手动模式不能放下棋子的情况
	private void canNotBePutOn(int[][] br, int i, int j, float cy, float rx){
		try{
			int t;
			//System.out.println("i:" + ((int)cy + i) + " j:" + ((int)rx + j));
			if(br[(int)cy + i][(int)rx + j] == 0 
					&& (blueS > 1 || yellowS > 1 || redS > 1 || greenS > 1)){
				
				if((int)cy + i == 0 && (int)rx + j > 0 && (int)rx + j < 20 &&
						(br[(int)cy + i + 1][(int)rx + j] == temp.getpColor() ||
						br[(int)cy + i][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(false);
					//System.out.println("1");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j > 0 
						&& (int)rx + j < 20 &&
						(br[(int)cy + i + 1][(int)rx + j] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j] == temp.getpColor() ||		
						br[(int)cy + i][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(false);
					//System.out.println("2");
				}
				
				else if((int)cy + i == 20 && (int)rx + j > 0 && (int)rx + j < 20 &&
						(br[(int)cy + i - 1][(int)rx + j] == temp.getpColor() ||		
						br[(int)cy + i][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(false);
					//System.out.println("3");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j == 0 &&
						(br[(int)cy + i + 1][(int)rx + j] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j] == temp.getpColor() ||		
						br[(int)cy + i][(int)rx + j + 1] == temp.getpColor())){
					setCanPut(false);
					//System.out.println("4");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j == 20 &&
						(br[(int)cy + i + 1][(int)rx + j] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j] == temp.getpColor() ||		
						br[(int)cy + i][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(false);
					//System.out.println("5");
				}
				
				else if((int)cy + i >= 20 ||(int)rx + j >= 20){
					setCanPut(false);
					//System.out.println("6");
				}
				
				else{
					t = br[(int)cy + i][(int)rx + j];
					br[(int)cy + i][(int)rx + j] = temp.getpColor();
					br[(int)cy + i][(int)rx + j] = t;
					//System.out.println(((int)cy + i) + " " + ((int)rx + j));
				}
			}
			//else{
				//setCanPut(false);
				//System.out.println("777777777777777777");
			//}
		}
		catch(Exception exe){
			setCanPut(false);
			//System.out.println((int)cy + i + " " + (int)rx + j);
			//System.out.println(" hahaha ");
			game.repaint();
		}
	}
	
	//手动模式能放下棋子的情况
	private void canBePutOn(int[][] br, int i, int j, float cy, float rx){
		try{
			int t;
			//System.out.println("i:" + ((int)cy + i) + " j:" + ((int)rx + j));
			if(br[(int)cy + i][(int)rx + j] == 0 
					&& (blueS > 1 || yellowS > 1 || redS > 1 || greenS > 1)){
				
				if((int)cy + i == 0 && (int)rx + j > 0 && (int)rx + j < 20 &&
						(br[(int)cy + i + 1][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i + 1][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(true);
					//System.out.println("11");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j > 0 
						&& (int)rx + j < 20 &&
						(br[(int)cy + i + 1][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i + 1][(int)rx + j - 1] == temp.getpColor() ||		
						br[(int)cy + i - 1][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(true);
					//System.out.println("22");
				}
				
				else if((int)cy + i == 20 && (int)rx + j > 0 && (int)rx + j < 20 &&
						(br[(int)cy + i - 1][(int)rx + j + 1] == temp.getpColor() ||		
						br[(int)cy + i - 1][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(true);
					//System.out.println("33");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j == 0 &&
						(br[(int)cy + i + 1][(int)rx + j + 1] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j + 1] == temp.getpColor())){
					setCanPut(true);
					//System.out.println("44");
				}
				
				else if((int)cy + i > 0 && (int)cy + i < 20 && (int)rx + j == 20 &&
						(br[(int)cy + i + 1][(int)rx + j - 1] == temp.getpColor() ||
						br[(int)cy + i - 1][(int)rx + j - 1] == temp.getpColor())){
					setCanPut(true);
					//System.out.println("55");
				}
			}
			//else{
				//setCanPut(false);
				//System.out.println("777777777777777777");
			//}
		}
		catch(Exception exe){
			setCanPut(false);
			System.out.println((int)cy + i + " " + (int)rx + j);
			System.out.println(" hahaha ");
			game.repaint();
		}
	}
	
	//手动模式下第一块棋子
	private int firstTurn(int turn, float cy, float rx){
		int[][] gr = temp.getGrid();
		int[][] br = game.getBoardGrid();
		int m,n,t;
		
		switch(turn){
			case 1:{m = 0; n = 0;}
				break;
			case 2:{m = 0; n = 19;}
				break;
			case 3:{m = 19; n = 19;}
				break;
			case 4:{m = 19; n =0;}
				break;
			default:{m = 0; n = 0;}
				break;
		}
		setCanPut(false);
		//System.out.println("turn:" + turn + " m:" + m + " n:" + n);
		for(int i = 0; i < temp.getScore(); i ++){
			for(int j = 0; j < temp.getScore(); j ++){
				//System.out.print(gr[i][j] + " ");
				if(gr[i][j] == 1){
					try{
						//System.out.println("I:" + ((int)cy + i) + " I:" + ((int)rx + j));
						if((int)cy + i == m && (int)rx + j == n){
							setCanPut(true);
							//System.out.println("i:" + ((int)cy + i) + " j:" + ((int)rx + j));
						}
						t = br[(int)cy + i][(int)rx + j];
						br[(int)cy + i][(int)rx + j] = temp.getpColor();
						br[(int)cy + i][(int)rx + j] = t;
					}catch(Exception exe){
						return 0;
					}
				}
				
			}
		}
		
		for(int i = 0; i < temp.getScore(); i ++){
			for(int j = 0; j < temp.getScore(); j ++){
				if(gr[i][j] == 1){
					try{
						if((int)cy + i > 19 || (int)rx + j > 19){
							setCanPut(false);
							return 0;
						}
					}catch(Exception exe){
						return 0;
					}
				}
			}
		}
		
		
		System.out.println("canput:" + this.canPut);
		if(canPut == true){
			for(int i = 0; i < temp.getScore(); i ++){
				for(int j = 0; j < temp.getScore(); j ++){

⌨️ 快捷键说明

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