Hello all!
Okay, so I guess it's pretty obvious from the title that I started programming in Java after I learned a bit of C++. I swapped because I basically found out that the fun little game project I was working on could never be run from a web page in a million years and no one on the internet trusts downloadable .exe files.
Live and learn I guess.
So anyway I've been trying to re-write the text adventure I was working on to teach myself C++, salvaging code here and there where I can, but I've run into some major snags.
The first snag I ran into was that unlike in C++, where for a user to modify a variable you just need to do a little "cin <<" statement, in java you have to start off with a statement of "import java.util.Scanner;" before your class declaration to import that from a library of commands in the IDE (presumably), assign memory for the object in the main method like so:
Scanner sc = new Scanner(System.in);
(I really wish I knew what I was doing when I typed that)
Then for the player to actually modify something, after I declare the variable, I need to type:
String name = sc.nextLine();
(I also really wish I knew what I was doing when I typed that)
So I've basically figured out that detail, but it's just something I bumped into that wasn't very well explained rather than an object that I'm really familiar with.
My second problem is that I'm trying to figure out how to tie those user modified variables to variables within a method so that I can make my status screen, here's a simplified version of that:
public class Chapter1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter your character's name: "); String name = sc.nextLine(); int raceChoice = 0; System.out.println("Choose your race: "); raceChoice = sc.nextInt(); int playerHealth = 1; int roomTracker = 1; } public void breatheDeep(int raceChoice, int playerHealth, int roomTracker, String name) { System.out.print("You take a deep breath, close your eyes and look inward. You have a\nbrief moment of deep awareness. \n\n HEALTH: "); System.out.print(playerHealth); System.out.print("NAME: " + name+ " \n\n"); if (raceChoice == 1) { System.out.print("..................~()~()./|.....\n" +"..................(~0000/ /............\n" +"..............(~0/ _ \\............\n" +".............(~0/ Q \\__.....\n" +"............(~0/ _D\\........\n" +"...........(~0/ ___/.........\n" +"..........(~0/ \\__/...................\n" +"____________/ /.........................\n" +" |..........................\n" +" |...........................\n" +" |..........................\n " +" |..........................\n" +" |.........................\n" +" \\.......................\n" +" \\.......................\n" +"________| |_____ \\.......................\n" +"........| |......\\ \\......................\n" +"........| |.......\\ \\ .........................\n"); } else if (raceChoice == 2) { System.out.print("..................~()~()......\n" +"..................(~000000............\n" +"..............(~0/ _ \\............\n" +".............(~0/ Q \\__.....\n" +"............(~0/ _D\\........\n" +"...........(~0/ ___/.........\n" +"..........(~0/ \\__/...................\n" +"____________/ /.........................\n" +"|||||||||>> |..........................\n" +"|||||||||>> |...........................\n" +"|||||||||> |..........................\n" +"||||||||| |..........................\n" +"||||||||| |.........................\n" +"||||||||| \\.......................\n" +"||||||||| \\.......................\n" +"||||||||| |_____ \\.......................\n" +"--------| |......\\ \\......................\n" +"........| |.......\\ \\ .........................\n"); } else if (raceChoice == 3) { System.out.print("..................~()~()......\n" +"..................(~000000............\n" +"..............(~0/ _ \\............\n" +".............(~0/ Q \\__.....\n" +"............(~0/ _D\\........\n" +"...........(~0/ ___/.........\n" +"..........(~0/ \\__/...................\n" +"____________/ /.........................\n" +" |..........................\n" +" |...........................\n" +" |..........................\n" +" |..........................\n" +" |.........................\n" +" \\.......................\n" +" \\.......................\n" +" | |_____ \\.......................\n" +"--------| |......\\ \\......................\n" +"........| |.......\\ \\ .........................\n"); } //I'll need to fix the ascii art above, it's a great idea, but I have to figure out how to get the spacing right and make the \ character show up. if (roomTracker == 1) { System.out.print("CLINIC\n"); System.out.print("00000000_____000000000000000000000000000000000\n"); System.out.print("0 DOOR U()U | 0\n"); System.out.print("0 WASH BASIN | 0\n"); System.out.print("0 |CABINET 0\n"); System.out.print("0 | 0\n"); System.out.print("0 ----------0\n"); System.out.print("0 0\n"); System.out.print("0 0\n"); System.out.print("0 0\n"); System.out.print("0 0\n"); System.out.print("0------- -------- 0\n"); System.out.print("0 | | | |\n"); System.out.print("0 YOUR | (MARE) | | DOOR|\n"); System.out.print("0 COT | | COT | |\n"); System.out.print("0 | | | 0\n"); System.out.print("0 | | | 0\n"); System.out.print("0000000000000000000000000000000000000000000000\n"); System.out.print("You are in some sort of clinic. It is tidy and neat, but doesn't\nappear to have much in the way of medical supplies. Everything is worn\ndown, but obvious efforts have been made to maintain what little is\nthere. A mare in an orange vest resides here, looking watchful. There\nis also a heavy metal cabinet tucked away in a corner. It has a very\nsturdy chain lock.\n\n"); } } }
See in C++ I could just use pointers to tie how the variables were modified by the user input to "universal variables" that are read as the same value no matter where they are referred to in the code, but that doesn't appear to be the case in java (I also don't know how to call that method easily, but that's another story).
I've been trying to teach myself how to program in java using the Sun tutorials here: The Java™ Tutorials
But honestly they are deeply confusing and don't follow a very logical order so it's been difficult for me to figure out answers to fundamental questions like this. I've gone to a huge pile of sites trying to get straight answers, but they're all really difficult to sort through.
I know these are all really silly newbie questions, but I'm really, truly lost at this point. Can any of you intelligent and experienced programmers help me out? I would be deeply grateful for any experience you could provide.