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


ADVERTISEMENT

Adding Items To The Game

Jan 4, 2015

I made my items class and I am storing my item as a String array to list them all and what I want to be able to do is type pickup, have the game read my location and display the items that are avaible to pickup at current location then type the item and store it in my playerInventory. Then, have it check the slot if it is doesn't equal null go to next.

Use a boolean value of 0 = false and 1 = true. then, have it check if the inv array = 1 or 0. if 1 go to next inv. If all are full then, ask player if they would like to replace an item. Use a 2d array for storage for slots and true or false value.

Here is my code

Player.java
package com.PenguinGaming;
import java.util.Random;
import java.util.Scanner;
public class Player {
public void User(){
Commands commands = new Commands();
Map map = new Map();

[Code] .....

View Replies View Related

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

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

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 View Related

Java Text Adventure Game - Adding Characters

Apr 14, 2014

I am making a java text adventure and i am trying to add characters to it. I wrote it exactly the same as i wrote the items class (which works fine) but for some reason the character class keeps getting a null pointer exception when it gets to line 140 in the room class

characters.add(c);
game class
import java.util.ArrayList;
import java.util.HashMap;
/**
* Game class for Free Willy Five: an exciting text based adventure game.
*

[Code] ....

View Replies View Related

JavaFX 2.0 :: Sizing Width Of ComboBox Based On Items

Apr 16, 2015

I have a ComboBox -- just a simple ComboBox with string items.
 
My string items aren't very long (5 letters max), but the ComboBox shows quite wide relative to my strings. So I would like to size my ComboBox to the size of my strings.
 
I messed around with setting the CellFactory of the ComboBox, and have the Cells produced by the CellFactory set the preferred width of the cells to some constant like 100. That worked in terms of changing the size of the ComboBox to the preferred width of 100.
 
But what I really want to do is to compute the preferred width from the string items. For that I need to be able to compute how wide a string item will be when rendered. And I guess that depends on the font size used by the ComboBox to render strings, which probably depends on the platform (OS X different to Windows?).

View Replies View Related

Adding Array Of Items To Linked List

Sep 21, 2014

I'm having trouble completing my homework. The problem:

>Suppose that you want an operation for the ADT list that adds an array of items to the end of the list. The header of the method could be as follows:
public void addAll(T[] items)

>Write an implementation of this method for the class LinearLinkedList

At first this seemed like an easy problem to me. This is the solution I came up with:

public void addAll(T[] items) {
int length = items.length;
for(int i = 0 ; i < length; i++){
this.addLast(items[index]);
}
}

However, one of the requirements for the assignment is that we're not allowed to use the addLast method. how else to insert items to the Linked List without this method. These are the user-defined LinearLinkedList and ListNode classes we made during class:

**LinearLinkedList**
// Linear linked list class
import java.util.NoSuchElementException;
public class LinearLinkedList {

[code]....

View Replies View Related

ArrayList Only Adding 1 Item When There Are Multiple Items

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");
method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
if(files.hasReadData) {

[Code] ....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Adding Items To JComboBox Taken From JTextField Listener

Nov 11, 2014

I need to take the value of what's typed in my JTextField, and once the submit button is clicked, I want to add that string to my JComboBox list items.

Depending which RadioButton they selected, I need to put the team in HOME or AWAY teams, and so on and so on, until they continue clicking submit.

View Replies View Related

Swing/AWT/SWT :: Java GUI With Separate Class For JList - Adding Items To The List?

Sep 19, 2014

I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.

Here is my code:

//Main class
public class TestProject {
public static void main(String[] args) {
GUI mainWindow = new GUI();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[Code] ....

When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.

View Replies View Related

ArrayList Only Adding 1 Item Even Though There Are Multiple Items (Setting Data To Files)

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");

method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);

[code]....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[code]....

View Replies View Related

How To Get Past Loading In Items From Text File

Oct 2, 2014

I am not sure why I am getting this error. The code is not finished at all, but I am stumped on how to get past loading in the things from the text file. Here is my code:

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Hurricanes2
{
public static void main(String[] args)throws IOException
{
//declare and initialize variables
 
[code]...

It compiles fine, but when I execute it I get this.

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

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

Boolean Method - Adding Information To Mailing List Based On User Input

May 5, 2014

This program contains a superclass and a subclass that will gather the following information from the user:

name, address, phone number, and customer number.

Everything works fine except that I have to create a boolean method in this program that is required to determine based on user input whether they want to be added to a mailing list.

I cannot get this method to work with main, each time it is called it will always return the value but main will constantly read the last statement (else, where it will read "not wanting to be added to the mailing list).

The only way I can get this part of the program to work is by adding an equals method in main that ignores the case, but I am required to write a boolean method so this is not allowed.

Superclass:

public class Person
{
private String name;
private String address;
private String phoneNum;
public Person(String pName, String add, String number)
{
name = pName;
address = add;

[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

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

Tic Tac Toe - Adding Draw System / Game Over

Jul 31, 2014

I have been trying to add a draw system to my code so far once all the boxes have been taken it does not tell the player its a draw game over. I have tried and deleted some code but I have commented some stuff that did'nt work at the bottom and also the X's and O's can be replaced in the same spaces?

import java.util.*;
//import for scanner
public class NoughtsAndCrosses {
public static int row,col; //integer for rows and columns
public static Scanner scan = new Scanner(System.in); //Scans the program
public static char[][] board = new char [4][4]; //Characters for the board set out 4/4

[Code] .....

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

Adding A Tick Rate To Game To Unlock FPS?

Nov 25, 2014

I need to add a tick rate so i can unlock the FPS. Here's the main render class/update class/game loop class.

Added back the formatting

Java Code:

package com.educodes.Main;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;

[Code] ....

View Replies View Related







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