Text Based RPG Game - Working With Multiple ArrayLists

Feb 22, 2014

I have come across an issue with arraylists. I am writing a text based RPG game as something to start with ...

Initially I had a single zone which was all stored in an arraylist and everything was working in regards to the player moving around. The problem I now have is how to add further zones to my game. Ideally I would like an arraylist for each zone, and would use the below to create each arraylist

public static ArrayList<RoomsClass> castleMap = new ArrayList<>();

The problem I now have is how to handle the player moving, initially with a single zone/arraylist I could reference that arraylist directly

public void findRoomCoords(int ID) {
for (int i = 0; i < castleMap.size(); i++) {
if (castleMap.get(i).roomID.equals(ID)) {
PLAYER.setCurrentRoomZone(castleMap.get(i).roomZone);
PLAYER.setCurrentRoomX(castleMap.get(i).roomX);
PLAYER.setCurrentRoomY(castleMap.get(i).roomY);
PLAYER.setCurrentRoomZ(castleMap.get(i).roomZ);
}
}
}

My initial thought was to use a getter/setter to remove the reference of castleMap from my movement code in order to access different arraylists, however this is where things have fallen over, I can't seem to work out how to get the arraylist name to change, depending on the outcome of the setZoneMap() method.

public void setZoneMap() {
switch (PLAYER.getCurrentRoomZone()) {
case 0: {
zoneMap = Castle.castleMap;
break;

[Code] ....

View Replies


ADVERTISEMENT

How To Do Movement In Text Based Game

Feb 13, 2015

I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"

View Replies View Related

Text Based Game With A Window

Jun 4, 2014

I started a text based game, but I am dissatisfied with the console that PrintF prints to. How can I set up a window and have text output to that window, and have my player type responses in the window?

View Replies View Related

Text-based Game Map Creation

Oct 25, 2014

So, I've been working on creating a text-based game engine that would create games similar to Achaea. It's been working pretty well so far. I just finished creating a great mapping system, but now I've run into a problem. I have a mapping system, but actually creating a map would prove to be quite a lot of work. Each location that the player can be inside of has a name, description, map symbol, and an array of the things inside of it. How can I make some sort of map creation program or something so that I can create my maps more easily?

I thought perhaps making a constructor that accepts a list of files, the first containing a table of strings for the names, the second containing a table of strings for the descriptions, etc.; but it seems that would be quite tedious and may be more complex than actually just hard-programming maps.

View Replies View Related

Text Based Game Adding Items

Apr 11, 2014

I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns :

java.lang.NullPointerException
at Room.addItem(Room.java:107)
at Game.createRooms(Game.java:133)
at Game.<init>(Game.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

[Code] .....

Here are the classes that matter for this particular situation

import java.util.HashMap;
public class Item
{
private HashMap<String, Item> itemList;
private String name;
private String itemDescription;

[Code] ....

I know that it is the line

itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));

In the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly....

View Replies View Related

How To Implement Basic Text-based Rpg Game In A Website

Jan 13, 2015

I started programming some time ago and i recently finished a game i've been programming in Java just to get used to the code. The game is a simple text-based RPG where almost everything is random except the character movement.

I've been thinking about learning HTML and CSS because i'm really interested in building webpages. I have no one to ask this question so here i am.

Is there a way to implement my game in a webpage?

I imagine a black window exactly like a classic OS terminal where the text is streamed and the user can play the game with keyboard inputs. I made the game with 5 different classes, i used Eclipse and i have my project there. Should i use a service like Github to share works like this one?

View Replies View Related

Making A Window For Java Text Based Game

Jan 10, 2015

So, Iv'e been trying to make a simple Text Based RPG with Java, and it is going quite well, and my friends want to play it too but they aren't very tech savvy, so it's hard to tell them to get an IDE or use the CMD, so I wanted to know if there was a way to make my text-based game into a window, like using JFrame or something. All i need is a window that displays the text, and a bar on the bottom that lets the user input what they want (Kind of like a CMD).

I want it sort of like this window: This Pic

View Replies View Related

Drawing A Graph Based On Stock Values From 2 ArrayLists?

Apr 19, 2015

[URL] I made a program that takes 2 stock values by URL tickers, and now I need it to draw a graph with the values for the 2 stocks, so they can be compared visually. So far my idea was to create 2 arraylists that consist of the values for each stock, so that I can draw the graph so that x always move with 1 step, and y0 is the first coordinate, and y1 is the second, and after that y1 is the first, y2 second etc.

View Replies View Related

Tic Tac Toe Game Based On GUI

Apr 26, 2014

My instructor told me to make game from java but based on GUI. And I thought about it, I want to make Tic Tac Toe (X-O) game.

View Replies View Related

JRE :: Deploying Working Ruleset For Use With Intranet Based Applications?

Mar 10, 2015

I question this as I have not yet succeeded in deploying a working ruleset for use with intranet based applications. I have verified the ruleset is working with external internet java apps so it is being deployed correctly just doesn't steer Intranet based apps to the correct version.

View Replies View Related

Tiled Based Map Game In Java

May 10, 2014

I'm trying to create a tile based map JPanel but all I get is a white screen. I'm fairly new to the Java Swing and AWT package so I've been watching tutorials on YouTube so learn as much as I can.

I've got three classes: Window.java which includes the Main method, Panel.java which is the JPanel and Tile.java to draw all the images into an array.

Window.java:

import javax.swing.JFrame;
public class Window extends JFrame {
public Window() {
setTitle("Project");
setSize(500, 400);

[Code] .....

I've checked through everything and still cannot find what I'm doing wrong. I did try different codes but I just got errors instead.

View Replies View Related

Creating Tiled Based Map Game In Java?

May 10, 2014

I'm trying to create a tile based map JPanel but all I get is a white screen. I'm fairly new to the Java Swing and AWT package so I've been watching tutorials on YouTube so learn as much as I can. I don't know where I'm going wrong.

I've got three classes: Window.java which includes the Main method, Panel.java which is the JPanel and Tile.java to draw all the images into an array.

Window.java:

import javax.swing.JFrame;
public class Window extends JFrame {
public Window() {
setTitle("Project");
setSize(500, 400);
setLocationRelativeTo(null);

[Code] ....

Panel.java:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
public class Panel extends JPanel implements Runnable {
private Image dbImage;

[code]....

I've checked through everything and still cannot find what I'm doing wrong. I did try different codes but I just got errors instead.

View Replies View Related

Multiple Key Inputs Not Working

Sep 16, 2014

i am currently making a game in java and currently i am working on the basic mechanics. most of it is working fine but i cannot seem to make it so when the user presses and movment key and space to fire a bullet the bullet fires in the direction they are moving. here is the code i have for movement.

public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
int bulletx = Player.x + 100;
int bullety = Player.y + 20;
int key = e.getKeyCode();
if( key == e.VK_W){
p.moveUp();
}
if(key == e.VK_S){
p.moveDown();

[code]....

View Replies View Related

Multiple JPanels - Paint Not Working

Jun 17, 2014

nothing is painted.Here's the code for the Main class:

Java Code: import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Random;

[code]....

View Replies View Related

Building A Small Text Based RPG

Dec 18, 2014

i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.

Java Code:

import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Player playerObject = new Player();

[code]....

My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?

I tried like 'int Mongoloid = 1; int Caucasian = 2;'

And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.

View Replies View Related

Text Based RPG - Allow User To Change Their Name

Sep 26, 2014

String name = "Aaron";
String whatToChange = "name";
String verifyNameChange = "";
boolean changeName = false;

if(whatToChange.equals("name")){
while(!changeName){

[Code] ....

I've been working on a small text-based RPG for fun. This particular part is supposed to allow the user to change their name. Now, the problem is that when they reach the option to change their name, the above code seems to skip the line:

name = scan.nextLine();

It will erase whatever the player previously entered for their name, as well. So it will print out:

Okay, let's change your name. What did you say it was? Alright, so you'll go by . Is that correct? [now allows input for verifyNameChange]

The above code works fine on it's own, but somehow messes up when put into the full program. I don't want to post the whole program, because it's fairly large. But the String name is set and functions fine before this bit of code.

View Replies View Related

Key Presses In Game Not Working

Jan 25, 2014

I finished a game. It works perfectly fine on my computer. Sent it to a friend. On his computer, for some reason, one of the keys that are used to play doesn't work inside the game. (It works in any other context, like a web browser).

He tried pushing this key with no other keys held. Still didn't work. So it's not a 'key combination' issue. We both use Windows and the most updated JRE version.

The key that doesn't work on his computer, is: ; (semicolon)

View Replies View Related

Complicated ArrayList Function - Moving Between Fields Which A Player Can Perform Based On Game Rules

May 27, 2014

I have been working on this function and i can't get it to work. It's a little bit complicated so let me first explain what this is about:

1. As a little exam in my studies i have to program a halma console game with KI an stuff.

2. Everything is finished and works except for the Move-Calculation.

3. A Move is a Move from Field a to Field b which a player can perform in one round based on the game rules (Careful: We are not using the standard halma rules, we use different ones).

4. Class Move consists of the Starting Cell where the Figure before the Move stands and a target Cell where the figure will stay on at the Move end. It may include an Array of serveral Cells, the stop cells which the figure passes from start -> target since several jumps can be performed in one Move.

Valid Examples for Moves:

a -> b (From Field a to Field b)
d -> f through g,h,i (From Field d to Field f through the Field g,h,i

My Move Calculation where all possible Moves are calculated for a given figure consists of 2 parts. An expand() function which will generate all possible moves (works perfectly) and a jumpFix() function which isn't working properly.

Example:

After expand() I'm getting something like that:

a -> b
b -> c
c -> d
s -> t

This is however not finished, because the first 3 Moves are actually 1 Move. Because the player can Move from a -> d in one turn because those 3 are consecutive Move. The fixed Move would look like that:

a -> d through b,c

jumpFix() is also perfectly working for that situation, however there is one specific situation when it doesn't work. Let's say we have this situation.

a -> b
b -> c
c -> d
b -> e
e -> f
f -> g
s -> t

Then the only valid jumpFix() output would be:

a -> d through b,c
a -> g through b,e,f
s -> t

However i can not get it to work yet. Note: It definitely needs to be iterative, not rekursive else i would get an StackoverflowError.

This is my current Code of jumpFix():

Java Code:

/**
* Takes a look into all calculated moves and finds those which should be seen as one move, but are still considered to be more than one move (several jumps in one move)
*/

public static List<Move> jumpFix(List<Move> moves) {
Set<Move> result = new HashSet<Move>();
Set<Move> remove = new HashSet<Move>();
int lastSize = -1;
// repeat action until no moves could be merged
while (lastSize != remove.size()) {

[Code] ....

How to implement the special case where a Move splits into 2 or more branches and jumpFix() able to handle this case.

View Replies View Related

Servlets :: Populate Text Fields Based On Dropdown

Nov 20, 2014

I have list of employees in my database and their associated information like employeeId,supervisor and process. I have class named EmployeeDetails having same properties. I am fetching details of all users using below code:

<%EmployeeDetails employeeList;
employeeList=(List<EmployeeDetails>)assetmain2.getEmployeeList(loginName);%>
<table>
<tr>
<td>
Requested For <select name="requestedForName" id="requestedForNameID">
<option selected="selected">--Select--</option>
<%int i=0;

[Code] .....

In employeeList, we have list of objects having data of employees. I donot know how to get which object is selected in dropdown and based on that rest of the text fields are populated. Example:

Name ID Supervisor
-------------------------------------------------------
Pawan Kumar3033045Vimal Kumar
Vimal Kumar3040901Dinesh Hemrajani

If Pawan Kumar is selected from dropdown then '3033045' and 'Vimal Kumar' should get populated.

View Replies View Related

Java Game KeyListener Not Working In FSEM

Sep 5, 2014

I had a game written in a 500x400 window using JFrame and a threaded JPanel. It used KeyListener to detect user input and worked just fine, problem was it was very click dependent and therefore I wanted to put it into fullscreen mode so I would no longer come across the problem of clicking outside the window and being taken out of the game. But when I ported the game to Full Screen Exclusive Mode the KeyListener no longer seems to be working and I have no clue why. I tried using KeyBindings as well, that code didn't work and is left commented out in the FSEM code.Here is my code for the windowed application:

import java.awt.Container;
import javax.swing.*;
public class Main extends JFrame{
private GamePanel panel;
public Main(){
panel = new GamePanel();

[code]....

View Replies View Related

Triangle Evaluation Based On Data Found In Text File

Mar 24, 2015

For an assignment I need to read an input text file and evaluate the triangle based on the data found in the text file which consists of an unknown number of groups of 3 numbers (Each group representing a different triangle). According to the project specifications I need to have a main method and several other methods. I have the main method set-up to receive data correctly but I am confused as to how I would get the values out of the text file and use them in the main method. For example, if I were to call the computePerimeter method in my main method, how would I make sure I get the correct perimeter for the given data?

Here is the code I have so far:

import java.io.*;
import java.util.Scanner;
public class TriangleEvaluator
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(new File("triangleData.txt"));
double s1;
double s2;
double s3;
while (in.hasNextDouble())

[Code] ....

View Replies View Related

Using Multiple Arrays To Play A Roulette Game

Mar 20, 2015

I am creating a roulette program that I converted from C++ to Java. Why its not finding the main class. Therefore it will not compile. Heres the code:

import java.util.Scanner;
public class P1RouletteDB
{
// This program demonstrates the use use multiple arrays to play a roulette game.
//Also a random number will generated to be used as the ball in the game. The user will be provided the random number to test the win algorithms
// Program Set 2 Roulette Game

// Global constants
public static final int COLS = 3; // Number of columns in each array

[Code] ....

View Replies View Related

Servlets :: Shopping Cart - Show Text Based On Which Page A User Is Coming From

May 30, 2014

I am making a shopping cart app in JSP and servlets to bring it all together. Finally.

I have a registration servlet (c1), a registration form jsp (c2), a login jsp (c3). c1 checks if a username is in the database or not.

If the username is not there, then register the user and send them to c3. I want c3 to display a "registration successful" message if a user has just registered successfully and is coming from c1. ELSE, take the user back to c2 with a message which tells them to choose a different username or password etc.

How do I implement the logic of showing a message depending on where a user is coming from ? The servlets and jsps are ready and I only need to add this logic for a custom message. Of course, I could make a JSP for Registration Successful and one for Registration Failure. But, that seems to be unnecessary.

View Replies View Related

Multi-Player Game With Multiple Worlds - Unhandled Packets

Sep 16, 2014

So I am trying to create a Multi-Player game in java, and I have a Game server and a Client. They normally connect with either but I would like to add a login server so that there can be an option to go to a different world then just the main one. It will have the same map and data but will be separate from the Players that are on world one per say. Now if you are on world two I would like it to have the option for you to be able to Private message players that are on World one. That is where the login server comes in to play.

I am still new at Java and would like to be able to understand Packets and how to handle them more clearly. So far I have gotten the basis of the login server connected to the server and the client connects to the server via the login server. But I am getting a bunch of "unhandled packets" and I would like to know how to handle them. Here are some bits of the code.

package com.ls.net;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

[Code] ....

So when I run my client this pops up in the console:

[Tue Sep 16 16:50:56 EDT 2014][LoginServer]: Finished initializing login server.
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 15
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 41
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 74

[Code] ....

And here are the class's for Accounts:

package com.ls.net.codec.decoder.packets;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.ChannelHandlerContext;
import com.ls.bufutils.BufferUtils;
import com.ls.net.codec.decoder.PacketDecoder;
import com.ls.net.codec.decoder.handlers.AccountHandler;

[Code] ....

View Replies View Related

Reading Input From Text File Not Working?

Apr 7, 2014

public void savePlants(ArrayList flowerPack) throws IOException
{
Scanner input = new Scanner(System.in);
String name;

[Code].....

When I open the saved file the information I need seems to be saved, but when I try to load and search it the data is not there. This is homework that was due about 2 days ago. I just want to get it right in my head for next time.

This is my text file: ¬í sr java.util.ArrayListxÒ™Ça I sizexp w sr FlowerNÏŠ¨r;¾  Z hasScentZ hasThornsL flowerColort Ljava/lang/String;xr Plant"ô²Ò0¢ I IDL Nameq ~ xp t Roset redsr Fungus“ +) Z isPoisonousL fungusColorq ~ xq ~  t toadstool t brownsr Weed #©éÇÙN Z isEdibleZ isMedicinalZ isPoisonousL weedColorq ~ xq ~  t dandylion t yellowsq ~  t tulip t pinkxq ~ q ~ q ~ 

View Replies View Related

Multiple Colors For A Text Field

May 25, 2014

I have a question about JTextArea colors. When i set the color to blue and then write something on the JTextArea (JTextArea.append) and then set it back to black everything will be black. How can i solve that? Like in Notepad++ or Eclipse when you write keywords in a JTextArea (where you write your code) only some words change color.

This is my code:

// All the imports
public class whatever extends JFrame {
JTextArea a = new JTextArea();
public whatever() {
super("Title");
add(a);

[code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved