I have recently started to learn java and wanted skills to test my skills so far. I started making a small text-based game and have hit an early roadblock.
I have two classes so far, one for the menu system and the core processes, another for the character's stats and information.
While testing the two classes interacting, I was able to successfully print the stats, call it in an if by setting two variables equal (operation and stats).
The problem came when I wanted to use scanner to allow the user to type "stats" and show the stats. I have tried both if and while with the variables equal, so I know that the problem has something to do with scanner.
Here are the classes.
GameD01.java
import java.util.Scanner; public class GameD01 { public static void main(String args[]){ Scanner input = new Scanner(System.in); characterStats charStats = new characterStats(); String operation, stats = null; System.out.println("What would you like to see?"); operation = input.nextLine(); if(stats){ System.out.println("Your stats are: "); System.out.println("HP: "+ charStats.health); System.out.println("MP: "+ charStats.magic); System.out.println("Str: "+ charStats.strength); System.out.println("Def: "+ charStats.defense); operation = null; }else{ System.out.println("Please work..."); } } }
characterStats.java
public class characterStats { public int health, magic, strength, defense; { health = 100; magic = 20; strength = 50; defense = 50; } }