📄 a0dfce4c86fa001c187a96d076d31f00
字号:
package com.sans.ninemen.test;
import java.applet.Applet;
import java.awt.Graphics;
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
{
public static boolean gameStatus=true;
public static int posArray;
public static String initialPosition="xxxxxxxxxxxxxxxxxxxxxxx";
public static int moveNo =1;
public static int offset=10;
//The method that will be automatically called when the applet is started
public void init()
{
// It is required but does not need anything.
}
//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) {
return;
}
while(gameStatus==true) {
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(15000);
}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 + -