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

📄 battledialog.java

📁 java 开源游戏源码 RISK 联机对战 战棋类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:


			g2.setColor( new Color(color1.getRed(), color1.getGreen(), color1.getBlue(), 150) );


			g2.fillPolygon( arrow );

			int noa;

			g2.setColor( RiskUtil.getTextColorFor(color1) );

			noa = myrisk.hasArmiesInt(c1num);

			if (noa < 10) {
				g2.drawString( String.valueOf( noa ) , 126, 105 );
			}
			else if (noa < 100) {
				g2.drawString( String.valueOf( noa ) , 123, 105 );
			}
			else {
				g2.drawString( String.valueOf( noa ) , 120, 105 );
			}

			g2.setColor( RiskUtil.getTextColorFor(color2) );

			noa = myrisk.hasArmiesInt(c2num);

			if (noa < 10) {
				g2.drawString( String.valueOf( noa ) , 346, 105 );
			}
			else if (noa < 100) {
				g2.drawString( String.valueOf( noa ) , 343, 105 );
			}
			else {
				g2.drawString( String.valueOf( noa ) , 340, 105 );
			}


			if (max != 0 && canRetreat) {

				g.drawImage( Battle.getSubimage(481, 0, 21, 21) , 120, 180, this );

				if (nod > 1) {

					g.drawImage( Battle.getSubimage(481, 0, 21, 21) , 120, 211, this );

				}
				else if (max > 1) {

					g.drawImage( Battle.getSubimage(502, 0, 21, 21) , 120, 211, this );

				}

				if (nod > 2) {

					g.drawImage( Battle.getSubimage(481, 0, 21, 21) , 120, 242, this );

				}
				else if (max > 2) {

					g.drawImage( Battle.getSubimage(502, 0, 21, 21) , 120, 242, this );

				}

				// draw the dead dice
				int deadDice = myrisk.hasArmiesInt(c2num);

				g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 180, this );

				if (deadDice > 1) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 211, this );

				}

				if (game.getSimone()) {
				    if (deadDice > 2) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 242, this );

				    }
				}


			}
			else if (max != 0 ) {

				g.drawImage( Battle.getSubimage(481, 21, 21, 21) , 339, 180, this );

				if (nod > 1) {

					g.drawImage( Battle.getSubimage(481, 21, 21, 21) , 339, 211, this );

				}
				else if (max > 1) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 211, this );

				}

				if (game.getSimone()) {

				    if (nod > 2) {

					g.drawImage( Battle.getSubimage(481, 21, 21, 21) , 339, 242, this );

				    }
				    else if (max > 2) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 242, this );

				    }
				}


			}
			else if (max == 0 && nodd == 0 && atti == null && defi == null ) {

				// draw the dead dice
				int DdeadDice = myrisk.hasArmiesInt(c2num);

				g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 180, this );

				if (DdeadDice > 1) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 211, this );

				}

				if (game.getSimone()) {

				    if (DdeadDice > 2) {

					g.drawImage( Battle.getSubimage(502, 21, 21, 21) , 339, 242, this );

				    }

				}

				if (noda == 0) {

					// draw dead dice for attacker
					int AdeadDice = myrisk.hasArmiesInt(c1num)-1;

					g.drawImage( Battle.getSubimage(502, 0, 21, 21) , 120, 180, this );

					if (AdeadDice > 1) {

						g.drawImage( Battle.getSubimage(502, 0, 21, 21) , 120, 211, this );

					}
					if (AdeadDice > 2) {

						g.drawImage( Battle.getSubimage(502, 0, 21, 21) , 120, 242, this );

					}

				}

			}

			drawDiceAnimated(g);

			if (atti != null && defi != null ) {


				if (defi[0] >= atti[0]) {

					g2.setColor( Color.blue );

					int xCoords[] = {339, 339, 140};
					int yCoords[] = {180, 200, 190};

					g2.fillPolygon(xCoords, yCoords, xCoords.length);

				}
				else {

					g2.setColor( Color.red );

					int xCoords[] = {140, 140, 339};
					int yCoords[] = {180, 200, 190};

					g2.fillPolygon(xCoords, yCoords, xCoords.length);


				}

				if (atti.length > 1 && defi.length > 1) {

					if (defi[1] >= atti[1]) {

						g2.setColor( Color.blue );

						int xCoords[] = {339, 339, 140};
						int yCoords[] = {211, 231, 221};

						g2.fillPolygon(xCoords, yCoords, xCoords.length);

					}
					else {

						g2.setColor( Color.red );

						int xCoords[] = {140, 140, 339};
						int yCoords[] = {211, 231, 221};

						g2.fillPolygon(xCoords, yCoords, xCoords.length);


					}
				}

				if (game.getSimone()) {

				    if (atti.length > 2 && defi.length > 2) {

					if (defi[2] >= atti[2]) {

						g2.setColor( Color.blue );

						int xCoords[] = {339, 339, 140};
						int yCoords[] = {242, 262, 252};

						g2.fillPolygon(xCoords, yCoords, xCoords.length);

					}
					else {

						g2.setColor( Color.red );

						int xCoords[] = {140, 140, 339};
						int yCoords[] = {242, 262, 252};

						g2.fillPolygon(xCoords, yCoords, xCoords.length);


					}
				    }
				}


				// draw attacker dice
				g.drawImage( getDice(true, atti[0] ), 120, 180, this );

				if (atti.length > 1) {

					g.drawImage( getDice(true, atti[1] ), 120, 211, this );

				}
				if (atti.length > 2) {

					g.drawImage( getDice(true, atti[2] ), 120, 242, this );

				}

				// draw defender dice
				g.drawImage( getDice(false, defi[0] ), 339, 180, this );

				if (defi.length > 1) {

					g.drawImage( getDice(false, defi[1] ), 339, 211, this );

				}

				if (game.getSimone()) {

				    if (defi.length > 2) {

					g.drawImage( getDice(false, defi[2] ), 339, 242, this );

				    }
				}

			}

		}

	}

	/**
	 * Gets the dice
	 * @param isAttacker if the dice is an attacker
	 * @param result Result of the dice
	 * @return BufferedImage The image of the die
	 */
	public BufferedImage getDice(boolean isAttacker, int result) {

		BufferedImage die = new BufferedImage(21, 21, java.awt.image.BufferedImage.TYPE_INT_RGB );

		Graphics2D g = die.createGraphics();

		if (isAttacker) {

			g.drawImage( Battle.getSubimage(481, 0, 21, 21) , 0, 0, this );

		}
		else {

			g.drawImage( Battle.getSubimage(481, 21, 21, 21) , 0, 0, this );

		}

		int size=3;
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor( new Color(255, 255, 255, 200) );

		if (result==0) {

			g.fillOval(9, 9, size, size);

		}
		else if (result==1) {

			g.fillOval(3, 3, size, size);
			g.fillOval(15, 15, size, size);

		}
		else if (result==2) {

			g.fillOval(3, 3, size, size);
			g.fillOval(9, 9, size, size);
			g.fillOval(15, 15, size, size);

		}
		else if (result==3) {

			g.fillOval(3, 3, size, size);
			g.fillOval(15, 3, size, size);
			g.fillOval(15, 15, size, size);
			g.fillOval(3, 15, size, size);

		}
		else if (result==4) {

			g.fillOval(3, 3, size, size);
			g.fillOval(15, 3, size, size);
			g.fillOval(15, 15, size, size);
			g.fillOval(3, 15, size, size);
			g.fillOval(9, 9, size, size);

		}
		else if (result==5) {

			g.fillOval(3, 3, size, size);
			g.fillOval(15, 3, size, size);
			g.fillOval(15, 15, size, size);
			g.fillOval(3, 15, size, size);
			g.fillOval(9, 3, size, size);
			g.fillOval(9, 15, size, size);

		}

		g.dispose();

		return die;

	}

	/**
	 * Checks where the mouse was clicked
	 * @param x x co-ordinate
	 * @param y y co-ordinate
	 * @return int type of button
	 */
	public int insideButton(int x, int y) {

		int W=21;
		int H=21;

		int B=0;

		if (x >= 120 && x < (120 + W) && y >= 180 && y < (180 + H)) {
			B=1;
		}
		else if (x >= 120 && x < (120 + W) && y >= 211 && y < (211 + H)) {
			B=2;
		}
		else if (x >= 120 && x < (120 + W) && y >= 242 && y < (242 + H)) {
			B=3;
		}
		else if (x >= 339 && x < (339 + W) && y >= 180 && y < (180 + H)) {
			B=4;
		}
		else if (x >= 339 && x < (339 + W) && y >= 211 && y < (211 + H)) {
			B=5;
		}

		else if (game.getSimone()) {

		    if (x >= 339 && x < (339 + W) && y >= 232 && y < (232 + H)) {
			B=6;
		    }

		}

		return B;

	}

	/**
	 * Works out where the mouse was clicked
	 * @param e A mouse event
	 */
	public void mouseClicked(MouseEvent e) {

		int click=insideButton(e.getX(),e.getY());

		if (max != 0 && canRetreat) {

			if (click == 1) { nod=1; }
			if (click == 2 && max > 1) { nod=2; }
			if (click == 3 && max > 2) { nod=3; }

		}
		else if (max != 0) {

			if (click == 4) { nod=1; }
			if (click == 5 && max > 1) { nod=2; }

			if (game.getSimone()) {

				if (click == 6 && max > 2) { nod=3; }

			}


		}

		battle.repaint();

	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}

}

⌨️ 快捷键说明

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