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

📄 200847628cfa001c187a96d076d31f00

📁 Svm based face detector code
💻
字号:
package com.sans.ninemen.test;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;

import com.sans.ninemen.core.MM;
import com.sans.ninemen.core.Utility;


//the start of an applet - HelloWorld will be the executable class
//Extends applet means that you will build the code on the standard Applet class
public class GameManager extends Applet implements MouseListener
{
	public static boolean gameStatus=true;
	public static int posArray;
	public static String initialPosition="xxxxxxxxxxxxxxxxxxxxxxx";
	public static int moveNo =1;
	public static int offset=10;
	JButton playButton = new JButton();
	boolean mouseEntered;
	int xpos;
	int ypos;
//The method that will be automatically called  when the applet is started
	public void init() 
	{
	// It is required but does not need anything.
		addMouseListener(this);
	}
	
public void mouseClicked (MouseEvent me) {
		
		// Save the coordinates of the click lke this.
		xpos = me.getX();
		ypos = me.getY();
		if(me.getButton()==me.BUTTON1);
		// Check if the click was inside the rectangle area.
		/*if (xpos > rect1xco && xpos < rect1xco+rect1width && ypos >rect1yco && ypos < rect1yco+rect1height) 
			rect1Clicked = true;
		// if it was not then rect1Clicked	is false;
		else 
			rect1Clicked = false;*/
		//show the results	of the click
		repaint();
		
	}

	// This is called when the mous has been pressed
	public void mousePressed (MouseEvent me) {}
	
	// When it has been released
	// not that a click also calls these Mouse-Pressed and Released.
	// since they are empty nothing hapens here.
	public void mouseReleased (MouseEvent me) {}	
	
	// This is executed when the mouse enters the applet. it will only
	// be executed again when the mouse has left and then re-entered.
	public void mouseEntered (MouseEvent me) {
		// Will draw the "inside applet message"
		mouseEntered = true;
		repaint();
	}
	
	// When the Mouse leaves the applet.
	public void mouseExited (MouseEvent me) {
		// will draw the "outside applet message"
		mouseEntered = false;
		repaint();
	}	

	
	 public void actionPerformed(ActionEvent e) {
	        e.getActionCommand();
	    }


//This method gets called when the applet is terminated
//That's when the user goes to another page or exits the browser.
	public void stop() 
	{
	// required but no actions neede here now.
	}


//The standard method that you have to use to paint things on screen
//This overrides the empty Applet method, you can't called it "display" for example.
	
	public void paint(Graphics g) 
	{
	//method to draw text on screen
	// String first, then x and y coordinate.
		//g.drawString("Nine Men Morris",20,20);
		System.out.println("i am here="+moveNo);
		g.drawRect(0+offset, 0+offset, 500, 500);
		g.drawRect(50+offset, 50+offset, 400, 400);
		g.drawRect(100+offset, 100+offset, 300, 300);
		g.drawLine(0+offset,0+offset, 100+offset, 100+offset);
		g.drawLine(0+offset,500+offset, 100+offset, 400+offset);
		g.drawLine(500+offset,0+offset, 400+offset, 100+offset);
		g.drawLine(500+offset,500+offset, 400+offset, 400+offset);
		g.drawLine(250+offset, 0+offset, 250+offset, 100+offset);
		g.drawLine(0+offset, 250+offset, 100+offset, 250+offset);
		g.drawLine(250+offset, 500+offset, 250+offset, 450+offset);
		g.drawLine(500+offset, 250+offset, 400+offset, 250+offset);
		String tempString = initialPosition.toLowerCase();
		drawCoins(g,tempString);
		if (gameStatus==false) {
			System.exit(0);
		}
		
			String finalPosition;
			if(moveNo <=18) {
				if(moveNo%2==1) {
					finalPosition= new MM().getMaxMove(initialPosition,4,0);
				} else {
					 
					finalPosition= new MM().getMaxMove(Utility.reverseColors(initialPosition),4,0);
					finalPosition = Utility.reverseColors(finalPosition);
				}
				
			} else {
				
				if(moveNo%2==1) {
					finalPosition = new MM().getMaxMove(initialPosition,4,1);
				} else {					 
					finalPosition= new MM().getMaxMove(Utility.reverseColors(initialPosition),4,1);
					finalPosition = Utility.reverseColors(finalPosition);
				}
				int x= Utility.countChar(finalPosition,'W');
				int y= Utility.countChar(finalPosition,'B');
				if(x<=2) {
					g.drawString("Black Won", 5, 3);
					gameStatus=false;
					//break;
				} else if(y <= 2) {
					g.drawString("White Won", 5, 3);
					gameStatus=false;
					//break;
				}
				
			}		
			
		moveNo++;
		initialPosition = finalPosition;
		
		/*repaint();
		update(g);
		try {
			Thread.sleep(2);
				}catch(Exception e) {System.out.println("interrupted");
				}*/
		
	}
	
	public static void drawCoins(Graphics g,String initialPosition) {
		int width=30;
		int height=30;
		for(int i=0;i<23;i++) {
			int x,y;
			x=getCood(i,1)+offset;
			y=getCood(i,2)+offset;
			switch(initialPosition.charAt(i)) {
			case 'x':break;
			case 'w':
				g.drawOval(x-width/2, y-width/2, width, height);
				//g.drawRect(x-width/2, y-width/2, width, height);				
				break;
			case 'b':
				g.fillOval(x-width/2, y-width/2, width, height);
				break;
			}
		}
	}
	
	public static int getCood(int pos,int mode) {
		int x,y;
		x=y=0;
		switch(pos) {
		case 0:
			x=0;y=500;
			break;
		case 1:
			x=250;y=500;
			break;
		case 2:
			x=500;y=500;
			break;
		case 3:
			x=50;y=450;
			break;
		case 4:
			x=250;y=450;
			break;
		case 5:
			x=450;y=450;
			break;
		case 6:
			x=100;y=400;
			break;
		case 7:
			x=400;y=400;
			break;
		case 8:
			x=0;y=250;
			break;
		case 9:
			x=50;y=250;
			break;
		case 10:
			x=100;y=250;
			break;
		case 11:
			x=400;y=250;
			break;
		case 12:
			x=450;y=250;
			break;
		case 13:
			x=500;y=250;
			break;
		case 14:
			x=100;y=100;
			break;
		case 15:
			x=250;y=100;
			break;
		case 16:
			x=400;y=100;
			break;
		case 17:
			x=50;y=50;
			break;
		case 18:
			x=250;y=50;
			break;
		case 19:
			x=450;y=50;
			break;
		case 20:
			x=0;y=0;
			break;
		case 21:
			x=250;y=0;
			break;
		case 22:
			x=500;y=0;
			break;
		
		}
		if(mode==1) return x;
		return y;
	}

}

⌨️ 快捷键说明

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