Textadventure (Newb Questions)

I really don’t understand why you need a static reference to the player in the Class combat… and ever less why you create it in it !!!

Like Orangy Tang said :


class Combat
{
   private Dice dice;

   public Combat(Dice dice)
  {
     this.dice = dice;
  }

  public int doCombat(Player play,Mob mob)
  {
     ....

     return WIN / LOOSE ;
  }
}

You should have a Game class (aka your TegrgMain) where you create your object and deal with your game life:


public class TegrgMain
{
   private Dice   dice;
   private Player player;
   private Combat combat;
   ...
 
   public TegrgMain()
   {
      dice = new Dice();
      combat = new Combat(dice);
      player = new Player();
      ....
   }

   public void start()
   {
      ...

      while(!finish)
      {
         ...
           case COMBAT:
              result = combat.doCombat(player,mob);
         ...
      }
   }
}


The problem is, that the tutorials I read mostly only use two classes to show an example, so when I started writing this “game” I played around with what I already knew and get it to do what I want it to do (that’s why I used static reference for example) . As I said it worked … and now I wanted to try to make it better as I progress. But for example I didn’t know that you should create all objects in the main class and then pass them on.

I guess I’m gonna stop doing this for now as I see I still lack the basic understanding of how things work. I’ll finish the book I’m currently reading and then try again. :-\

Thank’s for your help @ all

[quote]…is a terrible idea and shouldn’t be made static.
[/quote]
and I learned it from Kev’s tutorial

[quote]Or preloading the resources for the next level while still using the current level’s resources?
[/quote]
I load all resource even before the menu appears. All sprites are hold by a static HashMap.

For me, it is more on a philosophy point of view. Static was not mean to be use like that… but a working code is a working code. And if not using a static make thing far more simple (not parse an object through 36 invocations…), I will not be embarased to use it :wink:

To EatenByAGrue (you are a french worm ?), you have choosen a good game to start with (aka not MMO guys ;D). Since it is your first time, you should have to redo your design 5 or 6 times. Since your game is working, you should take what we say as advice and not thinks that you must do. If you see that it will make your code more simple go for it, otherwise continue until you see a problem.

We will always be pleased to help you so don’t hesitate to ask question.

Guess who’s back! :slight_smile:

It was really frustrating for me, that you guys tried so hard to explain something to me, that I could’ve learned by myself if I had just read a few more tutorials… That’s why I sat down and read a lot about objects (and their usage) the last two days and now started rewriting my game. I think I now at least understand the basics :slight_smile:
I thought that you had to create an object “where it is needed” … that’s why I wanted to create it in the Combat class in the last version. I now know better :slight_smile:

I also removed all the “method1() -> method2() -> method3() -> method1()” invocations (is that the correct word?) and improved some of my methods (for example creating only one method that can roll multiple different dice at once, instead of having multiple methods for each kind of dice like W4, W6 … and so on).

I hope I can finish it until tomorrow evening.
Thank you once again :slight_smile:

P.S.:

I really laughed about that :smiley:

(for those who don’t know the scariest monster in Gaming history: http://en.wikipedia.org/wiki/Grue_(monster))

Oh what a coincidence! I’m currently playing Zork for a CS project where I have to make my own text-based interactive fiction game!

Okay I finished updating my game. Maybe I should change the title of this thread as it basically isn’t a Textadventure anymore but more a “Text-based Hack and Slay” :smiley:
I wanted to add Armor and Weapon Items but I can’t motivate myself enough to do so atm. But I have to say I’m quite happy how it is right now. I also think the “balancing” is quite okay. This is the profile of my own char which died after 22 won fights because I wasn’t able to find a merchant to buy potions :smiley:

========================================
Name: Robert
Race: Orc Class: Brawler
Health: 1

Skills
I: 4 W: 5 S: 9 R: 7 E: 12

Level: 3
Exp: 1450 LvlUp: 4450
Fights Won: 22

If anybody is interested I could upload the jar file (but I have to warn you the graphics aren’t quite on the Next-Gen-Level :)).

Thank’s to everyone who helped me, especially bonbon-chan :slight_smile:

