Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2008, 10:51 PM
Member
 
Join Date: May 2008
Posts: 10
f_the_cook is on a distinguished road
help please
ok so i am having a problem with my while loop. it does let me go again it stop a a ceratin point. help would be appreciated.

import cs1.Keyboard;
public class combat
{


public static void main(String args[])
{


String again="yes";
String again2="yes";
String again3="yes";
String Equip;

int playerHP=30;
int playerItem=1;
int playerItem2=1;
int playerXP=0;
int level=1;
int atk=1;
int def=1;
int basicAttack=15;
int spiralAttack=20;
int omegaStrike=25;
int whirlWind=20;



while (again3.equalsIgnoreCase("yes"))
{
int enemyHP=30;
int enemyAttack=10;
int choice;
System.out.println("1.would you like to head north to duweldenvarden\n2.head east to murgenville\n3.head south to ruby island\n4.head west to city of the great");
choice=Keyboard.readInt();
switch(choice)
{
case 1:
System.out.println("As you are walking you are attacked by a goblin!\n");
break;
case 2:
System.out.println("you smell a foul smell in the air...its a wild boar!\n");
break;
case 3:
System.out.println("As you are walking you are attacked by a zombie!\n");
break;
case 4:
System.out.println("As you are walking you are attacked by a baby dragon!\n");
break;
}
while(again.equalsIgnoreCase("yes"))
{
System.out.println("1.fight\n2.item\n3.flee ");
choice=Keyboard.readInt();
switch(choice)
{


case 1:
System.out.println("1.basic attack\n2.spiral attack\n3.omega strike\n4.whrilwind");
choice=Keyboard.readInt();
switch(choice)
{
case 1:
if (choice==1)
{
enemyHP=enemyHP-basicAttack;
System.out.println("the enemy's health is "+enemyHP);
}
case 2:
if (choice==2)
{
enemyHP=enemyHP-spiralAttack;
System.out.println("the enemy's health is "+enemyHP);
}
case 3:
if (choice==3)
{
enemyHP=enemyHP-omegaStrike;
System.out.println("the enemy's health is "+enemyHP);
}
case 4:
if (choice==4)
{
enemyHP=enemyHP-whirlWind;
System.out.println("the enemy's health is "+enemyHP);
}
}
break;
case 2:
System.out.println("1.potion\n2.super potion");
choice=Keyboard.readInt();
switch(choice)
{
case 1:
if (choice==1)
{

if (playerItem<1)
{
System.out.println("you have no more potions!");
}
else
playerHP=playerHP+15;
playerItem=playerItem-1;
}
case 2:
if (choice==2)
{

if (playerItem2<1)
{
System.out.println("you have no more super potions!");
}
else
playerHP=playerHP+35;
playerItem2=playerItem2-1;
}
}
case 3:
if(choice==3)
{
System.out.println("You ran like a little girl! ");
}
break;

}


if (choice==1)
{
System.out.println("the enemy has attacked you! ");
playerHP=playerHP-enemyAttack;
System.out.println("your health is "+playerHP);
}
else if (choice==2)
{
System.out.println("the enemy has attacked you! ");
playerHP=playerHP-enemyAttack;
System.out.println("your health is "+playerHP);
}
else if (choice==3)
{
System.out.println("the enemy has attacked you! ");
playerHP=playerHP-enemyAttack;
System.out.println("your health is "+playerHP);
}
else if (choice==4)
{
System.out.println("the enemy has attacked you! ");
playerHP=playerHP-enemyAttack;
System.out.println("your health is "+playerHP);

}

if (enemyHP<=0)
{

System.out.println("You win! ");
playerXP=playerXP+100;

if (playerXP==100)
{
level=level+1;
System.out.println("you went up one level!!! you are now level "+level);
if (level>1)
{
atk=atk+1;
def=def+1;
playerHP=playerHP+15;
basicAttack=basicAttack+5;
spiralAttack=spiralAttack+5;
omegaStrike=omegaStrike+5;
whirlWind=whirlWind+5;
enemyAttack=enemyAttack--;
enemyHP=enemyHP+10;
}

}


Claymore weapon=new Claymore();

System.out.println("you get a sword with "+weapon.getClaymoreAtk());


System.out.println("would you like to equip the "+weapon.getClaymoreName()+"?");
Equip=Keyboard.readString();
if (Equip.equalsIgnoreCase("yes"))
{
atk=atk+weapon.getClaymoreAtk();
System.out.println("your atk is now "+atk);
basicAttack=basicAttack+10;
spiralAttack=spiralAttack+10;
omegaStrike=omegaStrike+10;
whirlWind=whirlWind+10;
}

}


System.out.print("Would you like to continue fighting or run yes/no : ");
again=Keyboard.readString();


if (again.equalsIgnoreCase("no"))
{
while(again2.equalsIgnoreCase("yes"))
{


System.out.println("welcome to the town! what would you like to do?\n1.go to the inn?\n2.go to the store\n3.leave");
choice=Keyboard.readInt();
switch(choice)
{
case 1:
playerHP=playerHP+playerHP;
System.out.println("you are fully healed");
break;
case 2:
System.out.println("Welcome to the store! what would you like?");

System.out.println("\n1.potion\n2.super potion\n3.weapons\n4.leave");
choice=Keyboard.readInt();
switch(choice)
{
case 1:
playerItem=playerItem+1;
case 2:
playerItem2=playerItem2+1;

case 3:
System.out.println("what weapon would you like to buy?");
System.out.println("\n1.claymore\n2.sword\n3.katan a");
choice=Keyboard.readInt();
switch(choice)
{

case 1:
Claymore weapon=new Claymore();
System.out.println("would you like to equip the "+weapon.getClaymoreName()+"?");
Equip=Keyboard.readString();
if (Equip.equalsIgnoreCase("yes"))
{
atk=atk+weapon.getClaymoreAtk();
System.out.println("your atk is now "+atk);
basicAttack=basicAttack+10;
spiralAttack=spiralAttack+10;
omegaStrike=omegaStrike+10;
whirlWind=whirlWind+10;

}
break;
case 2:

break;
case 3:
katana weapon3=new katana();
System.out.println("would you like to equip the "+weapon3.getKatanaName()+"?");
Equip=Keyboard.readString();
if (Equip.equalsIgnoreCase("yes"))
{
atk=atk+weapon3.getKatanaAtk();
System.out.println("your atk is now "+atk);
basicAttack=basicAttack+10;
spiralAttack=spiralAttack+10;
omegaStrike=omegaStrike+10;
whirlWind=whirlWind+10;

}
break;
}
}







}
System.out.println("is the anything else you would do today?");
again2=Keyboard.readString();
}


}





}
}
System.out.println("is the anything else you would do today?");
again3=Keyboard.readString();
}
}






