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?
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:
Anonymous2007-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:
Anonymous2007-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
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.
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