@ra4king: Zork is a great game. Have you played “A Hitchhiker’s Guide to the Galaxy”? I really love these kind of games.

Inventory
You have:
a splitting headache
no tea

:smiley:

Armor and weapon can be created by making a super class i.e Item. Then make one class per item extending Item class so they can have value like ATK pow, DEF pow etc.

You can upload your jar (I want see it too). If it is almost complete (or beta state) you can make thread on showcase. Good luck!

It’s funny because that’s excactly how I tried to do it (as I’ve read on about inheritence and polymorphism) :slight_smile: This is what I’ve come up with so far.

EDIT: If I understood it right, I could declare the Item class as abstract because it only serves as a “blueprint” for the subclasses and will never be used to create an object of the type “Item”.


public class Item
{
	protected Player player;
	protected int amount; 	// amount of items stored in inventory
	
	// Constructor
	public Item (Player player)        
	{
		this.player = player;
	}

	/**
	 * Tests if player has enough money to buy a 
	 * certain item.
	 * 
	 * @param price
	 */
	public void buy(int price)
	{	
		int money = player.getMoney();       
		
		if(money >= price)
		{ 
			money -= price;		// remove money from player's purse
			player.setMoney(money);
			
			increaseAmountOfItem();
		}
		else
		{
			System.out.println("Sorry, but you don't have enough money!");
			System.out.println();
		}
	}
	
	/* Polymorphic method */
	public void increaseAmountOfItem()            // Is this correct?
	{
		// Empty2
	}
	
	public int getAmount()
	{
		return amount;
	}
}

class SmallPotion extends Item
{	
	public SmallPotion(Player player)                     // Is there a way to make "Player" available without having to use a constructor in the subcalss?
	{
		super(player);
	}

	public void increaseAmountOfItem()
	{
		amount++;
		System.out.println("You now have " + amount + " small Potion(s).");
		System.out.println("");
	}
}

Even if it’s only a text-based game like this? I mean I don’t even have an executable jar file - it’s only runnable in the console at the moment ???

Greetings,
EatenByAGrue

You can still run jars from the console.


java -jar MyJar.jar

EDIT: D’oh! I clicked the appreciate button before I clicked the quote button xD free medal for you

Yes of course I know that you can run jars from the console. I just meant if it’s okay to post a game in the “Showcase” that solely runs in the console … I thought you should only put more “advanced” games there :wink:

EDIT: I will have a finsihed version (if you can call it like that) by tomorrow.

Greetings

P.S.: Can’t you ‘un’-appreciate it… or maybe a mod?

For shopwcase maybe you can ask Kappa the mod. Game is rated not only based to graphics but also in term fun of gameplay, story, replayablity etc. I dont think some of us will shout you in showcase like “wtf is this?! your game is suck! burn it! you got to the hell and bring along this crap!” so dont worry too much 8)

I didn’t see that. Do it again now trying to quote me :stuck_out_tongue:

Nice try :wink:

Okay, maybe I’ll make a thread in showcase when I improve it further. For now I’ll just post it here.

I also included the source code so feel free to criticise and comment. I know that there is a lot of room for improvement (for example the way I included the items is very ugly).

I also added “blocking” to the fights, but I think it threw the balancing off and also made them even longer. Anyways I hope you can enjoy it at least a little bit :slight_smile:

EDIT: Removed Link

greetings

P.S.: Oh and I would love to see how far you come with your characters :slight_smile:

This pretty good so far.
I think in the “Event menu” you should move the save feature near the bottom of the list, making the top items the ones used more frequently.
I’m not sure the continue after an attack is needed, maybe just go back to the event menu. It feels like an extra step.

Thank you very much :slight_smile:

You are right, I moved the save feature down.

Do you mean the Continue option after each of the enemy’s attack? I included it because a friend of mine said, that it was annoying to always scroll up to see what the enemy did to him :slight_smile:
But I guess it’s not really interesting after the first few fights.

Greetings

EDIT: I think I will rewrite the game once again, trying to put the newly learned stuff to use (make Items work, improve Menus, etc.).

