Personality Cafe banner

1 - 11 of 11 Posts

·
Registered
Joined
·
2,577 Posts
Discussion Starter #1
Truth is, I've forgotten my Java. No worries tho, we'll learn it together. This is my journey to create a fun, small, modifiable Role Playing Game(RPG) in Java.
 

·
Registered
Joined
·
2,577 Posts
Discussion Starter #2
Linux Ubuntu 14.04.5 LTS
Editor and Compiler: Geany
And I'm using OpenJDK 7
 

·
Registered
Joined
·
2,577 Posts
Discussion Starter #3
Let's start with a hello world program:

openjdk-7-jdk

public class helloworld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}

 

·
Registered
Joined
·
2,577 Posts
Discussion Starter #4
To install the Java environment: sudo apt-get install -y openjdk-7-jdk

To compile on the console: javac hellowold.java


 

·
Registered
Joined
·
2,577 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);
}

}

}
 

·
Registered
Peter Petrelli
Joined
·
6,159 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.
 
  • Like
Reactions: SgtPepper

·
Registered
INTP
Joined
·
5,111 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,577 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.
 

·
Registered
Peter Petrelli
Joined
·
6,159 Posts
I'm pretty confident this will remain text based. It's easier for others to follow/copy.
Good idea. Will be following, because I think I forgot some of my command line based Java.
 
  • Like
Reactions: SgtPepper
1 - 11 of 11 Posts
Top