Round based gamerules

Hey,

in my chess-like game, the user currently can klick on a playstone, which moves it to a certain position.



Actually, i would like there to be a kind of rule, like the following:

  1. The player (1 of 2) can klick on a playstone (to select it)
  2. Only after a stone has been selected, the player then can klick on a part of the gameboard to move the stone to that position.
  3. The first player now has finished his move, so now the second player (there are only 2 players total) can take his turn (step 1 and then step 2)
  4. After the second player has finished his turn, all starts over.



    How could i implement this? I wasnt able to find any examples for this.

    If there exist any, i'd be grateful for a link to that source :slight_smile:



    Im using Gamestates, and my main game is basegame. My ingamestate is a camerastate.





    Later i want to make this game playable over network (still only 2 players) via the JGN. Is there anything i need to look out for?

I would suggest you have a look at the classes TestPick and MousePick in the jmetest.intersection package.

They should give you a clue how to implement the selection of playstones and the gameboard.

The rest will be just game logic.

ive done that already and i can pick the stones.

but im not sure where/how i could do the gamelogic





i thought of some simple variables like: boolean isPlaystonePicked

and so on. but is this the best approach?

Sure, when you know already the state of the gameboard and when the player picked something, you will need only a few vars to count the turns and gamestates.



ChessBoardState boardState; // This can be an enum with the values: Player1Picking, Player1Placing, Player2Picking, Player2Placing
int turns; // Number of this turn.
int pickedPlayStoneID; // -1 when no playstone is picked.
Vector2f newPlayStonePosition; // null when the playstone is not placed yet.



Something like this should be enough to handle the logic. Perhaps a few vars more.
But it is not more complicated.

With an enum your update-method could look perhaps a bit like this:


public void updateBoard(float tpf) {
  switch(boardState) {
    case Player1Picking:
      if(pickedPlayStoneID != -1) {
        boardState = Player1Placing;
        // Some more  logic for this state here
        ...
      }
    break;

    case Player1Placing:
    // Logic for this state here
    ...
    break;

    ...

  }
}

thanks for the fast reply.

this really helps me alot :slight_smile:

papercut said:

2) Only after a stone has been selected, the player then can klick on a part of the gameboard to move the stone to that position.

Look at HelloMousePick in the jmetest.TutorialGuide.  Also look at wolfgang's code http://jmonkeyengine.com/forum/index.php?topic=9234.msg88037#msg88037

The first reference will give you a better fit for your game.
The second one will give you the ending position of where you want to move your playstone.

papercut said:

but im not sure where/how i could do the gamelogic

I stumbled upon one solution to your case when I was trying to do 2 separate things:
1. left mouse click to pick and highlight a target
2. right mouse click to rotate and travel to the clicked location

Well, you can use this 
1. pick the target object with your code or the first above
2. 'grab' the target by identifying which mesh -> node; i'm using ogre mesh right now so I had to modify the OgreEntityNode so I could assign unique names to each node (I'm sure I'm doing it the hard way  ;) )
3. pick the terrain using the second above to get the TriMesh to get the terrain pick location
4. translate the location of the target by assigning it to the TriMesh location

papercut said:

i thought of some simple variables like: boolean isPlaystonePicked
and so on. but is this the best approach?

I've always liked simplicity, but don't always get it.  Maybe using one variable boolean isMyTurn.
Two ways to for it to be true.
1. You're player 1 at the start,
2. You're 'given' both the play stone location and the turn (i.e. player 2's isMyTurn=false, and yours becomes true)

When it's not you're turn, you could

if(!isMyTurn) {
  // code telling you each time you click the stone that it's not your turn  XD
}

receiveTurn() {
  receivePlaystoneLocation();
  setPlaystoneLocation();
  isPlaystoneMovable = true;
}

giveUpTurn(){
  sendPlaystoneLocation();
  isPlaystoneMovable = false;
}

I think the isPlaystoneMovable is not needed because you can just use isMyTurn for control.