Personality Cafe banner

1 - 11 of 11 Posts

·
Registered
Joined
·
2,284 Posts
Discussion Starter #7
Mage, Warrior, and Theif classes added:



code:

import java.io.*;
public class game {
public static void main(String[] args) {
char ch;


System.out.println("Are you a (m)age,(w)arrior, or (t)heif?");

try{
if((ch = (char)System.in.read())== 'w')
System.out.println("You are a warrior.");

if(ch == 'm')
System.out.println("You are a mage.");

if(ch == 't')
System.out.println("You are a theif");

}

catch(FileNotFoundException e){
System.err.println(e);
}

catch(IOException e){
System.err.println(e);
}

}

}
 

·
Banned
Joined
·
5,472 Posts
Cool.
I might make an adventure game in javafx soon and show it to ya
When you get to graphics, still recommend learning fx over relearning swing/at, even if it means upgrading to Java 8 if you haven't already. Yes I know I know, 9s out, but I tend to wait a bit before trying out the new version
But yeah, Swing was supposed to replace AWT, except it's not thread safe.
 

·
Registered
Joined
·
4,823 Posts
Code:
import	java.io.*;
public class game {
    public static void main(String[] args) { 
		char ch;
  
		
        System.out.println("Are you a (m)age,(w)arrior, or (t)heif?"); 
		
		try{
		if((ch	=	(char)System.in.read())== 'w')	
		System.out.println("You are a warrior."); 
		
		if(ch == 'm')
		System.out.println("You are a mage."); 
		
		if(ch == 't')
		System.out.println("You are a theif"); 
		
			}
			
		catch(FileNotFoundException	e){
System.err.println(e);
									  }

	catch(IOException	e){
System.err.println(e);
}
	
											}

}
If you go to 'Advanced' mode when creating your post, you can wrap 'CODE' tags around the code to get the result above.

Is this going to be a text input based game?
 

·
Registered
Joined
·
2,284 Posts
Discussion Starter #10 (Edited)
Cool.
I might make an adventure game in javafx soon and show it to ya
When you get to graphics, still recommend learning fx over relearning swing/at, even if it means upgrading to Java 8 if you haven't already. Yes I know I know, 9s out, but I tend to wait a bit before trying out the new version
But yeah, Swing was supposed to replace AWT, except it's not thread safe.
I'm pretty confident this will remain text based. It's easier for others to follow/copy.


If you go to 'Advanced' mode when creating your post, you can wrap 'CODE' tags around the code to get the result above.

Is this going to be a text input based game?
Yes. Thanks a bunch.



New code. I added three separate simple text file profiles to my working directory, one per class . I updated the 'warrior' option so that it reads the warrior file and prints out the stats of the warrior class onto the screen. This information is placed in the text file. I need to do the same to the 'thief' and 'mage' classes.

Code:
import	java.io.*;
public class game {
    public static void main(String[] args) { 

		char ch;
  
	    System.out.println("Are you a (m)age,(w)arrior, or (t)heif?"); 
		try{
		if((ch	=	(char)System.in.read())== 'w')	
		{
		      System.out.println("\nYou are a warrior."); 
		
		       [I]//Place this into a method on a seperate file.[/I]
		       try (BufferedReader br = new BufferedReader(new FileReader("warrior.txt"))) {
                       String line = null;
                           while ((line = br.readLine()) != null) {
                           System.out.println(line);
                                                                                                                                                      }               
                                                                                    }
	          }
		
	
		
		if(ch == 'm')
		System.out.println("You are a mage."); 
		
		if(ch == 't')
		System.out.println("You are a theif"); 
		
			}
			
		catch(FileNotFoundException	e){
System.err.println(e);
							                   }

	catch(IOException	e){
System.err.println(e);
                                                    }
	
											}

                    }

Result when you choose the warrior class:

Code:
You are a warrior.
20
18
6
5


The four figures represent Attack, Defense, Steal, and Magicka, respectively.
 
1 - 11 of 11 Posts
Top