Yes, the continue after the attack. Perhap condensing the results so they are visible on less lines would help.

I was lvl 4 Human brawler before ide out of potion :slight_smile:

some little advice:

  • fill HP when Level up
  • cut down each turn info. I think the info about dice result isnt necessary.
  • menu to buy items anytime
  • show chance to win on every turn
    and a bug, I bought big potion but it said “you now have 1 small potion”. Maybe you did typo.

Overall, I really like the battle system where you use dice to determine the chance (guess that char’s stats affect number required to some actions right???)

When you are confident enought, try to do an applet version : a JTextEditor to show the text (I say JTextEditor so you can add some html tag ;)) and a JTextField to enter commands.

But beware that it is not a simple modification. You will have to deal with event (when entering a commad) and it will change how your engine works. May be it is a good time to do it, later on it will be more difficult… well it is up to you and up to what you have plan to do.

@ aazimon:

Thank you, I’m going to change this in the next update. I thought that it would be interesting to see what actually went on “behind the scenes” alomst like playing a tabletop or D&D-kind of game. But I realised myself that sooner or later you just spam “1.” again and again till the fight is over :slight_smile:

@ Rebirth:

These are good ideas. Much appreciated :slight_smile:

Although I’m not sure how to do that, I’ll try to come up with a solution.

Indeed. Basically it works somewhat like the Warhammer tabletop rules.

First Strike:
Whoever has the highest Initiative strikes first each turn - If the Initiatives are equal a die decides the outcome).

Chance to Hit:
This decides if the attack hits the target. Therefore both the player’s and the mob’s Weapon Skill are compared based on
the following rules.

	
// Calculate the chance to hit based on the Weapon Skill of the Attacker and Defender
// attWS = attacker's weapon skill
// defWS = defender's weapon skill

		if(attWS == defWS) {
			neededToHit = 3; 
			}
		else if(attWS >= (defWS + 1) && attWS < (defWS + 5)) {
			neededToHit = 2;
		}
		else if(attWS >= (defWS + 5)) {
			neededToHit = 1;
		}
		else if(attWS <= (defWS - 1)) {
			neededToHit = 3;
		}
		else if(attWS <= (defWS - 2) && attWS > (defWS - 5)) {
			neededToHit = 4;
		}
		else if(attWS <= (defWS - 5)) {
			neededToHit = 5;
		}

After that a die is thrown and the total is compared to neededToHit. If the total >= neededToHit the attack hits.

Damage:

The damage is based on the attacker’s strength (and luck of course :)).


		rnd = dice.rollDice(1, 6);	// roll a W6 dice
		
		System.out.println("> The die comes up with " + rnd + ".");
		System.out.println("");
		
		if(rnd == 1)
		{
			System.out.println("Weak hit.");
			damage = (int) (attStr/2);
		}
		else if(rnd == 2 || rnd == 3 || rnd == 4 || rnd == 5)
		{
			System.out.println("Normal hit.");
			damage = (int) (attStr);
		}
		else if(rnd == 6)
		{
			System.out.println("Critical hit.");
			damage = (int) (attStr + attStr/2);
		}

Block Damage:
And last but not least the damage can be blocked. This is decided by comparing the defender’s resistance
and the attacker’s strength:


		/* Calculate chance to block damage based on attacker's strength and defender's resistance */
		if(defRes == attStr) {
			neededToBlock = 5; 
			}
		else if(defRes >= (attStr + 1) && defRes < (attStr + 5)) {
			neededToBlock = 4;
		}
		else if(defRes >= (attStr + 5)) {
			neededToBlock = 3;
		}
		else if(defRes <= (attStr - 1)) {
			neededToBlock = 5;
		}
		else if(defRes <= (attStr - 2) && defRes > (attStr - 5)) {
			neededToBlock = 6;
		}
		else if(defRes <= (attStr - 5)) {
			neededToBlock = 6;
		}

@ Bonbon-Chan:

I’m just starting on GUIs but I’m not sure if I already try to use them … yet. Especially as I’m still struggling with objects (super, subclasses, where to use them, how to use them, etc…) ;D.

Greetings,
EatenByAGrue