thank you!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-06-2008, 04:31 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
i am having a problem with my while loop. it does let me go again it stop a a ceratin point.
what's wrong with your while loop?
What certain point are you talking about?

You may use a codetag when posting source codes.
You may just post the specific code where you suspect the cause, not the whole code....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-06-2008, 07:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Specifically describe your question.

Please use the code tags when you post again.

Keep your codes as much as shorter. Very long codes are reading is too boring.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-06-2008, 08:11 PM
Member
 
Join Date: May 2008
Posts: 10
f_the_cook is on a distinguished road
sorry about that the problem im having is that the while loop only runs once and then just stops.






Code:
import cs1.Keyboard; public class combat { public static void main(String args[]) { String again="yes"; String again2="yes"; String again3="yes"; String Equip; int playerHP=30; int playerItem=1; int playerItem2=1; int playerXP=0; int level=1; int atk=1; int def=1; int basicAttack=15; int spiralAttack=20; int omegaStrike=25; int whirlWind=20; while (again3.equalsIgnoreCase("yes")) { int enemyHP=30; int enemyAttack=10; int choice; System.out.println("1.would you like to head north to duweldenvarden\n2.head east to murgenville\n3.head south to ruby island\n4.head west to city of the great"); choice=Keyboard.readInt(); switch(choice) { case 1: System.out.println("As you are walking you are attacked by a goblin!\n"); break; case 2: System.out.println("you smell a foul smell in the air...its a wild boar!\n"); break; case 3: System.out.println("As you are walking you are attacked by a zombie!\n"); break; case 4: System.out.println("As you are walking you are attacked by a baby dragon!\n"); break; } while(again.equalsIgnoreCase("yes")) { System.out.println("1.fight\n2.item\n3.flee "); choice=Keyboard.readInt(); switch(choice) { case 1: System.out.println("1.basic attack\n2.spiral attack\n3.omega strike\n4.whrilwind"); choice=Keyboard.readInt(); switch(choice) { case 1: if (choice==1) { enemyHP=enemyHP-basicAttack; System.out.println("the enemy's health is "+enemyHP); } case 2: if (choice==2) { enemyHP=enemyHP-spiralAttack; System.out.println("the enemy's health is "+enemyHP); } case 3: if (choice==3) { enemyHP=enemyHP-omegaStrike; System.out.println("the enemy's health is "+enemyHP); } case 4: if (choice==4) { enemyHP=enemyHP-whirlWind; System.out.println("the enemy's health is "+enemyHP); } } break; case 2: System.out.println("1.potion\n2.super potion"); choice=Keyboard.readInt(); switch(choice) { case 1: if (choice==1) { if (playerItem<1) { System.out.println("you have no more potions!"); } else playerHP=playerHP+15; playerItem=playerItem-1; } case 2: if (choice==2) { if (playerItem2<1) { System.out.println("you have no more super potions!"); } else playerHP=playerHP+35; playerItem2=playerItem2-1; } } case 3: if(choice==3) { System.out.println("You ran like a little girl! "); } break; } if (choice==1) { System.out.println("the enemy has attacked you! "); playerHP=playerHP-enemyAttack; System.out.println("your health is "+playerHP); } else if (choice==2) { System.out.println("the enemy has attacked you! "); playerHP=playerHP-enemyAttack; System.out.println("your health is "+playerHP); } else if (choice==3) { System.out.println("the enemy has attacked you! "); playerHP=playerHP-enemyAttack; System.out.println("your health is "+playerHP); } else if (choice==4) { System.out.println("the enemy has attacked you! "); playerHP=playerHP-enemyAttack; System.out.println("your health is "+playerHP); } if (enemyHP<=0) { System.out.println("You win! "); playerXP=playerXP+100; if (playerXP==100) { level=level+1; System.out.println("you went up one level!!! you are now level "+level); if (level>1) { atk=atk+1; def=def+1; playerHP=playerHP+15; basicAttack=basicAttack+5; spiralAttack=spiralAttack+5; omegaStrike=omegaStrike+5; whirlWind=whirlWind+5; enemyAttack=enemyAttack--; enemyHP=enemyHP+10; } } Claymore weapon=new Claymore(); System.out.println("you get a sword with "+weapon.getClaymoreAtk()); System.out.println("would you like to equip the "+weapon.getClaymoreName()+"?"); Equip=Keyboard.readString(); if (Equip.equalsIgnoreCase("yes")) { atk=atk+weapon.getClaymoreAtk(); System.out.println("your atk is now "+atk); basicAttack=basicAttack+10; spiralAttack=spiralAttack+10; omegaStrike=omegaStrike+10; whirlWind=whirlWind+10; } } System.out.print("Would you like to continue fighting or run yes/no : "); again=Keyboard.readString(); if (again.equalsIgnoreCase("no")) { while(again2.equalsIgnoreCase("yes")) { System.out.println("welcome to the town! what would you like to do?\n1.go to the inn?\n2.go to the store\n3.leave"); choice=Keyboard.readInt(); switch(choice) { case 1: playerHP=playerHP+playerHP; System.out.println("you are fully healed"); break; case 2: System.out.println("Welcome to the store! what would you like?"); System.out.println("\n1.potion\n2.super potion\n3.weapons\n4.leave"); choice=Keyboard.readInt(); switch(choice) { case 1: playerItem=playerItem+1; case 2: playerItem2=playerItem2+1; case 3: System.out.println("what weapon would you like to buy?"); System.out.println("\n1.claymore\n2.sword\n3.katana"); choice=Keyboard.readInt(); switch(choice) { case 1: Claymore weapon=new Claymore(); System.out.println("would you like to equip the "+weapon.getClaymoreName()+"?"); Equip=Keyboard.readString(); if (Equip.equalsIgnoreCase("yes")) { atk=atk+weapon.getClaymoreAtk(); System.out.println("your atk is now "+atk); basicAttack=basicAttack+10; spiralAttack=spiralAttack+10; omegaStrike=omegaStrike+10; whirlWind=whirlWind+10; } break; case 2: break; case 3: katana weapon3=new katana(); System.out.println("would you like to equip the "+weapon3.getKatanaName()+"?"); Equip=Keyboard.readString(); if (Equip.equalsIgnoreCase("yes")) { atk=atk+weapon3.getKatanaAtk(); System.out.println("your atk is now "+atk); basicAttack=basicAttack+10; spiralAttack=spiralAttack+10; omegaStrike=omegaStrike+10; whirlWind=whirlWind+10; } break; } } } System.out.println("is the anything else you would do today?"); again2=Keyboard.readString(); } } } } System.out.println("is the anything else you would do today?"); again3=Keyboard.readString(); } }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-09-2008, 01:01 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Can you tell on which while loop you get the error. I don't have your imported package to run and test.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-10-2008, 04:08 AM
Member
 
Join Date: May 2008
Posts: 10
f_the_cook is on a distinguished road
its the first loop there.



thank you
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-10-2008, 05:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Why don't you use the scanner class there. Do you have to avoid it in your implementation?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-11-2008, 07:58 PM
Member
 
Join Date: May 2008
Posts: 10
f_the_cook is on a distinguished road
i honestly have no idea what that means. what is a scanner class?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-11-2008, 09:16 PM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
Read the API docs then, and see if there is a class ther called Scanner.

Edit: Though Scanner is not really meant to be used for user input, although many teachers these days are teaching it as such. It is easy to get user input using it, however, it does not gracefully handle "false" input.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-11-2008, 09:23 PM
Senior Member
 
Join Date: Jun 2008
Posts: 317
masijade is on a distinguished road
Also, you would be well served breaking down that "run-on" method into several smaller methods.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 06-12-2008, 04:45 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,543
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by f_the_cook View Post
i honestly have no idea what that means. what is a scanner class?

In simple words, scanner class used to read data in runtime.

Read the Java documentations for more details.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 10:24 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org