jeudi 18 mars 2021

If statement within if statement is not running

So i am trying to make a text based rpg game and what is supposed to happen here is when you activate a hunt by typing hunt it asks you yes or no. However even when i input yes, the you killed the boar message does not pop up. I am fairly new to java so sorry if the code is bad.

//Branches
            if (ins.equals("branches") && loc.equals("forest")) {
                System.out.println("You got a branch");
                ib++;
            } else if (ins.equals("branches") && !"forest".equals(loc)) {
                System.out.println("You need to be in the forest to cut branches");
            } else if (ins.equals("bcount")) {
                System.out.println(ib);
            }
            //Branches


            //Stones
            if (ins.equals("stones") && loc.equals("mountains")) {
                System.out.println("You got a stone");
                is++;
            } else if (ins.equals("stones") && !"mountains".equals(loc)) {
                System.out.println("You need to be in the mountains to gather stones");
            } else if (ins.equals("scount")) {
                System.out.println(is);
            }
            //Stones


            //Spears
            if (ins.equals("spear") && is >= 1 && ib >= 1) {
                System.out.println("+1 spear");
                is--;
                ib--;
                ispear++;
            } else if (ins.equals("spear") && is < 1) {
                System.out.println("Insufficient resources");
            } else if (ins.equals("spear") && ib < 1) {
                System.out.println("Insufficient resources");
            } else if (ins.equals("spearcount")) {
                System.out.println(ispear);
            }
            //Spears


            //Hunt
            if (ins.equals("hunt") && ispear >= 1) {

                System.out.println("A wild boar comes charging at you! Throw spear? (yes or no)");
                


                if (ins.equals("yes")) {

                    System.out.println("You killed the boar!");

                }


            } else if (ins.equals("hunt") && ispear < 1) {

                System.out.println("You dont have any spears");

            }

        }

Aucun commentaire:

Enregistrer un commentaire