Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Turn-based combat in java

Name: Anonymous 2007-05-11 16:17 ID:djeUSFex

howye
i was wondering, how does one go about making turn-based combat, in java? Some kind of nested for/if structure? Could i do-while(enemies avghp != 0) to keep it going? Turn order would be based on each object's "speed" variable.
Any pointers?

Name: Anonymous 2007-05-11 16:24 ID:mO3xCyYO

Pointers? No, it's Java

Name: Anonymous 2007-05-11 16:24 ID:z8VNMFK3

Use a priority queue.

Name: Anonymous 2007-05-11 16:25 ID:djeUSFex

3>> please explain? My java abilities are shit.

Name: Anonymous 2007-05-11 16:26 ID:bBhEuz+o

No, Java doesn't support pointers.

Name: Anonymous 2007-05-11 16:26 ID:bBhEuz+o

>>2

Ah damn you

Name: Anonymous 2007-05-11 16:26 ID:bBhEuz+o

Seriously though, what triggers the turn?

Name: Anonymous 2007-05-11 16:27 ID:Heaven

>>4
Learn the basics of programming before trying to do anything.

Name: Anonymous 2007-05-11 16:38 ID:mO3xCyYO

>>5,6
HA HA HA

Name: Anonymous 2007-05-11 16:49 ID:0JqWUzjX

Java doesn't support anything good

Name: Anonymous 2007-05-11 19:00 ID:SzBWy8Ks

You could just build the whole thing around the widget toolkit and its events. Create custom widgets to represent units that know the player# of their owner, react to events like mouse clicking by doing something strategy game units should do (compare unit's owner id to current player's id before they move or do something). Will look and play like Microsoft Excel but it should work.

If you manage to code this you can probably proceed to making the same program with something more "low level" like Java2d, that should actually make it look like a game, if you can't you suck and shouldn't think about coding something this complex.

Name: Anonymous 2007-05-11 19:36 ID:J/TfYj0G

I'd let the 'end turn' button govern everything. Something like this:

OnEndTurnButtonPressed()
{
   current player state = idle
   next player = active
   if (it's a computer player)
   {
      run it's AI
      OnEndTurnButtonPressed() //press end of turn for him
   }
}

The input functions should only let the active player use the UI.

Name: Anonymous 2007-05-11 19:48 ID:SzBWy8Ks

Try something like this (java-ish pseudocode):

class Game{
  Vector<Unit> units;
  int currentPlayerNum; // whose turn it is?
  int numPlayers;       // using looong names for clarity

  void changeTurn(){
    currentPlayerNum++;
    if(currentPlayerNum >= numPlayers){
      currentPlayerNum = 0;
      newRound(); // reset units' action points etc.
    }

    while(currentPlayerNum belongs to AI){
      playAITurn(); // make AI play this turn
    }
  }
}
class Unit{
  int ownerNum;
  int positionx, whatever, etc;
}

Put any real game logic into the Game class, and make an UI (Swing+Java2D might do it) that calls Game's methods when the player triggers UI events. Make it check if unit.ownerNum matches game.currentPlayerNum before letting the player issue commands to unit.

Name: Anonymous 2009-01-14 13:34

Name: Sgt.Kabu辶ꗹkiman셜᧚ 2012-05-29 2:01

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List