版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
//:HitPlane.java
//a game to destory the plane !
//输入 myz 可以直接胜利
import java.util.*;
import java.io.*;
public class HitPlane {
private int midNumber,azimuthNumber,headNumber;
HitPlane(){
System.out.println("_____________________________");
System.out.println("A game to destory the plane !");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
setPlane();
}
//set the plane to map
void setPlane(){
midNumber = setMidPoint()*10 + setMidPoint();
azimuthNumber = setAzimuth();
headNumber = setHeadPoint(midNumber,azimuthNumber);
System.out.println("One Plane is ready for you !");
System.out.println("The Plane is in the square of 8X8 !");
System.out.print("Please input the point like 11 or 54 in (1-8) X (1-8) ");
System.out.println("to destory the plane !");
System.out.println("the first number is horizontal,second is uprightness !");
System.out.println("GOOD LUCK !");
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println("If you want to stop the game please press [Ctrl+Break]");
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
//set the middle of the point
int setMidPoint(){
int randomNumber;
do{
randomNumber = (int)(Math.random()*7);
}while(randomNumber<3);
return randomNumber;
}
//set the head of the plane
int setHeadPoint(int midNumber,int azimuthNumber){
int headNumber = midNumber;
switch(azimuthNumber){
case 1:headNumber=headNumber%10+(headNumber/10+2)*10;break;
case 2:headNumber=headNumber%10+(headNumber/10-2)*10;break;
case 3:headNumber=(headNumber%10+2)+headNumber/10*10;break;
case 4:headNumber=(headNumber%10-2)+headNumber/10*10;break;
default: System.out.println("this default is crazy~~~");
}
return headNumber;
}
//set the E-W-S-N(1-2-3-4)
int setAzimuth(){
int randomNumber;
do{
randomNumber = (int)(Math.random()*5);
}while(randomNumber<1);
int azimuthNumber = randomNumber;
return azimuthNumber;
}
//the player choose a point to destory the plane
void choosePoint() throws IOException{
int destroyIt = 0;
while(destroyIt == 0){
System.out.print("Input the azimuth:");
BufferedReader buf = new BufferedReader(new InputStreamReader
(System.in));
String str = buf.readLine();
if (str.equals("myz")){
System.out.println ("Congratulation! You Win!");
destroyIt =1;
}
else{
try{
int azimuth = Integer.parseInt(str);
if(provePoint(azimuth) == 1){
int compareP = comparePoint(azimuth,midNumber,azimuthNumber,headNumber);
if(compareP == 0){
System.out.println ("Congratulation! You Win!");
destroyIt =1;
}
else if(compareP == 1){
System.out.println ("You Hit the body of Plane!");
}
else if(compareP == 2){
System.out.println ("Bad luck,you dont hit the plane!");
}
}
else {
System.out.println("---------------------------------------");
System.out.println("You input beyond the area of 1-8 X1-8 !");
System.out.println("Please input again !");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
catch(Exception e){
System.out.println("---------------------------------------");
System.out.println("You input beyond the area of 1-8 X1-8 !");
System.out.println("Please input again !");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
}
}
}
//prove the point is in effect
int provePoint(int azimuth){
if(((azimuth%10)>8) || ((azimuth%10)<1) || ((azimuth/10)>8) || ((azimuth/10)<1)){
return 0;
}
else
return 1;
}
//compare your input to the right point
int comparePoint(int azimuth,int midNumber,int azimuthNumber,int headNumber){
int sidePoint1=0;
int sidePoint2=0;
switch(azimuthNumber){
case 1:sidePoint1=midNumber%10-1+(midNumber/10-2)*10;
sidePoint2=midNumber%10+1+(midNumber/10-2)*10;break;
case 2:sidePoint1=midNumber%10-1+(midNumber/10+2)*10;
sidePoint2=midNumber%10+1+(midNumber/10+2)*10;break;
case 3:sidePoint1=midNumber%10-2+(midNumber/10+1)*10;
sidePoint2=midNumber%10-2+(midNumber/10-1)*10;break;
case 4:sidePoint1=midNumber%10+2+(midNumber/10+1)*10;
sidePoint2=midNumber%10+2+(midNumber/10-1)*10;break;
default: System.out.println("this default is crazy~~~");
}
if(azimuth == headNumber){
azimuth = 0;
}
else if((azimuth == sidePoint1) || (azimuth == sidePoint2) || (azimuth == midNumber)){
azimuth = 1;
}
//change the azimuth to compare to midNumber
else if(((azimuth+20) == midNumber) || ((azimuth+10) == midNumber) || ((azimuth-20) == midNumber) || ((azimuth-10) == midNumber) || ((azimuth+2) == midNumber) || ((azimuth+1) == midNumber) || ((azimuth-2) == midNumber) || ((azimuth-1) == midNumber)){azimuth = 1;}
else azimuth = 2;
return azimuth;
}
//-----entry-----
public static void main(String[] args) throws IOException{
HitPlane a = new HitPlane();
a.choosePoint();
}
}
///:~