mardi 29 octobre 2019

Are my if statements messing up with my menu?

I created a fishing game with a menu.A user simply enters a letter to do that option.However when I try to access the code under the corresponding if statement, for some reasons it either skips it or displays high score stats. I tried changing the letters to see if that was the issue that didn't work. Maybe its the way im comparing the user input string (im using .equals) or maybe its a bigger issue I don't see. In short my if statements arnt working as a menu and some if statements such as my r to 'ready up' for fishing dosnt do anything. Or my u to 'purchase upgrades' for the fishing rod.

//Intense Fishing Simulator 2019
//2019-10-29
//Ormim Bari
//to practice the usage of realtionships.
package com.mycompany.intensefishingsimulator2019_ormimbari;

 import java.io.*;

public class DriverClass 
{
    public static void main (String args[]) throws IOException
    {
        BufferedReader MyInput=new BufferedReader (new InputStreamReader(System.in));

        Fisher joe = new Fisher(); //creates the fisher

        System.out.println("Welcome to Intesne Fishing Simulator 2019");
        System.out.println("You join fisher Joe's in the intense world of Fishing");
        int money=0;
        int endGame=0;
        boolean purchase1=false;//if purchased firsst upgrade
        boolean purchase2=false;//if purchased last upgrade
        do
        {
            //menu
            System.out.println("Enter r when ready to catch a fish");
            System.out.println("Enter c to see total of cash earned");
            System.out.println("Enter f to see total amount of fish caught");
            System.out.println("Enter u to upgrade your fishing rod");
            System.out.println("Enter joe to see stats");
            System.out.println("Enter Exit to end game ");

            String strInput=MyInput.readLine(); //gathers ihnput

            //ends game
            if (strInput.equals("Exit"))
            {
                endGame=999;
            }
            //display hp and fishing rod damage
            if (strInput.equals("joe"))
            {
                strInput="";
                System.out.println("Joe has a total hp of " +joe.getHp());
                System.out.println("Joes fishingrod does a total of "+joe.fr.getDamage() +" damage");

            }
            //display career total of fish caught
            if (strInput.equals("f"));
            {
                strInput="";
                System.out.println("You caught a total of"+joe.GetCatches()+"fishes");

            }
            //display career total of cash earned
            if (strInput.equals("c"));
            {
                strInput="";
                System.out.println( "You earned a total of $"+joe.getCashTotal());

            }
            if (strInput.equals("u"))
            {

                if (purchase1==false)
                {
                    System.out.println("Welcome to the shop! The first upgrade is $30. To buy enter b");
                    strInput=MyInput.readLine();
                    if (strInput.equals("b"))
                    {
                        strInput="";
                       boolean sucess= joe.fr.Upgrade1(money, joe, joe.fr);
                       if (sucess==true)
                       {
                           purchase1=true;
                       }
                    }
                }
                if (purchase1==true)
                {
                    System.out.println("Welcome to the shop! The last upgrade is $50. To buy enter b");
                    strInput=MyInput.readLine();
                    if (strInput.equals("b"))
                    {
                        strInput="";
                       boolean sucess= joe.fr.Upgrade2(money, joe, joe.fr);
                       if (sucess==true)
                       {
                           purchase2=true;
                       }
                    }
                }
                if (purchase2==true)
                {
                    System.out.println("You purchased all the upgrades");
                }
            }
            //user chooses to 'ready up' to fish
            if (strInput.equals("r"))
            {
                strInput="";
                int endFishing=0;

                //creation of fish to fight
                Fish fish= new Fish();

                //ceratopm of all fish 
                TunaFish tf= new TunaFish(); 
                SilverCarp sc= new SilverCarp();    
                Shark shark= new Shark();

                //intro
                System.out.println("You have been approached by a " + fish.getType());
                do
                {
                    //instructions
                    System.out.println("Enter a to attack the fish or r to run away");
                    strInput=MyInput.readLine(); 
                    //if chosing to run away
                    if (strInput.equals("r"))
                    {
                        strInput="";
                        boolean sucess;
                        sucess=joe.RunAway();
                        //if sucesfull
                        if (sucess==true)
                        {
                            joe.RunAwaySucess(joe);
                            endFishing=999;
                        }
                        //if joe failed to runaway
                        if (sucess==false)
                        {
                            //if tuna
                            if (fish.getType().equals("Tuna Fish"))
                            {   

                                boolean damageGiven= tf.AttackChanceTuna();
                                //if tuna dosnt miss
                                if (damageGiven==true)
                                {
                                    //joe gets the damage 
                                    joe.HarmJoe(tf.returnTunaDamage());
                                    System.out.println("Joe has been harmed by the tuna for "+ tf.returnTunaDamage());
                                    System.out.println("Joe now has" + joe.getHp());

                                    //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999; //ends game
                                    }
                                }
                            }

                            //if carp
                            if (fish.getType().equals("Silver Carp"))
                            {
                                boolean damageGiven= sc.AttackChanceCarp();
                                //if carp dosnt miss
                                if (damageGiven==true)
                                {
                                    //harms joe
                                    joe.HarmJoe(sc.returnCarpDamage());
                                    System.out.println("Joe has been harmed by the silver carp for "+ sc.returnCarpDamage());
                                    System.out.println("Joe now has" + joe.getHp());
                                }
                                //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999; //ends game
                                    }
                            }
                            //if shark
                            if (fish.getType().equals("Shark"))
                            {
                                boolean damageGiven= shark.AttackChanceShark();
                                //if shark dosnt miss
                                if (damageGiven==true)
                                {
                                    //harms joe
                                    joe.HarmJoe(shark.returnSharkDamage());
                                    System.out.println("Joe has been harmed by the silver carp for "+ shark.returnSharkDamage());
                                    System.out.println("Joe now has" + joe.getHp());


                                }
                                //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999; //ends game
                                    }
                            }

                        }

                    }
                    //if attacking
                    if (strInput.equals("a"))
                    {
                        strInput="";
                        //tells user it did attack
                        fish.HarmFish(joe.fr.getDamage());
                        System.out.println("Joe has hurt " + fish.getType()+ "for "+ joe.fr.getDamage()+"damage");

                         //if tuna
                            if (fish.getType().equals("Tuna Fish"))
                            {
                                //damage the tuna
                                tf.harmTuna(joe.fr.getDamage());

                                boolean damageGiven= tf.AttackChanceTuna();
                                //if tuna attacks
                                if (damageGiven==true)
                                {
                                    //joe gets the damage if true
                                    joe.HarmJoe(tf.returnTunaDamage());
                                    System.out.println("Joe has been harmed by the tuna for "+ tf.returnTunaDamage());
                                    System.out.println("Joe now has" + joe.getHp());

                                    //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999;
                                    }
                                    //if tuna dies
                                    if (tf.getTunaHp()<=0)
                                    {
                                        //reward screen output
                                        System.out.println("You beat the tuna!You got " + tf.fl.getLootType());
                                        System.out.println("You sold the " + tf.fl.getLootType()+ "for $" + tf.fl.getLootPrice());
                                        joe.increaseCash(tf.fl.getLootPrice());
                                        System.out.println("You now have $" + joe.getMoney()); //cash update
                                        tf.healTuna();//reset for next potential round
                                        joe.CareerCashTotal(tf.fl.getLootPrice()); //add to highscore
                                        joe.addCatches(); // add to high score
                                        endFishing=999; //stops the fishing
                                    }
                                }
                            }

                            //if carp
                            if (fish.getType().equals("Silver Carp"))
                            {
                                //damages the tuna
                                sc.harmCarp(joe.fr.getDamage());
                                boolean damageGiven= sc.AttackChanceCarp();
                                //if tuna dosnt miss
                                if (damageGiven==true)
                                {
                                    //harms joe
                                    joe.HarmJoe(sc.returnCarpDamage());
                                    System.out.println("Joe has been harmed by the silver carp for "+ sc.returnCarpDamage());
                                    System.out.println("Joe now has" + joe.getHp());
                                }
                                //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999;
                                    }
                                    if (sc.getCarpHp()<=0)
                                    {
                                         //reward screen output
                                        System.out.println("You beat the silver carp!You got " + sc.fl.getLootType());
                                        System.out.println("You sold the " + sc.fl.getLootType()+ "for $" + sc.fl.getLootPrice());
                                        joe.increaseCash(sc.fl.getLootPrice());
                                        System.out.println("You now have $" + joe.getMoney()); //upgrade cash
                                        sc.healCarp();//reset for next potential round
                                        joe.CareerCashTotal(sc.fl.getLootPrice()); //add to high score
                                        joe.addCatches(); //add to high score
                                        endFishing=999; //stops the fishing
                                    }
                            }
                            //if shark
                            if (fish.getType().equals("Shark"))
                            { 
                                //harms the shark
                                shark.harmShark(joe.fr.getDamage());
                                boolean damageGiven= shark.AttackChanceShark();
                                //if shark dosnt miss
                                if (damageGiven==true)
                                {
                                    //harms joe
                                    joe.HarmJoe(shark.returnSharkDamage());
                                    System.out.println("Joe has been harmed by the silver carp for "+ shark.returnSharkDamage());
                                    System.out.println("Joe now has" + joe.getHp());


                                }
                                //if joe dies
                                    if (joe.getHp()<=0)
                                    {
                                        joe.EndGame(joe);
                                        endGame=999;
                                    }
                                //if shark dies
                                if (shark.getSharkHp()<=0)
                                    {
                                        //reward screen output
                                        System.out.println("You beat the Shark!You got " + shark.fl.getLootType());
                                        System.out.println("You sold the " + shark.fl.getLootType()+ "for $" + shark.fl.getLootPrice());
                                        joe.increaseCash(shark.fl.getLootPrice());
                                        System.out.println("You now have $" + joe.getMoney()); //updatees cash
                                        shark.healShark();//reset for next potential round
                                        joe.CareerCashTotal(shark.fl.getLootPrice()); //adds to high score
                                        joe.addCatches(); //adds to high score
                                        endFishing=999;
                                    }
                            }

                        }

                } while (endFishing!=999);
            }



        }while (endGame!=999);

        System.out.println("Thanks for joining Joe in the world of Intense Fishing ");


    }



}

Aucun commentaire:

Enregistrer un commentaire