Java Problem.
Quaunaut
The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
<div class="IPBDescription">Boolean no method?</div> Why does Java not recognize this is a method?(look for the battle system):
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->import javax.swing.*;
class basepcnpc {
int strength;
int dexterity;
int agility;
int intelligence;
int wisdom;
int charisma;
int maxhp;
int maxmp;
int hp=maxhp;
int mp=maxmp;
String name;
String weaponname;
int weapondamage;
boolean learnedimpFireBall;
boolean alreadylearned;
int slashAttack(){
int a = strength + (agility/2) + weapondamage;
return a;
}
int useLightning(){
int l = intelligence + (charisma/2);
mp=mp-20;
return l;
}
int useHeal(){
int h = wisdom + (charisma/2);
mp=mp-30;
int overheal = 0;
for(; overheal<=h||hp<=maxhp; overheal++){
hp = hp+1;
}
return overheal;
}
boolean learnimpMove() {
boolean learned;
if(charisma > 18){
System.out.println("You learned the imp's move!");
return true;
}
else return false;
}
int LearnedimpFireBall(){
int fb = 0;
if(learnedimpFireBall=true){
fb = charisma + (intelligence/2);
}
if(fb==0){
System.out.println("You didn't learn the imp's move yet!");
}
return fb;
}
int useRanged() {
int r = dexterity + (agility/2) + weapondamage;
return r;
}
int impFireBall(){
int f = intelligence + wisdom;
return f;
}
basepcnpc() {
}
basepcnpc(int s, int d, int a, int i, int w, int c, int h, int m, String n){
strength=s;
dexterity=d;
agility=a;
intelligence=i;
wisdom=w;
charisma=c;
maxhp=h;
maxmp=m;
hp=maxhp;
mp=maxmp;
name=n;
}
}
class weapon {
int strength;
int dexterity;
int agility;
int intelligence;
int wisdom;
int charisma;
int maxhp;
int maxmp;
int hp;
int mp;
int weapondamage;
String weaponattribute;
}
/*class pcnpc {
String combatant1 = "player";
int str, dex, agi, Int, wis, cha, xhp, xmp, chp, cmp;
int getStr() {
int a = str;
return a;
}
}*/
class rpg {
public static void main(String args[]) throws java.lang.NoSuchMethodError{
basepcnpc first = new basepcnpc();
basepcnpc second = new basepcnpc();
/*The Battle System*/
boolean battle(first.name,second.name.name){ {
for(;first.name.hp>0&second.name.hp>0;) {
String Battlechoice = "3";
first.name.alreadylearned=false;
if(first.name.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
if(first.name.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
int battlechoice;
battlechoice = Integer.parseInt(Battlechoice);
if(battlechoice==1){
second.name.hp = second.name.hp - first.slashAttack();
System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
first.name.hp = first.name.hp-second.name.slashAttack();
System.out.println("first.name's HP: "+first.name.hp+"/"+first.name.maxhp);
}
if(battlechoice==2){
second.name.hp = second.name.hp - first.name.useLightning();
first.name.hp = first.name.hp-second.name.slashAttack();
}
if(battlechoice==3){
first.name.hp = first.name.useHeal();
System.out.println("first.name's Healed HP: "+first.name.hp);
first.name.hp = first.name.hp-second.name.slashAttack();
};
if(battlechoice==4){
if(first.name.alreadylearned=false){
if(first.name.learnedimpFireBall=false){
System.out.println(first.name.learnimpMove());
System.out.println("You didn't learn the imp's move!");
}
else {
first.name.learnedimpFireBall = true;
first.name.alreadylearned = true;
}
}
if(first.name.alreadylearned=true){
System.out.println("You used the imp's move!");
second.name.hp= second.name.hp-first.name.LearnedimpFireBall();
System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
}
}
if(battlechoice==5){
second.name.hp = second.name.hp-first.name.useRanged();
first.name.hp = first.name.hp-second.name.slashAttack();
first.name.weapondamage=0;
}
}
if(second.name.hp<0)return true;
else return false;
}}
/*End Battle System*/
/*sdaiwchmweapon sword = new weapon();
weapon axe = new weapon();
weapon club = new weapon();*/
basepcnpc player = new basepcnpc(15,15,15,15,15,15,15,15,"player");
basepcnpc imp = new basepcnpc(3,1,5,2,1,1,210,210,"imp");
imp.hp=imp.maxhp;
System.out.println(imp.hp);
imp.weaponname = "Claw";
imp.weapondamage=0;
player.alreadylearned=false;
System.out.println(imp.hp);
/*for(;player.name.length()>2;){
player.name = JOptionPane.showInputDialog("What is your character's name?");
if(player.name.length()<=2)System.out.println("DO IT RIGHT");
}*/
// Character creation system.
for(int choicepoints=10;choicepoints>0;choicepoints--){
String Choices;
int choices;
try{
Choices = JOptionPane.showInputDialog("Choose what to put your attribute points into?"+
"\n 1. Strength : "+player.strength+
"\n 2. Dexterity : "+player.dexterity+
"\n 3. Agility : "+player.agility+
"\n 4. Intelligence : "+player.intelligence+
"\n 5. Wisdom : "+player.wisdom+
"\n 6. Charisma : "+player.charisma+
"\n Choose by number. You have "+choicepoints+" points left to put into attributes."+
"\n Just remember to put at least a few points into everything, or you may find your character...limited.");
choices = Integer.parseInt(Choices);
if(choices==1)player.strength++;
if(choices==2)player.dexterity++;
if(choices==3)player.agility++;
if(choices==4)player.intelligence++;
if(choices==5)player.wisdom++;
if(choices==6)player.charisma++;
}
catch(java.lang.NumberFormatException exc){
System.out.println("You must choose a number!");
choicepoints++;
}
}
player.weaponname = JOptionPane.showInputDialog("What kind of weapon do you use?\n 1. Sword \n 2. Club \n 3. Axe");
if(player.weaponname=="1"){
player.weaponname= "Sword";
player.weapondamage=20;
}
if(player.weaponname=="2"){
player.weaponname= "Club";
player.weapondamage=10;
}
if(player.weaponname=="3"){
player.weaponname = "Axe";
player.weapondamage=30;
}
player.hp=(player.strength*5)+20;
player.mp=(player.intelligence*5)+10;
player.maxhp=player.hp;
player.maxmp=player.mp;
System.out.println(player.name+"'s Character Sheet:");
System.out.println();
System.out.println("Health: "+player.hp);
System.out.println("Mana: "+player.mp);
System.out.println();
System.out.println("Strength: "+player.strength);
System.out.println("Dexterity: "+player.dexterity);
System.out.println("Agility: "+player.agility);
System.out.println("Intelligence: "+player.intelligence);
System.out.println("Wisdom: "+player.wisdom);
System.out.println("Charisma: "+player.charisma);
System.out.println("An imp spawns behind you!");
System.out.println("Player HP:"+player.hp+" "+imp.hp);
// slashAttack();useLightning();useHeal;learnimpMove;useRanged;
/*for(;player.hp>0&imp.hp>0;){
String Battlechoice = "3";
player.alreadylearned=false;
if(player.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
if(player.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
int battlechoice;
battlechoice = Integer.parseInt(Battlechoice);
if(battlechoice==1){
imp.hp = imp.hp - player.slashAttack();
System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
player.hp = player.hp-imp.slashAttack();
System.out.println("Player's HP: "+player.hp+"/"+player.maxhp);
}
if(battlechoice==2){
imp.hp = imp.hp - player.useLightning();
player.hp = player.hp-imp.slashAttack();
}
if(battlechoice==3){
player.hp = player.useHeal();
System.out.println("Player's Healed HP: "+player.hp);
player.hp = player.hp-imp.slashAttack();
};
if(battlechoice==4){
if(player.alreadylearned=false){
if(player.learnedimpFireBall=false){
System.out.println(player.learnimpMove());
System.out.println("You didn't learn the imp's move!");
}
else {
player.learnedimpFireBall = true;
player.alreadylearned = true;
}
}
if(player.alreadylearned=true){
System.out.println("You used the imp's move!");
imp.hp= imp.hp-player.LearnedimpFireBall();
System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
}
}
if(battlechoice==5){
imp.hp = imp.hp-player.useRanged();
player.hp = player.hp-imp.slashAttack();
player.weapondamage=0;
}*/
System.exit(0);
}
}<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->import javax.swing.*;
class basepcnpc {
int strength;
int dexterity;
int agility;
int intelligence;
int wisdom;
int charisma;
int maxhp;
int maxmp;
int hp=maxhp;
int mp=maxmp;
String name;
String weaponname;
int weapondamage;
boolean learnedimpFireBall;
boolean alreadylearned;
int slashAttack(){
int a = strength + (agility/2) + weapondamage;
return a;
}
int useLightning(){
int l = intelligence + (charisma/2);
mp=mp-20;
return l;
}
int useHeal(){
int h = wisdom + (charisma/2);
mp=mp-30;
int overheal = 0;
for(; overheal<=h||hp<=maxhp; overheal++){
hp = hp+1;
}
return overheal;
}
boolean learnimpMove() {
boolean learned;
if(charisma > 18){
System.out.println("You learned the imp's move!");
return true;
}
else return false;
}
int LearnedimpFireBall(){
int fb = 0;
if(learnedimpFireBall=true){
fb = charisma + (intelligence/2);
}
if(fb==0){
System.out.println("You didn't learn the imp's move yet!");
}
return fb;
}
int useRanged() {
int r = dexterity + (agility/2) + weapondamage;
return r;
}
int impFireBall(){
int f = intelligence + wisdom;
return f;
}
basepcnpc() {
}
basepcnpc(int s, int d, int a, int i, int w, int c, int h, int m, String n){
strength=s;
dexterity=d;
agility=a;
intelligence=i;
wisdom=w;
charisma=c;
maxhp=h;
maxmp=m;
hp=maxhp;
mp=maxmp;
name=n;
}
}
class weapon {
int strength;
int dexterity;
int agility;
int intelligence;
int wisdom;
int charisma;
int maxhp;
int maxmp;
int hp;
int mp;
int weapondamage;
String weaponattribute;
}
/*class pcnpc {
String combatant1 = "player";
int str, dex, agi, Int, wis, cha, xhp, xmp, chp, cmp;
int getStr() {
int a = str;
return a;
}
}*/
class rpg {
public static void main(String args[]) throws java.lang.NoSuchMethodError{
basepcnpc first = new basepcnpc();
basepcnpc second = new basepcnpc();
/*The Battle System*/
boolean battle(first.name,second.name.name){ {
for(;first.name.hp>0&second.name.hp>0;) {
String Battlechoice = "3";
first.name.alreadylearned=false;
if(first.name.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
if(first.name.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
int battlechoice;
battlechoice = Integer.parseInt(Battlechoice);
if(battlechoice==1){
second.name.hp = second.name.hp - first.slashAttack();
System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
first.name.hp = first.name.hp-second.name.slashAttack();
System.out.println("first.name's HP: "+first.name.hp+"/"+first.name.maxhp);
}
if(battlechoice==2){
second.name.hp = second.name.hp - first.name.useLightning();
first.name.hp = first.name.hp-second.name.slashAttack();
}
if(battlechoice==3){
first.name.hp = first.name.useHeal();
System.out.println("first.name's Healed HP: "+first.name.hp);
first.name.hp = first.name.hp-second.name.slashAttack();
};
if(battlechoice==4){
if(first.name.alreadylearned=false){
if(first.name.learnedimpFireBall=false){
System.out.println(first.name.learnimpMove());
System.out.println("You didn't learn the imp's move!");
}
else {
first.name.learnedimpFireBall = true;
first.name.alreadylearned = true;
}
}
if(first.name.alreadylearned=true){
System.out.println("You used the imp's move!");
second.name.hp= second.name.hp-first.name.LearnedimpFireBall();
System.out.println("imp's HP: "+second.name.hp+"/"+second.name.maxhp);
}
}
if(battlechoice==5){
second.name.hp = second.name.hp-first.name.useRanged();
first.name.hp = first.name.hp-second.name.slashAttack();
first.name.weapondamage=0;
}
}
if(second.name.hp<0)return true;
else return false;
}}
/*End Battle System*/
/*sdaiwchmweapon sword = new weapon();
weapon axe = new weapon();
weapon club = new weapon();*/
basepcnpc player = new basepcnpc(15,15,15,15,15,15,15,15,"player");
basepcnpc imp = new basepcnpc(3,1,5,2,1,1,210,210,"imp");
imp.hp=imp.maxhp;
System.out.println(imp.hp);
imp.weaponname = "Claw";
imp.weapondamage=0;
player.alreadylearned=false;
System.out.println(imp.hp);
/*for(;player.name.length()>2;){
player.name = JOptionPane.showInputDialog("What is your character's name?");
if(player.name.length()<=2)System.out.println("DO IT RIGHT");
}*/
// Character creation system.
for(int choicepoints=10;choicepoints>0;choicepoints--){
String Choices;
int choices;
try{
Choices = JOptionPane.showInputDialog("Choose what to put your attribute points into?"+
"\n 1. Strength : "+player.strength+
"\n 2. Dexterity : "+player.dexterity+
"\n 3. Agility : "+player.agility+
"\n 4. Intelligence : "+player.intelligence+
"\n 5. Wisdom : "+player.wisdom+
"\n 6. Charisma : "+player.charisma+
"\n Choose by number. You have "+choicepoints+" points left to put into attributes."+
"\n Just remember to put at least a few points into everything, or you may find your character...limited.");
choices = Integer.parseInt(Choices);
if(choices==1)player.strength++;
if(choices==2)player.dexterity++;
if(choices==3)player.agility++;
if(choices==4)player.intelligence++;
if(choices==5)player.wisdom++;
if(choices==6)player.charisma++;
}
catch(java.lang.NumberFormatException exc){
System.out.println("You must choose a number!");
choicepoints++;
}
}
player.weaponname = JOptionPane.showInputDialog("What kind of weapon do you use?\n 1. Sword \n 2. Club \n 3. Axe");
if(player.weaponname=="1"){
player.weaponname= "Sword";
player.weapondamage=20;
}
if(player.weaponname=="2"){
player.weaponname= "Club";
player.weapondamage=10;
}
if(player.weaponname=="3"){
player.weaponname = "Axe";
player.weapondamage=30;
}
player.hp=(player.strength*5)+20;
player.mp=(player.intelligence*5)+10;
player.maxhp=player.hp;
player.maxmp=player.mp;
System.out.println(player.name+"'s Character Sheet:");
System.out.println();
System.out.println("Health: "+player.hp);
System.out.println("Mana: "+player.mp);
System.out.println();
System.out.println("Strength: "+player.strength);
System.out.println("Dexterity: "+player.dexterity);
System.out.println("Agility: "+player.agility);
System.out.println("Intelligence: "+player.intelligence);
System.out.println("Wisdom: "+player.wisdom);
System.out.println("Charisma: "+player.charisma);
System.out.println("An imp spawns behind you!");
System.out.println("Player HP:"+player.hp+" "+imp.hp);
// slashAttack();useLightning();useHeal;learnimpMove;useRanged;
/*for(;player.hp>0&imp.hp>0;){
String Battlechoice = "3";
player.alreadylearned=false;
if(player.alreadylearned=false)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4. Learn \n5.Attack from Far");
if(player.alreadylearned=true)Battlechoice =JOptionPane.showInputDialog("The imp Spawned Behind you. What do you do?\n 1. Attack \n 2. Lightning \n 3. Heal\n 4.Use \n5. Attack from Far");
int battlechoice;
battlechoice = Integer.parseInt(Battlechoice);
if(battlechoice==1){
imp.hp = imp.hp - player.slashAttack();
System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
player.hp = player.hp-imp.slashAttack();
System.out.println("Player's HP: "+player.hp+"/"+player.maxhp);
}
if(battlechoice==2){
imp.hp = imp.hp - player.useLightning();
player.hp = player.hp-imp.slashAttack();
}
if(battlechoice==3){
player.hp = player.useHeal();
System.out.println("Player's Healed HP: "+player.hp);
player.hp = player.hp-imp.slashAttack();
};
if(battlechoice==4){
if(player.alreadylearned=false){
if(player.learnedimpFireBall=false){
System.out.println(player.learnimpMove());
System.out.println("You didn't learn the imp's move!");
}
else {
player.learnedimpFireBall = true;
player.alreadylearned = true;
}
}
if(player.alreadylearned=true){
System.out.println("You used the imp's move!");
imp.hp= imp.hp-player.LearnedimpFireBall();
System.out.println("imp's HP: "+imp.hp+"/"+imp.maxhp);
}
}
if(battlechoice==5){
imp.hp = imp.hp-player.useRanged();
player.hp = player.hp-imp.slashAttack();
player.weapondamage=0;
}*/
System.exit(0);
}
}<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
Comments
<!--emo&:(--><img src='http://www.unknownworlds.com/forums/html/emoticons/sad-fix.gif' border='0' style='vertical-align:middle' alt='sad-fix.gif' /><!--endemo-->
Also, why do you have
boolean battle()
{return false}
inside your main function? Are you trying to define a function, or are you trying to decalre a variable?
....
}</i> section. For example;
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->class rpg {
public boolean battle()
{return false;}
public static void main(String args[]) throws java.lang.NoSuchMethodError{
...
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
EDIT: oh, and the return false needed a semicolon. This sorts that particular problem...
SECOND EDIT: The code function takes out tabs. That's a major pain in the butt.
*swat*
*swat* <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
Grammar is for life, not just for Christmas.
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->rpg.java:125: ';' expected
boolean battle(first.name,second.name.name){ {<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
It motions for the semicolon to go after battle. Not battle(), but battle. As if I was just declaring it as a regular boolean: boolean battle;. Yeah. GAH.
Check back to the battle system area, I've updated the code.
When defining a method that takes parameters you declare the parameters' class and the variable names they will be recognized by in the method.
Ex: (battle takes two Character objects as parameters)
public boolean battle(Character person1, Character person2)
And then when you call battle you specify* the specific objects that it will take as parameters.
Ex: (battle is called with the Character objects johnny and susie as parameters)
battle(johnny, susie)
Then the method (function) will run its course, referring to johnny as person1 and susie as person2.
boolean battle(first.name,second.name.name){ {<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
It motions for the semicolon to go after battle. Not battle(), but battle. As if I was just declaring it as a regular boolean: boolean battle;. Yeah. GAH.
Check back to the battle system area, I've updated the code. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
I'm pretty sure its still the same problem that 0blique and Snidely mentioned. You cannot declare a method from within annother method (unless I've forgotten too much java). In this case, you cannot declare battle() inside of main(). Therefore the compiler thinks that you are trying to declare a plain old boolean scalar variable. The solution is still the same: move the battle() method declaration outside of main().
Edit: Also what TranquilChaos says. You seem to be confused between a method declaration and a method call.
heres the little java program ive been working on for the last two days, run the driver.class and enter text into the command window
<a href='ftp://guest:wordpass@yuo.ath.cx/Upload/Fractal.zip' target='_blank'>ftp://guest:wordpass@yuo.ath.cx/Upload/Fractal.zip</a>
Its not the second.name.name. That was me typing randomly.
I'm a very personal coder atm- plan to get more proffessional over time.
Thanks for your help, folks.