日期:2014-05-20 浏览次数:20881 次
import java.util.*;
import java.io.*;
public class Dragon2
{
public static void main(String[] args) throws IOException
{
System.out.print("Enter file name >> ");
String name;
int wingspan;
String weyr;
String colour;
int y2;
int x2;
int famle;
String input;
int y1;
int x1;
Scanner sc = new Scanner(System.in);
File file = new File(sc.nextLine());
if(file.exists())
{
Scanner file1 = new Scanner(file);
name = file1.nextLine();
wingspan = file1.nextInt();
file1.nextLine();
weyr = file1.nextLine();
colour = file1.nextLine();
y2 = file1.nextInt();
file1.nextLine();
x2 = file1.nextInt();
file1.nextLine();
int flame = file1.nextInt();
file1.nextLine();
file1.close();
Random random1 = new Random();
y1 = (int)random1.nextInt(2001)+1000;
Random random2 = new Random();
x1 = (int)random2.nextInt(4001);
System.out.println("Thread position");
System.out.println("x = " + x1 + " y = " + y1);
System.out.println("Dragon position");
System.out.println("x = " + x2 + " y = " + y2);
System.out.println(" "); //space
System.out.println(" Menu ");
System.out.println("left - Go left");
System.out.println("right - Go right");
System.out.println("up - Go up");
System.out.println("down - Go down");
System.out.println("flame on - breathe fire");
System.out.println("between - go between");
System.out.println("quit");
System.out.print("Enter choice >> ");
input = sc.nextLine().toUpperCase();
Random random3 = new Random();
int number = (int)random3.nextInt(17);
do
{
if(input == "LEFT")
{
x2 = x2 - ((100/wingspan)*50);
if(number == 0 || number == 3 || number == 11)
{
x1 += 100;
}
else if(number == 5 || number == 9 || number == 14)
{
x1 = x1 - 100;
}
else
{
x1 = x1;
y1 = y1 - 100;
}
}
else if(input == "RIGHT")
{
x2 = x2 +((100/wingspan)*50);
if(number == 0 || number == 3 || number == 11)
{
x1 += 100;
}
else if(number == 5 || number == 9 || number == 14)
{
x1 = x1 - 100;
}
else
{
x1 = x1;
y1 = y1 - 100;
}
}
else if(input == "UP")
{
y2 = y2 + (wingspan * 5);
if(number == 0 || number == 3 || number == 11)
{
x1 += 100;
}
else if(number == 5 || number == 9 || number == 14)
{
x1 = x1 - 100;
}
else
{
x1 = x1;
y1 = y1 - 100;
}
}
else if(input == "DOWN")
{
y2 = y2 - (wingspan * 5);
if(y2 < 0)
{
y2 =0;
}
if(number == 0 || number == 3 || number == 11)
{
x1 += 100;
}
else if(number == 5 || number == 9 || number == 14)
{
x1 = x1 - 100;
}
else
{
x1 = x1;
y1 = y1 - 100;
}
}
else if(input == "FLAMEON ON")
{
if((int)Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)) <= flame)
{
System.out.println("Congratulations Rider!!!");
System.out.println("you and your "+colour+" dragon "+"\""+name+"\" have successfully destroyed Thread "+weyr+" weyr is proud of you!");