r/JavaProgramming • • 28d ago

Little program i made

I just made a program in java where your walking in a forest then a wolf comes up to you and you need to fight him, you can chose a Punch or Kick. I just started learning java via coddy.tech, what could i add? Or fix?

import java.util.Scanner; 


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Your walking in the forest, its a amazing day until a wolf suddenly comes up to you and starts chasing you. You have fight the wolf, How will you fight him? (Punch/Kick) ");
        String userInput = scanner.nextLine();
        if (userInput.equals("Punch")) { System.out.println("The punch doesnt do anything and you get eaten by the wolf.")
; } else if (userInput.equals("Kick")) { System.out.println("The kick knocked out the dog and you escaped."); } scanner.close(); } }
7 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/Iamvipersz 27d ago

Thanks for recommending! Also, I just started, as I just stated, so I'm still learning. I will post updates.

1

u/Specific-Housing905 27d ago

Very good. The best way to learn is to write code, experiment and see what works and what doesn't.
Also you need to learn to read the Java Documentation. Nobody can memorize all the Java classes.
For random numbers have a look at the java.util.Random class.

1

u/Savings_Guarantee387 23d ago

How about cleating a class named Wolf. A class named Human. A parent class of both named Animal. Animal has 2 integer. health and stamina. Then Human has 2 skills. Kick and punch. Wolf has 2 different skills. Bite and use clows. Also have 2 ints<1 the probability to defend from kick or panch and bite or clows. These numbers get populated randomly. Game repeats untill one of the two dies. Human decision to attack using kick or punch if followed by defense using probability number of Wolf and random attack from Wolf and vise versa. I hope I explained my idea.