Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Newbie & Debugging Questions / Re: Correct way to use Random.class on: 2013-04-03 10:47:02
You're doing the worst thing for a programmer: applying patterns without knowing why, or just to feel smarter.
Patterns may solve problems (sometimes), but on the other hand they make code more complex and abstract (for sure!), therefore more buggy.

I used the Singleton here because I wanted only one instance of random instead of creating multiply objects in every class (or method) I needed it. But I really should follow the KISS-principle (great band btw Cheesy) and I know that I am far from having to worry about "performance". It just felt "bad" to create a bunch of new random isntances everywhere.

But if you know FOR SURE you'll need seeds, then yes, you may need a singleton, though I hate them.
I prefer to keep an object around (your random nb generator) instead.

Would you mind explaining how it looks? I mean do you use a private static Random field in that class?
Many thanks you for your reply.

Don't worry too much about what is "right" because if it works it is right. Singletons are just sorta a bad practice. Same goes with static things but in reality you do what works and is fast to write.
Thank you Smiley

You'll get somewhat better performance by using an instance of Random yourself such as the singleton, and not the static methods on Random. If you're working in multiple threads, using ThreadLocalRandom in 1.7 and later is also a bonus.
If you're going to use a JDK supplied RNG and 1.7+ is OK, then ThreadLocalRandom is a better choice even for single threaded apps (IMHO).
Yes, I have read about that here in the forum yesterday but I'm on MacOS 10.6.8 so I only have JDK1.6 available atm Cranky
2  Game Development / Newbie & Debugging Questions / Correct way to use Random.class on: 2013-04-03 01:26:19
Hey fellas,

I'm using java.util.Random for lots of different things in my game (rolling dice, choosing different enemies, names, etc.). I have read that it is usually a good idea to use one source of random numbers (incase you want to save the seed for example as far as I understood).

In my "older" game I had a Dice.class that in which I used:
1  
2  
3  
4  
5  
6  
7  
public static Random rnd = new Random();

// and called
{
    Dice.rnd ...
}
// everywhere else


In my latest try (in which I really want to take my time and learn stuff properly instead of wanting to finish a game as fast as possible) I now switched to a singleton pattern:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class RandomInstantiation
{
   final private static Random instance = new Random();
   
   private RandomInstantiation() {};
   
   public static Random getInstance() {
      return instance;
   }
}


I'd love to know if this is a proper way to do this, as I've also read that usually singleton patterns aren't encouraged... (whatever that means  Huh).
3  Game Development / Newbie & Debugging Questions / Re: Creating lots of different enemies (Inheritance, polymorphism, etc.) on: 2013-03-31 15:53:07
Thanks for all the replies they definitely helped!
I now use Properties to read the attributes from external text files.
This is what my system looks like now:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
public abstract class Entity
{
   final private FileHandler fh = FileHandler.getInstance();
   
   /* General Information */
   private String name;
   private String race;
   
   private int cb;
   private int cn;
   private int cr;
   private int in;
   private int mg;
   private int nt;
   private int st;
   private int wp;
   
   private int dv;
   private int mv;
   private int sz;
   private int lf;
   private int hp;
   
   /* Abstract methods */
   @Override
   public abstract String toString();
   
   /* Constructors */
   protected Entity() {}
   
   /* Concrete Methods */
   protected void initializeAbilities(String path) {
      race = fh.loadProperty("race", path);
      cb = Integer.parseInt(fh.loadProperty("cb", path));
      cn = Integer.parseInt(fh.loadProperty("cn", path));
      cr = Integer.parseInt(fh.loadProperty("cr", path));
      in = Integer.parseInt(fh.loadProperty("in", path));
      mg = Integer.parseInt(fh.loadProperty("mg", path));
      nt = Integer.parseInt(fh.loadProperty("nt", path));
      st = Integer.parseInt(fh.loadProperty("st", path));
      wp = Integer.parseInt(fh.loadProperty("wp", path));
      dv = Integer.parseInt(fh.loadProperty("dv", path));
      mv = Integer.parseInt(fh.loadProperty("mv", path));
      sz = Integer.parseInt(fh.loadProperty("sz", path));
      lf = Integer.parseInt(fh.loadProperty("lf", path));
   }
   
   /* Getters && Setters */
   public String getName() {
      return name;
   }
   .
   .
   .
   .
   .

}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
public abstract class Enemy extends Entity
{
   final private FileHandler fh = FileHandler.getInstance();
   final private Random rnd = Randomizer.getInstance();
   
   /* Attributes */
   private int sp;      // Speed
 
   public Enemy(String namePath, String propPath) {
      setName(loadRandomName(namePath));
      initializeAbilities(propPath);
   }
   
