Small adventure game
- by Nick Rosencrantz
I'm making a small adventure game where the player can walk through Dungeons and meet scary characters:
The whole thing is 20 java classes and I'm making this a standalone frame while it could very well be an applet I don't want to make another applet since I might want to recode this in C/C++ if the game or game engine turns out a success. The engine is the most interesting part of the game, it controls players and computer-controlled characters such as Zombies, Reptile Warriors, Trolls, Necromancers, and other Persons. These persons can sleep or walk around in the game and also pick up and move things. I didn't add many things so I suppose that is the next thing to do is to add things that can get used now that I already added many different types of walking persons.
What do you think I should add and do with things in the game?
The things I have so far is:
package adventure;
/**
* The data type for things. Subclasses will be create that takes part of the story
*/
public class Thing {
/**
* The name of the Thing.
*/
public String name;
/**
* @param name The name of the Thing.
*/
Thing( String name ) {
this.name = name;
}
}
public class Scroll extends Thing
{
Scroll (String name)
{
super(name);
}
}
class Key extends Thing
{
Key (String name)
{
super(name);
}
}
The key is the way to win the game if you figure our that you should give it to a certain person and the scroll can protect you from necromancers and trolls. If I make this game more Dungeons and Dragons-inspired, do you think will be any good? Any other ideas that you think I could use here?
The Threadwhich steps time forward and wakes up persons is called simulation. Do you think I could do something more advanced with this class?
package adventure;
class Simulation extends Thread
{
private PriorityQueue Eventqueue;
Simulation()
{
Eventqueue = new PriorityQueue();
start();
}
public void wakeMeAfter(Wakeable SleepingObject, double time)
{
Eventqueue.enqueue(SleepingObject, System.currentTimeMillis()+time);
}
public void run()
{
while(true)
{
try
{
sleep(5); //Sov i en halv sekund
if (Eventqueue.getFirstTime() <= System.currentTimeMillis())
{
((Wakeable)Eventqueue.getFirst()).wakeup();
Eventqueue.dequeue();
}
}
catch (InterruptedException e )
{
}
}
}
}
And here is the class that makes up the actual world:
package adventure;
import java.awt.*;
import java.net.URL;
/**
* Subklass to World that builds up the Dungeon World.
*/
public class DungeonWorld extends World {
/**
*
* @param a Reference to adventure game.
*
*/
public DungeonWorld(Adventure a) {
super ( a );
// Create all places
createPlace( "Himlen" );
createPlace( "Stairs3" );
createPlace( "IPLab" );
createPlace( "Dungeon3" );
createPlace( "Stairs5" );
createPlace( "C2M2" );
createPlace( "SANS" );
createPlace( "Macsal" );
createPlace( "Stairs4" );
createPlace( "Dungeon2" );
createPlace( "Datorsalen" );
createPlace( "Dungeon");//, "Ljushallen.gif" );
createPlace( "Cola-automaten", "ColaAutomat.gif" );
createPlace( "Stairs2" );
createPlace( "Fable1" );
createPlace( "Dungeon1" );
createPlace( "Kulverten" );
// Create all connections between places
connect( "Stairs3", "Stairs5", "Down", "Up" );
connect( "Dungeon3", "SANS", "Down", "Up" );
connect( "Dungeon3", "IPLab", "West", "East" );
connect( "IPLab", "Stairs3", "West", "East" );
connect( "Stairs5", "Stairs4", "Down", "Up" );
connect( "Macsal", "Stairs5", "South", "Norr" );
connect( "C2M2", "Stairs5", "West", "East" );
connect( "SANS", "C2M2", "West", "East" );
connect( "Stairs4", "Dungeon", "Down", "Up" );
connect( "Datorsalen", "Stairs4", "South", "Noth" );
connect( "Dungeon2", "Stairs4", "West", "East" );
connect( "Dungeon", "Stairs2", "Down", "Up" );
connect( "Dungeon", "Cola-automaten", "South", "North" );
connect( "Stairs2", "Kulverten", "Down", "Up" );
connect( "Stairs2", "Fable1", "East", "West" );
connect( "Fable1", "Dungeon1", "South", "North" );
// Add things
// --- Add new things here ---
getPlace("Cola-automaten").addThing(new CocaCola("Ljummen cola"));
getPlace("Cola-automaten").addThing(new CocaCola("Avslagen Cola"));
getPlace("Cola-automaten").addThing(new CocaCola("Iskall Cola"));
getPlace("Cola-automaten").addThing(new CocaCola("Cola Light"));
getPlace("Cola-automaten").addThing(new CocaCola("Cuba Cola"));
getPlace("Stairs4").addThing(new Scroll("Scroll"));
getPlace("Dungeon3").addThing(new Key("Key"));
Simulation sim = new Simulation();
// Load images to be used as appearance-parameter for persons
Image studAppearance = owner.loadPicture( "Person.gif" );
Image asseAppearance = owner.loadPicture( "Asse.gif" );
Image trollAppearance = owner.loadPicture( "Loke.gif" );
Image necromancerAppearance = owner.loadPicture( "Necromancer.gif" );
Image skeletonAppearance = owner.loadPicture( "Reptilewarrior.gif" );
Image reptileAppearance = owner.loadPicture( "Skeleton.gif" );
Image zombieAppearance = owner.loadPicture( "Zombie.gif" );
// --- Add new persons here ---
new WalkingPerson(sim, this, "Peter", studAppearance);
new WalkingPerson(sim, this, "Zombie", zombieAppearance );
new WalkingPerson(sim, this, "Zombie", zombieAppearance );
new WalkingPerson(sim, this, "Skeleton", skeletonAppearance );
new WalkingPerson(sim, this, "John", studAppearance );
new WalkingPerson(sim, this, "Skeleton", skeletonAppearance );
new WalkingPerson(sim, this, "Skeleton", skeletonAppearance );
new WalkingPerson(sim, this, "Skeleton", skeletonAppearance );
new WalkingPerson(sim, this, "Sean", studAppearance );
new WalkingPerson(sim, this, "Reptile", reptileAppearance );
new LabAssistant(sim, this, "Kate", asseAppearance);
new LabAssistant(sim, this, "Jenna", asseAppearance);
new Troll(sim, this, "Troll", trollAppearance);
new Necromancer(sim, this, "Necromancer", necromancerAppearance);
}
/**
*
* The place where persons are placed by default
*
*@return The default place.
*
*/
public Place defaultPlace() {
return getPlace( "Datorsalen" );
}
private void connect( String p1, String p2, String door1, String door2) {
Place place1 = getPlace( p1 );
Place place2 = getPlace( p2 );
place1.addExit( door1, place2 );
place2.addExit( door2, place1 );
}
}
Thanks