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


ADVERTISEMENT

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

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

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

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

JSP :: How To Display Only Text File In Selection Window

Apr 7, 2014

I am trying to upload the text file in specific location in my disk but when I open selection window it displays all type of files while it should display the files only having .txt extensions

I am writing the code below,

<%@page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<%
// JSP to handle uploading
// Create a new file upload handler

[code]....

View Replies View Related

Why Text-fields And Labels Not Appearing On Dialog Window

Apr 27, 2015

I'm not understanding why the Jtextfield and Jlabel are not appearing on the dialog window.

public class CreateQuote extends JDialog {
private final JPanel contentPane = new JPanel();
private JLabel interestRate;
private JLabel numberofYears;
private JButton tupac;

[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

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

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

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

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

JavaFX 2.0 :: Manipulating Several Windows (Window Inside Window)

Apr 6, 2015

I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.

I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.

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

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

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







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