📄 creatonsquest.java
字号:
}
}//end of main method
public static int inventory(int lvl, int str, int def, int mag,int skill)throws Exception{//method to display users inventory
int b=1;
System.out.println("---------------------------------------");
System.out.println("Your level is "+lvl);
System.out.println("Your strength level is "+str);
System.out.println("Your defence level is "+def);
System.out.println("Your magic level is "+mag);
System.out.println("You have "+skill+" skill points left to place");
System.out.println("---------------------------------------");
return b;
}//end of inventory method
public static int ability(int lvl){//dispalys the abilities the user is capable of
System.out.println("At your level you have the ability to do the following:");
System.out.println("Punch and Minor Heal");
if(lvl>=5){
System.out.println("Slash and Flame Bolt");
}
if(lvl>=10){
System.out.println("Kick and Wind Strike");
}
if(lvl>=15){
System.out.println("Range Attack and Poison Arrow");
}
if(lvl>=25){
System.out.println("Double Attack and Heal");
}
if(lvl>=35){
System.out.println("Eagle Strike and Serpent Strike");
}
if(lvl>=50){
System.out.println("Critical Hit and Meteor Shower");
}
if(lvl>=65){
System.out.println("Triple Attack and Holy Healing");
}
if(lvl>=80){
System.out.println("Flying Kick and Holy Light");
}
if(lvl>=100){
System.out.println("Berserk of Rage and Devastate");
}
int b=1;
return b;
}//end of ability method
public static int save(int lvl,int str,int def,int mag,int exp,int skill,String name)throws Exception{//method to output and save all user details
FileOutputStream file=new FileOutputStream(name);
PrintWriter file2=new PrintWriter(file);
file2.println(lvl);
file2.println(str);
file2.println(def);
file2.println(mag);
file2.println(exp);
file2.println(skill);
file2.close();
int b=1;
return b;
}
public static int points(int lvl,int str,int def,int mag, int exp, int skill,String name)throws Exception{//method to allocate skill points
int a=0;
int tem_str=0;
int tem_def=0;
int tem_mag=0;
boolean error=true;
while(error){
System.out.print("How many points do you wish to place in Strength 0-"+skill+"?");
try{
tem_str=key.readInt(tem_str);
str=tem_str+str;
if((tem_str<=skill)&&(tem_str>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
error=true;
skill=skill-tem_str;
while(error){
System.out.println("You have "+skill+" remaining");
System.out.print("How many points do you wish to place in Defence 0-"+skill+"?");
try{
tem_def=key.readInt(tem_def);
def=tem_def+def;
if((tem_def<=skill)&&(tem_def>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
error=true;
skill=skill-tem_def;
while(error){
System.out.println("You have "+skill+" remaining");
System.out.print("How many points do you wish to place in Magic 0-"+skill+"?");
try{
tem_mag=key.readInt(mag);
mag=mag+tem_mag;
if((tem_mag<=skill)&&(tem_mag>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
skill=0;
FileOutputStream file=new FileOutputStream(name);
PrintWriter file2=new PrintWriter(file);
file2.println(lvl);
file2.println(str);
file2.println(def);
file2.println(mag);
file2.println(exp);
file2.println(skill);
file2.close();
return skill;
}//end of points method
public static int newchar()throws Exception{//method that create's a new character
String name="";
String txt=".txt";
String filehandle="";
int str=0;
int def=0;
int mag=0;
int lvl=0;
boolean error=true;
int points=20;
int exp=0;
int skill=0;
String enter="";
System.out.print("Please enter your Character's name: ");
name=key.readString(name);
filehandle=name+txt;
FileOutputStream file=new FileOutputStream(filehandle);
PrintWriter file1=new PrintWriter(file);
lvl=1;
System.out.println("You may now choose to place ability points");
System.out.println("You have 20 points to place over 3 categories");
System.out.println("Strength, Defence, Magic");
while(error){
System.out.print("How many points do you wish to place in Strength 0-20?");
try{
str=key.readInt(str);
if((str<=points)&&(str>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
error=true;
points=points-str;
while(error){
System.out.println("You have "+points+" remaining");
System.out.println("How many points do you wish to place in Defence 0-"+points+"?");
try{
def=key.readInt(def);
if((def<=points)&&(def>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
error=true;
points=points-def;
while(error){
System.out.println("You have "+points+" remaining");
System.out.println("How many points do you wish to place in Magic 0-"+points+"?");
try{
mag=key.readInt(mag);
if((mag<=points)&&(mag>=0)){
error=false;
}
}
catch(NumberFormatException e){
System.out.println("Invalid Number");
}
}
System.out.println("You have created a your new character");
System.out.println("Please return to the main menu and select play existing character");
System.out.println("Have safe journey's with "+name);
file1.println(lvl);
file1.println(str);
file1.println(def+50);
file1.println(mag);
file1.println(exp+100);
file1.println(skill);
file1.close();
System.out.println("Press Enter to return to main menu");
enter=key.readString(enter);
int b=0;
return b;
}//end of newchar method
public static int combat (int skill, int exp, int lvl, int str, int def, int mag, String name, String monster) throws Exception{//combat method
int x=0;
double a=0;//stores random number
int b=0;
double heal=0;//stores the value of a players heal
int monster_lvl=0;//stores monster level
int monster_str=0;//stores monster strength
int monster_def=0;//stores monster defence
int monster_mag=0;//stores monster magic
int monster_exp=0;//stores monster experience
int monster_skill=0;//stores monster skill
double mexp=0;//stores random experience
double mskill=0;//stores random skill
double mlvl=0;//stores random level
String monster_name="";//stores monster name
int M=0;//stores users melee attack choice
int S=0;//stores users magic attack choice
int lvlgap=lvl-monster_lvl;//stores the difference of the level of the user compared to the monster
double ran=0;//stores random number
double hint;//stores random number
int dmg=0;//stores user damage
int monster_dmg=0;//monster damage
String txt=".txt";
String message="";//stores hint message
int realdef=0;//stores user defence
int Heal=0;//stores heal value
boolean error=true;
realdef=def;
monster_name=monster;
monster=monster+txt;
FileReader File2=new FileReader(monster);
BufferedReader reader2=new BufferedReader(File2);
mlvl=(Integer.parseInt(reader2.readLine())*Math.random()*5)+1;
monster_lvl=(int)mlvl;
monster_str=Integer.parseInt(reader2.readLine());
monster_def=Integer.parseInt(reader2.readLine())+50;
monster_mag=Integer.parseInt(reader2.readLine());
mexp=(Integer.parseInt(reader2.readLine()))*(Math.random()*5)+1;
monster_exp=(int)mexp;
mskill=(Integer.parseInt(reader2.readLine()))*(Math.random()*3)+1;
monster_skill=(int)mskill;
while((monster_def>=1)&&(def>1)){//loop to run combat while fighters are alive
lvlgap=lvl-monster_lvl;
while(error){
System.out.println("");
System.out.println("");
System.out.println("1.) Melee Attack");
System.out.println("2.) Magic Attack");
System.out.print("Which type of attack do you wish to use? ");
try{
x=key.readInt(x);
}
catch(NumberFormatException e){
}
if((x<=2)&&(x>0)){
error=false;
}
}
error=true;
if(x==1){
while(error){
S=0;
System.out.println("");
System.out.println("");
System.out.println("1.) Punch");
System.out.println("2.) Slash");
System.out.println("3.) Kick");
System.out.println("4.) Range Attack");
System.out.println("5.) Double Attack");
System.out.println("6.) Eagle Strike");
System.out.println("7.) Critical Hit");
System.out.println("8.) Triple Attack");
System.out.println("9.) Flying Kick");
System.out.println("10.) Berserk of Rage");
System.out.print("Which Attack Do you wish to use? ");
try{
M=key.readInt(M);
}
catch(NumberFormatException e){
}
if((M<=10)&&(M>0)){
error=false;
}
}
}
error=true;
if(x==2){
while(error){
M=0;
System.out.println("");
System.out.println("");
System.out.println("1.) Minor Heal");
System.out.println("2.) Flame Bolt");
System.out.println("3.) Wind Strike");
System.out.println("4.) Poison Arrow");
System.out.println("5.) Heal");
System.out.println("6.) Serpent Strike");
System.out.println("7.) Meteor Shower");
System.out.println("8.) Holy Healing");
System.out.println("9.) Holy Light");
System.out.println("10.) Devastate");
try{
S=key.readInt(S);
}
catch(NumberFormatException e){
}
if ((S<=10)&&(S>0)){
error=false;
}
}
}
error=true;
dmg=0;
Heal=0;
ran=0;
heal=0;
if(M==1){
a=Math.random()*lvl+1;
if(a>=1.1){
ran=(Math.random()*(lvl))*(Math.random()*(str));
}
dmg=(int)ran;
if(dmg>500){
dmg=1000;
}
}
if((M==2)&&(!(lvl<5))){
a=Math.random()*lvl+1;
a=Math.round(a);
if(a>=2){
ran=(Math.random()*(lvl+1))*(Math.random()*(str+1))+50;
dmg=(int)ran;
if(dmg>1000){
dmg=10000;
}
}
}
if((M==3)&&(!(lvl<=10))){
a=Math.random()*lvl+1;
a=Math.round(a);
if(a>=3){
ran=(Math.random()*(lvl+2))*(Math.random()*(str+2))+75;
dmg=(int)ran;
if(dmg>30000){
dmg=30000;
}
}
}
if((M==4)&&(!(lvl<=15))){
a=Math.random()*lvl+1;
a=Math.round(a);
if(a>=4){
ran=(Math.random()*(lvl+3))*(Math.random()*(str+3))+100;
dmg=(int)ran;
if(dmg>50000){
dmg=50000;
}
}
}
if((M==5)&&(!(lvl<=25))){
a=Math.random()*lvl+1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -