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

📄 shinterface.java

📁 一个非常不错的java纸牌游戏源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

		else if (label.equals("Close Connections")) {
			closeConnection();
		}

		else if (label.equals("1 Player")) {
			addMsg("One Play Option");
			if (dealer != null || player != null) {
				addMsg("You already have sockets open.  You must select  \"Close Connections\"  before you can create a new connection");
			} else {
				DealerD dealerD = new DealerD(this);
				dealerD.show();
				playersName = dealerD.getName();
				if (playersName != "cancel#*#") {
					if (dealerD.fastgame())
						addMsg("Fast Game Selected");
					if (dealerD.seven())
						addMsg("Must play under Seven Selected");
					if (dealerD.nine())
						addMsg("Nine is Invisible Selected");
					if (dealerD.swap())
						addMsg("Card Swap at start of game Selected");
					dealer = new Dealer(this, cardspic, g, hand, back, backSW,
							dealerD.fastgame(), dealerD.seven(),
							dealerD.nine(), dealerD.swap(), pointer, burntPic,
							score);
					dealer.onePlayer(playersName);
					imServer = true;
				}
			}
		}

		else if (label.equals("Redeal")) {
			if (dealer != null)
				dealer.redeal();
		}

		else if (label.equals("Start Game")) {
			if (dealer != null)
				dealer.start();
		}

		else if (label.equals("Scoreboard")) {
			score.display();
		}

		else if (label.equals("About")) {
			InfoD info = new InfoD(this);
			info.show();
		}

		else if (label.equals("Rules")) {
			try {
				Runtime
						.getRuntime()
						.exec(
								"cmd.exe /c start iexplore http://home.pacific.net.au/~cavenagh/SH/rules.html");
			} catch (Exception e) {
				addMsg("Error launching Internet Explorer.  Please visit http://home.pacific.net.au/~cavenagh/SH/rules.html");
			}
		}

		else if (label.equals("Home Page")) {
			try {
				Runtime
						.getRuntime()
						.exec(
								"cmd.exe /c start iexplore http://home.pacific.net.au/~cavenagh");
			} catch (Exception e) {
				addMsg("Error launching Internet Explorer.  Please visit http://home.pacific.net.au/~cavenagh");
			}
		}

		else if (label.equals("AI Speed")) {
			if (dealer != null) {
				Speed speed = new Speed(this, dealer.getAIPause());
				int temp = speed.getSpeed();
				addMsg("AI Speed: " + (double) temp / 1000 + " seconds");
				dealer.setAIPause(temp);
			} else
				addMsg("You must be the Dealer to change the AI Speed");
		}

		else if (label.equals("Multi Player Server")) {
			if (dealer != null || player != null) {
				addMsg("You already have sockets open.  You must select  \"Close Connections\"  before you can create a new connection");
			} else {
				DealerD dealerD = new DealerD(this);
				dealerD.show();
				playersName = dealerD.getName();
				if (!(playersName == "cancel#*#" || playersName.equals(""))) {
					if (dealerD.fastgame())
						addMsg("Fast Game Selected");
					if (dealerD.seven())
						addMsg("Must play under Seven Selected");
					if (dealerD.nine())
						addMsg("Nine is Invisible Selected");
					if (dealerD.swap())
						addMsg("Card Swap at start of game Selected");
					servermsg = new ServerMessage(this);
					servermsg.createConnection(playersName);
					dealer = new Dealer(this, cardspic, g, hand, back, backSW,
							dealerD.fastgame(), dealerD.seven(),
							dealerD.nine(), dealerD.swap(), pointer, burntPic,
							score);
					dealer.createConnection(playersName);
					imServer = true;

					try {// outputting host name and ip address
						java.net.InetAddress i = java.net.InetAddress
								.getLocalHost();
						java.net.InetAddress[] add = i.getAllByName(i
								.getHostName());

						addMsg("Host Name: " + i.getHostName()); // name
						addMsg("IP Address: " + i.getHostAddress()); // local
																		// IP
																		// address

						// Getting all address on system

						for (int n = 1; n < add.length; n++)
							addMsg("Other IP Address: "
									+ add[n].getHostAddress()); // Global IP
																// address

					} catch (Exception e) {
						addMsg("Error Finding IP : " + e);
						e.printStackTrace();
					}
				}
			}
		}

		else if (label.equals("Multi Player Client")) {
			if (dealer != null || player != null) {
				addMsg("You already have sockets open.  You must select  \"Close Connections\"  before you can create a new connection");
			} else {
				PlayerD playerD = new PlayerD(this);
				playerD.show();
				playersName = playerD.getName();
				String servername = playerD.getServer();
				if (!(playersName == "cancel" || servername == "cancel"
						|| playersName.equals("") || servername.equals(""))) {
					message = new Message(this);
					message.createConnection(servername, playersName);
					player = new Player(this, cardspic, g, hand, back, backSW,
							burntPic, pointer, score);
					player.createConnection(servername, playersName);
				}
			}
		} else {
			addMsg(": " + input.getText());
			if (servermsg != null)
				servermsg.sendMsg(input.getText());
			if (message != null)
				message.sendMsg(input.getText());
			input.setText("");
		}

	}

	public void closeConnection() {

		// Closing Sockets on Quiting
		if (servermsg != null)
			servermsg.endConnection();
		if (message != null)
			message.endConnection();
		if (dealer != null) {
			dealer.destroy();
			dealer = null;
		}
		if (player != null) {
			player.endConnection();
			player = null;
		}
		hand.removeAll();

		score = new Score(this);

		// redrawint title
		g.setColor(Color.black);
		g.fillRect(0, 0, 450, 550);
		g.setColor(Color.white);
		g.drawImage(title, -40, 120, this);
		g.setColor(Color.white);
		g.drawLine(0, 450, 450, 450);
		repaint();
	}

	private Image rotatePointer(Image img) {

		Image rot = null;

		int buffer[] = new int[15 * 15];
		int rotate[] = new int[15 * 15];

		PixelGrabber grabber = new PixelGrabber(img, 0, 0, 15, 15, buffer, 0,
				15);
		try {
			grabber.grabPixels();
		} catch (InterruptedException e) {
			addMsg("Rotate image error " + e);
		}
		for (int y = 0; y < 15; y++) {
			for (int x = 0; x < 15; x++) {
				rotate[((15 - x - 1) * 15) + y] = buffer[(y * 15) + x];
			}
		}
		rot = createImage(new MemoryImageSource(15, 15, rotate, 0, 15));

		return rot;
	}

	public void addMsg(String message) {
		if (message != null)
			msg.append(message + "\n");
		try { // scroll to end of display
			// msg.scrollRectToVisible(
			// new Rectangle(0,
			// msg.getLineCount() * , 0, (msg.getLineCount() + 5) * 100));
			// msg.scrollRectToVisible(msg.modelToView(msg.getLineCount()));
			Rectangle current = msg.getVisibleRect();
			int scrollunitinc = msg.getScrollableUnitIncrement(current,
					SwingConstants.VERTICAL, 1);
			// System.out.println("scrollunitinc " + scrollunitinc + " Y " +
			// current.getY());
			// current.setRect(current.getX(), current.getY() + scrollunitinc,
			// current.getWidth(), current.getHeight());
			current.setRect(current.getX(), (msg.getLineCount() + 1)
					* scrollunitinc, current.getWidth(), current.getHeight());
			// System.out.println("Y " + current.getY());
			msg.scrollRectToVisible(current);
		} catch (Exception ex) {
			System.out.println("\n Error scrolling to end " + ex);
		}

	}

	public void mousePressed(MouseEvent me) {
		if (myTurn) {
			int selection = hand.mouseClick(mouseX, mouseY);
			if (dealer != null && selection != -1)
				dealer.cardSelection(selection);
			if (player != null && selection != -1)
				player.cardSelection(selection);
		}
	}

	public void setmyTurn(boolean myTurn) {
		this.myTurn = myTurn;
	}

	// resizing image if to big for screen
	public void scalepic() {
		// g2.drawImage(offscreen, 0, 0, 338, 413, null);
		// AffineTransform at = new AffineTransform();
		// at.scale(0.75, 0.75);
		// g2d.transform(at);
		// g2d.drawImage(offscreen, 0, 0, null);
		// double temp = System.currentTimeMillis();
		g2.drawImage(offscreen, 0, 0, null);
		// addMsg("Time: " + (System.currentTimeMillis() - temp)/1000);
	}

	public boolean smallscreen() {
		if (screenSize.width < 1024)
			return true;
		return false;
	}

	public void repaint() {
		// if(screenSize.width < 1024){
		// offscreen2 = offscreen.getScaledInstance(338, 413, Image.SCALE_FAST);
		// imageI.setImage(offscreen2);
		// }
		panel.repaint();
		// panel.update();
	}

	public void mouseMoved(MouseEvent me) {
		// ajusting so mouse points are over image
		mouseX = me.getX() - 5;
		mouseY = me.getY() - 45;
		if (screenSize.width < 1024) {// scaling mouse movement if screen to
										// big
			mouseX = mouseX * 100 / 75;
			mouseY = mouseY * 100 / 75;
		}
		// addMsg("X: " + mouseX + " Y: " + mouseY);
	}

	public void mouseDragged(MouseEvent e) {
	}

	public void mouseEntered(MouseEvent me) {
	}

	public void mouseExited(MouseEvent me) {
	}

	public void mouseClicked(MouseEvent me) {
	}

	public void mouseReleased(MouseEvent me) {
	}

	public static void main(String[] args) {

		// setting look and feel
		// try {
		// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
		// UIManager.setLookAndFeel("javax.swing.plaf.mac.MacLookAndFeel");
		// } catch (Exception e) { System.out.println("Look and Feel Error " +
		// e); }

		try {
			SHinterface frame = new SHinterface();
			frame.setTitle("S-H");
			frame.setResizable(false);

			frame.pack();
			frame.setVisible(true);
		} catch (Exception e) {
			System.out.println("System Error: " + e);
		}
	}

	public void windowClosing(WindowEvent e) {
		// Closing Sockets on Quiting
		if (servermsg != null)
			servermsg.endConnection();
		if (message != null)
			message.endConnection();
		if (dealer != null)
			dealer.endConnection();
		if (player != null)
			player.endConnection();
		System.exit(0);
	}

	public void windowClosed(WindowEvent e) {
	}

	public void windowOpened(WindowEvent e) {
	}

	public void windowIconified(WindowEvent e) {
	}

	public void windowDeiconified(WindowEvent e) {
	}

	public void windowActivated(WindowEvent e) {
	}

	public void windowDeactivated(WindowEvent e) {
	}

}

⌨️ 快捷键说明

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