   private String loadRandomName(String path) {
      ArrayList<String> names = fh.readCompleteFile(path);   // Stores all names from the file
     String name = null;         // The name to be returned
     int index;               // The index number of the item to pick
     
      /* Provide a random index in range of the array list and select the
       * according item in the list */

      while (name == null) {
         index = rnd.nextInt(names.size());
         name = names.get(index).trim();
      }
     
      return name;
   }
   
   @Override
   protected void initializeAbilities(String path) {
      super.initializeAbilities(path);
      sp = Integer.parseInt(fh.loadProperty("sp", path));
   }
   
   @Override
   public String toString() {
// Ignore this - it's just for testing
     System.out.println("Name: " + getName());
      System.out.println("Race: " + getRace());
      System.out.println("CB: " + getCb());
      System.out.println("CN: " + getCn());
      System.out.println("CR: " + getCr());
      System.out.println("IN: " + getIn());
      System.out.println("MG: " + getMg());
      System.out.println("NT: " + getNt());
      System.out.println("ST: " + getSt());
      System.out.println("WP: " + getWp());
      System.out.println("DV: " + getDv());
      System.out.println("MV: " + getMv());
      System.out.println("SZ: " + getSz());
      System.out.println("LF: " + getLf());
      System.out.println("SP: " + getSp());
      return null;
   }
   
