Results 1 to 11 of 11

Thread: help please

  1. #1
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default 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!

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    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....
    freedom exists in the world of ideas

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  4. #4
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    sorry about that the problem im having is that the while loop only runs once and then just stops.






    Java 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();
    	}
    }

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you tell on which while loop you get the error. I don't have your imported package to run and test.

  6. #6
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    its the first loop there.



    thank you

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    f_the_cook's Avatar
    f_the_cook is offline Member
    Join Date
    May 2008
    Posts
    21
    Rep Power
    0

    Default

    i honestly have no idea what that means. what is a scanner class?

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Also, you would be well served breaking down that "run-on" method into several smaller methods.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •