📄 c045ee207bfa001c187a96d076d31f00
字号:
package com.sans.ninemen.test;
import java.applet.*;
//required to paint on screen
import java.awt.*;
//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 =0;
public static int offset=100;
//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);
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,initialPosition);
while(gameStatus==false) {
if(moveNo <=18) {
//String finalPosition =
}
}
}
public static void drawCoins(Graphics g,String initialPosition) {
int width=10;
int height=10;
for(int i=0;i<23;i++) {
int x,y;
x=getCood(i,1);
y=getCood(i,2);
switch(initialPosition.charAt(i)) {
case 'x':break;
case 'w':
g.fillRect(x, y, width, height);
break;
case 'b':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 + -