Results 1 to 4 of 4
  1. #1
    nephos is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Alternating between players moves in a game

    Hello,

    I was wondering, what is the best way to alternate between players moves in a simple multi player game that is played over a network? The number of players in each game may vary from 4 to 6. I will probably be using RMI for the network connection if it makes any difference. Does anyone know of any good examples also?

    Thanks for the help!!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    You should have some variable that keeps track whose turn it is. When a player ends their turn you increment the variable to the next player. The problem comes when you get to the last player, how do you go back to the first? You can use the circular counting pattern.
    Java Code:
    counter = min + (counter - min + step) % (max - min);

  3. #3
    nephos is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default

    Thank you Junky :D

    I just have one other question relating to this. How should I go about getting different text to appear on each players screen?

    e.g. On the person whose turn it is it should say something like "Player1 it's your turn!" but on all the other players screens it should say "Player1 is making their move".

    Thanks again!

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    in the method that displays the message, insert a simple conditional statement around the line that prints the string, e.g.

    Java Code:
    boolean yourTurn = (thisPlayer == currentPlayerTurn);
    String message = yourTurn? (""+thisPlayer+" it's your turn") : (""+otherPlayer+" is making their move");
    System.out.println(message);

    You don't need to write it exactly as above, it's just an example.

Similar Threads

  1. alternating series sum java help
    By java157 in forum New To Java
    Replies: 18
    Last Post: 03-20-2011, 03:41 AM
  2. Alternating Sum
    By ScaryJello in forum New To Java
    Replies: 6
    Last Post: 10-13-2009, 09:18 AM
  3. strange alternating array
    By jarvis in forum New To Java
    Replies: 2
    Last Post: 04-23-2009, 09:42 AM
  4. Replies: 1
    Last Post: 12-11-2008, 08:50 PM
  5. rii-soft Arcade - for game players/ developers
    By rii in forum Reviews / Advertising
    Replies: 0
    Last Post: 08-18-2008, 04:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •