Text Adventure Game

Jul 19, 2012

I'm creating a text adventure game, but there are some bugs in it that can get annoying such as restarting the program when it shouldn't be, going to the wrong piece of text, etc.

Java Code:

import java.util.Scanner;
public class Act_1 {
/**
* @param args
*/
public static void main(String[] args) {
boolean again = true;
do{
int option;
Scanner input = new Scanner(System.in);

System.out.println("You are Paul Soares Jr, an expert survivalist who has been caught in the midst of a zombie apocalypse in the land of MineZ. You awaken in a dense forest with a lake nearby. In your backpack you have a wooden sword, a pack of matches, one torch, some snacks and meals, a H.A.M. radio, a full water bottle, and a bandage.");

System.out.println("");//the "" adds a space in the text
System.out.println("Do you: ");
System.out.println("");
System.out.println("<1> Head inland");
System.out.println("<2> Stick close to the water");
option = input.nextInt();

[code]...

View Replies


ADVERTISEMENT

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

Text Adventure - Cannot Use Menu Selection

Apr 30, 2015

I cannot use menu selection 4 5 6 7 8 9 10 ... Why NO_EXIT has been declared and used in defining the contents of the map array, rather than just directly using the value 99999 in the map array definition

I don't understand map[][], objectName[] and objectLocation[]

package Assignment;
import java.util.Scanner;
public class GameWorld
{
// the map array holds details on which paths lead to which other rooms. NO_EXIT indicates no valid exit.
// each element holds the details of all paths leading out from a single-room in the order n ,e, s, w, ne, se, sw, nw
private final int NO_EXIT = 99999; // indicates that there is no exit in that direction
private int map[][] ={{NO_EXIT,NO_EXIT,NO_EXIT,1},{2,0,NO_EXIT,NO_EXIT},{NO_EXIT,3,1,NO_EXIT},{NO_EXIT,NO_EXIT,NO_EXIT,2}};

[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

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

Text From The Class Game Doesn't Update

May 3, 2014

I have a main class that hold the frame and paints, a class for drawing my game, and an image that is drawn too.
I want to count the amount of times I click on this "android" (right now it counts if i click the screen) but the text from the class Game doesn't update.

androidX = Main.width - android.getWidth();

doesn't work. In my head the image should be inside the borders but it isn't. Have I calculated the pixels wrong or am I missing something?

public class Main extends JPanel{
public static final int width = 600;
public static final int height = 600;
Game game = new Game();
Android android = new Android();
public void paint(Graphics g) {
super.paint(g);
game.render(g);
android.render(g);

[code]....

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

Creating Simple Text Editor - Delete Selected Text Inside Text Area

May 13, 2015

This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....

Here is the code..

package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Guessing Game - How To Reset Random Number When User Reset Game

Oct 2, 2014

I tried this program, its guessing game. Where program decide 1 number and user will guess number. I am getting 1 problem. When user want to play game again.the random number remain same. So where i can put reset random in code..? And 1 more question if I want to write driver code for this. What should i transfer to driver code.

import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main(String args[])
{
String choice="y";

[Code] ......

View Replies View Related

Replace String Text With Foreign Characters - JTextArea Output Plain Text

May 21, 2014

The problem is i want to replace some string text with foreign characters, but JTextArea returns plainText.

For Example:

str = new String();
str.replace('e', 'é');
textArea.setText(str);

but textArea returns plainText.

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Swing/AWT/SWT :: JTextField - How To Remove Text When User Clicks On Text Field

Jan 28, 2014

I have a textField in which I have text in. The text is enter customer name. I would like for this text to disappear whenever the user clicks on the textField to enter a customer name. I am using the automated swing gui builder in NetBeans. Is their some sort of feature for this under properties of the text field? If not then what are my other options?

View Replies View Related

Read Line Of Text And Output Text First In All Uppercase And Then In Lowercase Letters

May 29, 2014

Write a program that reads in a line of text and then outputs that line of text first in all uppercase letters and then in all lowercase letters.

INPUT and PROMPTS. The program prompts for a line of text as follows: "Enter the text: " and then reads in an entire line of text as a String .

OUTPUT . There are four lines of output . The first line is "The text in all upper case is: ". The second line is the line that was read in, displayed in all uppercase. The third line is "The text in all lower case is: " and the fourth line is the original line that was read in, displayed in all lowercase.

CLASS NAMES. Your program class should be called ShoutAndWhisper.

This is what I have so far:

import java.util.Scanner;
public class ShoutAndWhisper
{
public static void main(String[] args)
{
Scanner scannerObject = new Scanner (System.in);
System.out.println("Enter the text: ");
scannerObject.next();
System.out.println("The text in all upper case is: ");

View Replies View Related

Java Servlet :: How To Send Text Output To A Browser As Text Is Generated

Jan 27, 2013

I'm using JBoss 7.1.1.Final. I'm writing a Spring 3.1.1.RELEASE web application and have a massive amount (~5MB) of text output to send to the browser. I would like the browser to display the output as it is generated, but right now, the browser only displays everything after the servlet's doGet method completes. Here's my method …

    @RequestMapping(value = "/mymethod", method = RequestMethod.GET)
    public void refreshOrders(final HttpServletResponse response) throws IOException
    {
        execute(response, myWorker);
    }
    private void execute(final HttpServletResponse response,

[Code] ....

I set my buffer size to be 1K but that doesn't do anything.

View Replies View Related

Read Chars In Text Area And Produce Desired Output For Text Editor Project?

Nov 27, 2014

I am working on a personal project and want to create a text editor to write my code. I am wondering how could I read the last input from the user and if say it was an open curly brace {, then like netbean's my editor will supply the closing curly brace. My java experience is limited but I have tried to read key board input and a few other options that did not work.

View Replies View Related

Swing/AWT/SWT :: Reading From HTMLEditorKit Doesn't Display Text While In Text / HTML Content Type?

Apr 24, 2015

I'm working on a simple text editor, and I'm currently saving the contents of my JTextPane in a file using an HTMLEditorKit (text is a JTextPane):

private void save() throws IOException {
int returnVal = fc.showSaveDialog(window);
if (returnVal == JFileChooser.APPROVE_OPTION) {
StyledDocument doc = (StyledDocument)text.getDocument();
HTMLEditorKit kit = new HTMLEditorKit();
BufferedOutputStream out;

[Code] ....

The problem I'm having is that after opening a file that I saved, it does not display (if I disable text/html, it displays the entire html code, but when I re-enable it, nothing displays at all.) Am I loading it wrong, or am I setting the JTextPane's text incorrectly? Or is it, perhaps, another error that I didn't catch?

View Replies View Related

Clicking On TextField Will Show Some Required Text Under Text Field

Mar 15, 2015

I am trying to run a simple program in which on clicking on the TextField will show some required text under the Text Field .Here is my code:
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 class Awt
{
public static void main(String...s)

[Code] ....

I am expecting the on clicking anywhere inside the text field should show me the Text : "Mouse Clicked" . But i am getting this error:

Awt.java:77: error: cannot find symbol
tf.f.setText("Mouse Clicked");}
^
symbol: variable f
location: variable tf of type Awt
1 error

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

Swing/AWT/SWT :: How To Bold The Text In A Text Area

Oct 13, 2014

I am building a chat server/client and would like to have it so when a user sends a message, the message pops up in the main chat area beside their name, which I would like to be in bold font. Something like "Alan: Hello, how are you?". I can't find a way to do this with a text area or on a string. Do any swing components suitable for use as text areas support bolding of certain sections of the string that you will set to it?

View Replies View Related







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