   /* Getters && Setters */
   public int getSp() {
      return sp;
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
public class Zombie extends Enemy
{
   final private static String NAMEPATH = "files/enemies/names/zombie.name";
   final private static String PROPPATH = "files/enemies/races/zombie.prop";
   
   public Zombie() {
      super(NAMEPATH, PROPPATH);
   }
}

4  Games Center / WIP games, tools & toy projects / Re: Pseudo Voxel Expriements on: 2013-03-29 17:45:10
Looks really cool!

Reminds me of 3D Dot Game Heroes for the Ps3:

http://worldofvideogames.de/wp-content/uploads/2010/05/3D-Dot-Game-Heroes_Spielfigur.jpg
5  Game Development / Newbie & Debugging Questions / Creating lots of different enemies (Inheritance, polymorphism, etc.) on: 2013-03-04 03:06:04



Hey fellas,

I currently have run into a problem while creating lots of enemies - not that it doesn't work, I'm just not sure what the best approach would be.

I have about 30 different enemy-types (ants, rats, orcs, dragons, etc.) and they all are described by the same fields. Therefore I have created a superclass called enemy:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
public abstract class Enemy
{
   /* General Information */
   private String type;
   private int ac;
   
   /* Health related */
   private int maxHP;
   
   private int attackBonus;
   private int movement;
   
   /* Attack related */
   private String attType;
   private int attNo;
   private int damage;
   private int saveAs;
   private int morale;
   
   private int appearingNo;   // determines how many monsters of this type appear
 
   /* Drops */
   private String treasureType;
   private int exp;
   
   public Enemy(String type, int ac, int maxHP, int attackBonus, int movement, String attType, int attNo, int damage, int saveAs, int morale, int appearingNo, String treasureType, int exp) {
      this.type = type;
      this.ac = ac;
      this.maxHP = maxHP;
      this.attackBonus = attackBonus;
      this.movement = movement;
      this.attType = attType;
      this.attNo = attNo;
      this.damage = damage;
      this.saveAs = saveAs;
      this.morale = morale;
      this.appearingNo = appearingNo;
      this.treasureType = treasureType;
      this.exp = exp;
   }
}


Now when I want to create a giant ant for example I need to call the super.constructor:

1  
2  
3  
4  
5  
6  
public class MobGiantAnt extends Enemy
{
   public MobGiantAnt(String type, int ac, int maxHP, int attackBonus, int movement, String attType, int attNo, int damage, int saveAs, int morale, int appearingNo, String treasureType, int exp) {
      super(type, ac, maxHP, attackBonus, movement, attType, attNo, damage, saveAs, morale, appearingNo, treasureType, exp);
   }
}


Now here is where my question comes to play. All ants share the same stats (same type, same ac, same maxHP, etc.). I obviously don't want to type in all parameters when I create a new ant but rather have new MobGiantAnt() automatically create an ant with the shared base values. Long story short: Is it better to use static fields (as they are shared by all objects created from that class to my understanding).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public class MobGiantAnt extends Enemy
{
   final private static String type = "Giant Ant";
   final private static int ac = 17;
   final private maxHP = ...
         .
         .
         .
         .
     
         
   public MobGiantAnt() {
      super(type, ac, maxHP, attackBonus, movement, attType, attNo, damage, saveAs, morale, appearingNo, treasureType, exp);
   }
}


Or to change the fields in the Enemy class to protected and do this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class MobGiantAnt extends Enemy
{        
   public MobGiantAnt() {
      this.type = "Giant Ant";
      this.ac = 17;
         .
         .
         .
   }
}


Excuse me if this is a stupid question, but I often get stuck on stuff like that :/

To my understanding protected means that only classes in the same package have access to the fields, but generally use of private fields and getters/setters is suggested. Is it good to have different subclasses for each enemy at all?
6  Games Center / Archived Projects / Re: Trucker on: 2011-10-08 19:16:44
Maybe it's just me but I think that 'r' is pretty inconvenient for the reverse... I mean it's realistic but from a gamer's point of view I think that using 's' for the reverse would "feel" better.

Anyways nice little game Wink
7  Games Center / Archived Projects / Re: Fight For Arcadia (Text Based) on: 2011-10-07 15:30:34
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 Smiley) 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 :/
Anyways, I shortened the feedback during fight, included items ... etc. but mainly I improved my code Smiley

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
8  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-22 22:09:15
I guess Player and Enemy was a bad example ... I just picked them because I was in a hurry yesterday. But your posts made it pretty clear to me in general.
I ran into this problem while creating Items (like Armor, Potion, etc.) but solved that now by creating a "middleman" who can get information from both the player and the item class via accessors - why I didn't find that solution myself earlier... I don't know Clueless Sorry for that !

Considering my second question maybe a good example is my UserInput class which I use to get (who could've guessed it) all the user's input throughout the game and return it as a value (int or String). Besides that it doesn't have any fields nor accessor methods to communicate with other objects. What I want to know is, if it's still reasonable to create only one instance of that object at a higher level (e.g. in the main class similar to how I do it now with my player class) and pass it into the constructors of those classes who use it OR would it also be okay to create it in each class seperatly because (the way I see it) for those objects it isn't important to have access to one specific object  ... I hope you understand what I mean - it's really hard for me to explain it in english (so please forgive me if I use the wrong expressions occasionally :/).
9  Games Center / Archived Projects / Re: Fight For Arcadia (Text Based) on: 2011-09-21 13:01:46
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 Smiley

Greetings.
10  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-21 12:04:40
Write the game first before you start bikeshedding details like this. 

Yes I also don't see why I should write a custom engine for a simple game like that Smiley

I have two new questions:

I still don't understand Objects 100%. For example what if I have my "player object" and the "enemy object" and want them to communicate. The way I do it now only the "enemy object" can get information about the "player" via Getters and Setters (but not vice versa). I created them in the main game file like this:

1  
2  
3  
4  
5  
6  
7  
8  
private Player player;
private Mob mob;

public Main()
{
        player = new Player();
        mob = new Mob(player);
}


Is there a way I can get them to share information??

and No. 2:
When i have an class e.g. one that handles the player's input is it also good to make an instance in the main class or is it also okay to just create it in the class you really need it (since all the other objects don't need to see it) instead of passing it into a constructor.

Greetings, EatenByAGrue
11  Games Center / Archived Projects / Re: Fight For Arcadia (Text Based) on: 2011-09-19 13:38:44
Thank you Skarion Smiley

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
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. Smiley

Greetings,
EatenByAGrue
12  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-19 13:00:35
You mean instead of using the java-pseudorandom number generator I should use a true random number generator?
I already changed the "dice"-code from
1  
 die = (int) (sidesOfDie*Math.random() + 1); 
to use the java.util.Random API instead yesterday, if you meant that Smiley.



P.S.: I would really appreciate if any suggestions regarding the game would be made in the other thread but I would still like to keep this thread for asking general questions  Smiley.
13  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-19 00:51:07
I openend a new "Showcase" - Thread for the game here:

http://www.java-gaming.org/topics/fight-for-arcadia-text-based/24793/view.html
14  Games Center / Archived Projects / Fight For Arcadia (Text Based) on: 2011-09-19 00:49:37
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
15  Games Center / Showcase / Re: Unknown universe on: 2011-09-19 00:17:08
Edit2: Try to start the game from the command prompt (Terminal) and see what error the crash produces.

1  
2  
3  
4  
<Error>: CGContextFlush: invalid context 0x11ed4fa60
Invalid memory access of location 0x0 rip=0x11da0d8c9

Floating point exception

Hope that helps :/
16  Games Center / Showcase / Re: Unknown universe on: 2011-09-18 18:29:21
Hello Skarion,

I noticed that after you load a game the turn-counter in the top right corner is reset to zero. I wasn't quite sure if that's normal or a bug Smiley

Unfortunately I still get crashes every few minutes. It's strange as they seem to occur totally by random. Sometimes the game crashes without me doing anything and sometimes it happens when I click on a button or try to open a different view. Undecided

I will try it on a windows pc later on - maybe it's just a problem with mac os?

greetings,
EatenByAGrue
17  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-18 17:11:43
@ 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 Smiley

@ Rebirth:

These are good ideas. Much appreciated Smiley

Quote
- show chance to win on every turn

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

Quote
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???)

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   
// 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 Smiley).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
      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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
      /* 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...)   Grin.

Greetings,
EatenByAGrue
18  Games Center / Showcase / Re: Unknown universe on: 2011-09-16 13:13:10
Edit: Seem to been the tooltip, it work perfectly after I removed the tooltip. Smiley

Yes the tooltip is excactly what I meant Smiley
19  Discussions / Business and Project Management Discussions / Re: Mythology Unbound, new game in development on: 2011-09-16 11:05:46
MMORPG and Geocaching - sounds like a really cool idea Smiley

Using geo-location it will populate in-game objects to GPS coordinates.

I'm wondering how you are going to ensure, that those locations aren't inaccesible (or even dangerous). Are you planning to use fixed locations? I guess then you'll need the help of many people around the world ...

Anyways, looking forward to see this one coming to live Smiley
20  Games Center / Showcase / Re: Unknown universe on: 2011-09-16 00:31:12
Hey,

I really enjoy your game and I love how you start so small in such a huge map - It's almost the same feeling I get while playing minecraft. I want to explore more and more Smiley

I noticed a little thing though. When I try to click the "End Turn" button in the bottom right corner, the popup that says "Click to end turn no..." sometimes hinders me from actually being abled to click the button. It starts to flicker and I have to carefully place my mouse to be abled to click it then Smiley

I play on a MacBook res. 1280 x 800.

Greetings
21  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-15 21:53:28
Thank you very much Smiley

You are right, I moved the save feature down.

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.

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 Smiley
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.).
22  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-15 13:11:41
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 Smiley

EDIT: Removed Link

greetings

P.S.: Oh and I would love to see how far you come with your characters Smiley
23  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-14 23:50:18
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?
24  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-14 16:51:00
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.

It's funny because that's excactly how I tried to do it (as I've read on about inheritence and polymorphism) Smiley 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".

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
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("");
   }
}


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

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  Huh

Greetings,
EatenByAGrue
25  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-11 16:44:56
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" Cheesy
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 Cheesy

========================================
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 Smiley).

Thank's to everyone who helped me, especially bonbon-chan Smiley

@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

Cheesy

26  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-11 03:22:22
Guess who's back! Smiley

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

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 Smiley

P.S.:
EatenByAGrue (you are a french worm ?)

I really laughed about that Cheesy

(for those who don't know the scariest monster in Gaming history: http://en.wikipedia.org/wiki/Grue_%28monster%29)
27  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-08 13:32:11
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.  Undecided

Thank's for your help @ all
28  Games Center / Archived Projects / Re: Hostile Sector on: 2011-09-08 12:43:27
Looks great. It reminds me of "Shadow Company" if someone still knows this game.
29  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-08 11:51:52
To put it simple, use static for class that's not allowed to have multiple instance since all components inside your package only want it alone and same.

Well that's why I have used static for my "player" before (since there is only one player).

You don't need "only ever one", you need "currently only one". The correct design pattern for that is to just create one object.

Here is the problem I ran into. I created a new object of the type "player" in my combat class (since this is were all the magic happens and the player-class is needed the most) but now when I try to change one of it's variables, for example the player's name outside of the combat class I somehow need to access that certain object. So is that the right time and place to make it static (the pointer not the whole player-class I mean)?


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public class Combat
{
   static Player player = new Player();     // create a new object and store the reference to that object in player
                                                               //        make it static so that other classes can use it
     ...
      ...
      ...
}


public class Menu
{
      ...
      ...
        Combat.player.creation();      
      ...
      ...
      ...
}

public class Player
{
      ...
      public void creation()
      {
            ...
            ...
      }
      ...
}
30  Game Development / Newbie & Debugging Questions / Re: Textadventure (Newb Questions) on: 2011-09-07 23:39:35
I see that you are using a lot of "static" method. It is not in object oriented philosophically.

You are right. I still use "static" way too often. My "player" and "enemies" are objects already - I am currently rewriting the whole thing using objects and working on "state machines".

Your replies help a lot for my understanding Smiley


EDIT: Removed picture.
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (22 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (49 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (54 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!