Fight For Arcadia (Text Based)

Hello JGO,

I’ve been learning Java (and programming in general) for the last few weeks. I started working on a little text-based game, to put the newly learned things to a use. Doing this, I managed to finish a little text-based Hack 'n Slay (if you can call it like that … ^^).

You can download the latest version here (You’ll need to run it from console/terminal via “java -jar FFA.jar”):

NEW (10/07/11) - V. 0.9
http://dl.dropbox.com/u/40409752/FightForArcadia.zip

Please feel free to crit & comment :wink:

Greetings,
EatenByAGrue

Cute game!

Events are randomised right?

Wish to get help with a simple GUI?

Thank you Skarion :slight_smile:

Yes the events are currently (pseudo)random. But I intend to change that, as it makes more sense that you can buy Items all the time. As I also try to create a (small) storyline the random events wouldn’t really work aswell I guess. But I still want to have the fight against randomized enemies… Basically every random decision in the game is decided by dice (similar to D&D and Warhammer I guess).


import java.util.Random;

public class Dice
{
	Random rnd = new Random();

	public int rollDice(int noOfDie, int sidesOfDie)
	{
		int total = 0;		// the total sum of all thrown dice
		int die;			// the number of one die
		int counter;		// keeps track of how many dice have been rolled
		
		if(sidesOfDie < 2){ 	// Assures that the die has at least two sides 
			sidesOfDie = 2;
		}
		if(noOfDie < 1){		// Assures that at least one die gets rolled
			sidesOfDie = 1;
		}
		
		for(counter = 0; counter < noOfDie; counter++)	{
			die = rnd.nextInt(sidesOfDie);					// generate random number between 1 and sidesOfDie
			total += die;									// 	 and add that number to the total
		}
		return total;
	}
}

Of course any help would be appreciated. I am reading about GUI at the moment, but I thought I’d rather learn more about the basics first before I start getting into GUIs. :slight_smile:

Greetings,
EatenByAGrue

I kind of like the text and the general feeling! :slight_smile:

Here is a very simple and quickly made GUI with comments on how to use it!

package test;

import java.awt.Dimension;
import javax.swing.*;

//By Skarion
public class ScWindow extends JFrame{

	private JPanel view;
	
	public ScWindow(int width, int height){
		setTitle("Fight for Arcadia");
		Dimension d = new Dimension(width, height);
		setSize(d);
		setPreferredSize(new Dimension(d));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	public void setContentPane(JPanel view){
		super.setContentPane(this.view = view);
		pack();
		setVisible(true);
	}
	
	public static void main(String[] args){
		//Example of how to use these classes.
		char newLine = 10;
		View v = new View();
		v.setTitle("Main menu");
		v.setText("FIGHT FOR ARCADIA (now in HD)"+newLine+"Copyright (c) 2011 Robert M."+newLine+"Version 0.8 - 15 Sep 2011");
		v.setEvents(new Event("New Game"), new Event("Load Game"),new Event("Help"),new Event("Exit"));
		ScWindow s = new ScWindow(300,400);
		s.setContentPane(v);
	}
}

package test;

import java.awt.*;
import java.util.HashMap;
import javax.swing.*;
//By Skarion

public class View extends JPanel{

	private JLabel title;
	private JTextArea text;
	private JPanel south;
	private static int MAXEVENTS=6;
	
	public View(){
		super(new BorderLayout());
		title = new JLabel();
		title.setFont(new Font("Verdana",Font.PLAIN,20));
		text = new JTextArea();
		text.setEditable(false);
		text.setBackground(null);
		south = new JPanel(new GridLayout(MAXEVENTS,1));
		Dimension d = new Dimension(200,30*MAXEVENTS);
		south.setSize(d);
		south.setPreferredSize(d);
		add(title, BorderLayout.NORTH);
		add(text, BorderLayout.CENTER);
		add(south, BorderLayout.SOUTH);
	}
	
	public void setTitle(String s){
		title.setText(s);
	}
	public void setText(String s){
		text.setText(s);
	}
	public void setEvents(Event... events){
		south.removeAll();
		if(events.length>MAXEVENTS){
			System.out.println("You need to declare a larger MAXEVENTS to do this, else it will get ugly!");
		}
		for(int i = 0;i<events.length;i++){
			events[i].setSelected(i);
			JButton event = new JButton(events[i].getText());
			event.addMouseListener(events[i]);
			south.add(event);
		}
		updateUI();
	}
	
}

package test;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
//By Skarion
public class Event extends MouseAdapter{

	private int value;
	private String text;
	//private Model model;
	
	public Event(String text /*, Model model*/){
		//Send in the model here for usage.
		//this.model = model;
		this.text = text;
	}
	
	public String getText(){
		return text;
	}
	
	public void setSelected(int value){
		this.value = value;
	}
	
	public void mousePressed(MouseEvent e){
		//Tell model to activate this event.
		//model.eventFired(value);
	}
}

If there is anything you wonder or would like to know, post and I can see if I can fix it.

Thank you very much I’ll look into that. At the moment I’m still struggling with the basics of OOP. I’ll try to make the game work first before I try to create a GUI :slight_smile:

Greetings.

If you wonder anything, just ask.

The code above should easily be used with the code you got (at least the way I think you’ve programmed your game. Thought that said code would be a nice way to get a simple GUI up and running so you don’t get lost while doing the rest of your game. :slight_smile:

There is a game similar to the DOS era, there was a DOS-horror game, play it like watching horror fiction. Although only text, but very attractive.

Yes indeed. There are many games like this (but all way more complicated than mine :)) for example Zork, or ‘Hitchhiker’s Guide through the Galaxy’ (which you can play here: http://www.douglasadams.com/creations/infocomjava.html) by Infocom. I really like them I don’t know why. Especially the humor in the Infocom games was really entertaining.


Update 10/07/11 - Version 0.9:

I finally managed to update the game. It took me longer than expected because I had so many other things to do :confused:
Anyways, I shortened the feedback during fight, included items … etc. but mainly I improved my code :slight_smile:

I think it’s a bit harder than before because I changed some of the enemies but I’m gonna fix that soon.

Please feel free to crit,
Greetings