import java.io.*;
class Plane {
/*private int [][]z=new int[10][10];*/
private int [][]point=new int[1][2];
private int x;
private int y;
private int direction;
private int [][][]impoint=new int[10][1][2];
public int [][][] getImpoint() {
return impoint;
}
/*public void setX(int x) {
this.x=x;
}
public void setY(int y) {
this.y=y;
}*/
public void produce(int i) throws IOException {
int [][]point=new int[1][2];
if(i==0) {
direction=(int)(Math.random()*4)+1;
while(true) {
point=randomPoint();
if(judge(point[0][0],point[0][1])) {
break;
}
}
this.point=point;
f();
}
if(i==1) {
direction=(int)(Math.random()*4)+1;
while(true) {
System.out.println("请输入一组核心坐标:");
point=readPoint();
if(judge(point[0][0],point[0][1])) {
break;
}
}
this.point=point;
f();
}
}
private boolean judge(int x,int y) {
switch(direction) {
case 1:
if((x>=2&&x<=8)&&(y>=3&&y<=8)) {
return true;
}
break;
case 2:
if((x>=3&&x<=8)&&(y>=3&&y<=9)) {
return true;
}
break;
case 3:
if((x>=3&&x<=9)&&(y>=3&&y<=8)) {
return true;
}
break;
default :
if((x>=3&&x<=8)&&(y>=2&&y<=8)) {
return true;
}
}
return false;
}
private int[][] randomPoint() {
int [][]x=new int[1][2];
x[0][0]=(int)(Math.random()*10)+1;
x[0][1]=(int)(Math.random()*10)+1;
return x;
}
private int [][] readPoint() throws IOException {
int [][]x=new int[1][2];
int ch;
int num=0;
while(true) {
ch=System.in.read();
switch(ch) {
case ',':
x[0][0]=num;
num=0;
break;
case '\r':
x[0][1]=num;
num=0;
break;
case '\n':
return x;
default :
num=num*10+ch-'0';
}
}
}
/*public Plane() {
this.x=x;
this.y=y;
direction=(int)(Math.random()*4)+1;
f();
}
public Plane() {
this.x=5;
this.y=5;
direction=(int)(Math.random()*4)+1;
f();
}*/
private void f() {
x=point[0][0];
y=point[0][1];
switch(direction) {
case 1:
f1();
break;
case 2:
f2();
break;
case 3:
f3();
break;
default :
f4();
}
}
private void f1() {
impoint[0]=new int[][]{{x,y}};
impoint[1]=new int[][]{{x,y+1}};
impoint[2]=new int[][]{{x,y+2}};
impoint[3]=new int[][]{{x,y-1}};
impoint[4]=new int[][]{{x,y-2}};
impoint[5]=new int[][]{{x-1,y}};
impoint[6]=new int[][]{{x+1,y}};
impoint[7]=new int[][]{{x+2,y}};
impoint[8]=new int[][]{{x+2,y+1}};
impoint[9]=new int[][]{{x+2,y-1}};
}
private void f2() {
impoint[0]=new int[][]{{x,y}};
impoint[1]=new int[][]{{x-1,y}};
impoint[2]=new int[][]{{x-2,y}};
impoint[3]=new int[][]{{x+1,y}};
impoint[4]=new int[][]{{x+2,y}};
impoint[5]=new int[][]{{x,y+1}};
impoint[6]=new int[][]{{x,y-1}};
impoint[7]=new int[][]{{x,y-2}};
impoint[8]=new int[][]{{x-1,y-2}};
impoint[9]=new int[][]{{x+1,y-2}};
}
private void f3() {
impoint[0]=new int[][]{{x,y}};
impoint[1]=new int[][]{{x,y+1}};
impoint[2]=new int[][]{{x,y+2}};
impoint[3]=new int[][]{{x,y-1}};
impoint[4]=new int[][]{{x,y-2}};
impoint[5]=new int[][]{{x+1,y}};
impoint[6]=new int[][]{{x-1,y}};
impoint[7]=new int[][]{{x-2,y}};
impoint[8]=new int[][]{{x-2,y+1}};
impoint[9]=new int[][]{{x-2,y-1}};
}
private void f4() {
impoint[0]=new int[][]{{x,y}};
impoint[1]=new int[][]{{x+1,y}};
impoint[2]=new int[][]{{x+2,y}};
impoint[3]=new int[][]{{x-1,y}};
impoint[4]=new int[][]{{x-2,y}};
impoint[5]=new int[][]{{x,y-1}};
impoint[6]=new int[][]{{x,y+1}};
impoint[7]=new int[][]{{x,y+2}};
impoint[8]=new int[][]{{x+1,y+2}};
impoint[9]=new int[][]{{x-1,y+2}};
}
}
class T {
public static void main(String[]args) throws IOException {
Plane p=new Plane();
Plane p1=new Plane();
p.produce(0);
p1.produce(1);
view(p.getImpoint());
System.out.println("*****************************");
view(p1.getImpoint());
game(p.getImpoint(),p1.getImpoint());
}
public static void game(int [][][]p,int [][][]p1) throws IOException {
int [][]x=new int[1][2];
int [][]y=new int[1][2];
int []x1=new int[1];
x1[0]=0;
int []y1=new int[1];
y1[0]=0;
while(true) {
System.out.println("请输入一组坐标:");
x=readPoint();
if(!result(p,x,x1)) {
System.out.println("人获胜");
break;
}
System.out.println("系统自动产生一组坐标:");
y=randomPoint();
System.out.println(" "+y[0][0]+","+y[0][1]);
if(!result(p1,y,y1)) {
System.out.println("机获胜");
break;
}
}
}
public static boolean result(int [][][]x,int [][]y,int []count) {
boolean flag=true;
if(equal(x[0],y)) {
flag=false;
}
for(int i=1;i<10;i++) {
if(equal(x[i],y)) {
count[0]++;
}
}
if(count[0]==3) {
flag=false;
}
return flag;
}
public static int [][] readPoint() throws IOException {
int [][]x=new int[1][2];
int ch;
int num=0;
while(true) {
ch=System.in.read();
switch(ch) {
case ',':
x[0][0]=num;
num=0;
break;
case '\r':
x[0][1]=num;
num=0;
break;
case '\n':
return x;
default :
num=num*10+ch-'0';
}
}
}
public static int[][] randomPoint() {
int [][]x=new int[1][2];
x[0][0]=(int)(Math.random()*10)+1;
x[0][1]=(int)(Math.random()*10)+1;
return x;
}
public static boolean equal(int [][]x,int [][]y) {
if(x.length!=y.length) {
return false;
}
for(int i=0;i<x.length;i++) {
if(x[i].length!=y[i].length) {
return false;
}
}
for(int i=0;i<x.length;i++) {
for(int j=0;j<x[i].length;j++) {
if(x[i][j]!=y[i][j]) return false;
}
}
return true;
}
public static void view(int [][][]x) {
for(int i=0;i<x.length;i++) {
for(int j=0;j<x[i].length;j++) {
for(int k=0;k<x[i][j].length;k++) {
System.out.println(x[i][j][k]);
}
System.out.println("=================");
}
}
}
}
XX.rar_java飞机大战
版权申诉
17 浏览量
2022-09-20
22:30:04
上传
评论
收藏 1KB RAR 举报
周楷雯
- 粉丝: 80
- 资源: 1万+
最新资源
- Anaconda3-2024.02-1-Windows-x86-64.exe
- stm32cubemx can通信 一个板子负责传感器采集 一个板子负责wifi传递到网页 网页可控制传感器板子.zip
- k8s集群搭建1.27.1版本(来源于图灵k8s笔记)
- 树莓派连接 DS18B20 温度传感器读取温度时监控客户端,服务器端连接状况,实现断线重连机制
- 小游戏-坦克大战,你认为的小游戏
- 最好用的富文本编辑器wangeditor
- jQuery 3.7.1
- 校园失物招领小程序源码可作毕业设计
- SAP客户端GUI740安装包(JAVA版本)
- winlibs-x86-64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64msvcrt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