Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Norm

Thread: Need help, making my game to a multiplayer game.

  1. #1
    nimrod46 is offline Member
    Join Date
    Feb 2015
    Posts
    8
    Rep Power
    0

    Default Need help, making my game to a multiplayer game.

    Hello, I new in this forum and I don't sure if I in the right topic.
    Anyway my game is very simple something like snake, in the past my game supported only 2 remote players but now i want to make it unlimited if you guys get what I mean.
    So what I did is to make a class called "Player" and at any time that i need to make a new player I do this:

    Java Code:
    Player player = new Player(25,5){}; //define the player location and the player himself
    				player.GameIn();                                     // initialize the player
    				 GameClient.connectedPlayers.add(player);	//adding the player to the players list
    and when I want to render the player and make it movable I do this:
    Java Code:
    for(int i = 0; i <GameClient.connectedPlayers.size() ; i++){
    					Player player =  GameClient.connectedPlayers.get(i);					
    					player.start(); //starting to render the player and making it movable
    				}
    But my problem is that I can see only the last player that has been initialized, for example:
    Java Code:
    Player player = new Player(25,4){};
    				player.GameIn();
    				 GameClient.connectedPlayers.add(player);	 
              Player player1 = new Player(25,20){};
    				player1.GameIn();
    				 GameClient.connectedPlayers.add(player1);
    after doing this you will be able to see only the player that is on 25X,20Y.
    So what do I need to do to make it so he would show me few players?
    please help me, and thanks in advance :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Need help, making my game to a multiplayer game.

    what do I need to do to make it so he would show me few players?
    How are the players being saved so that it can show you all of them?
    Can you use a collection like an ArrayList to save references to more than one player?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    nimrod46 is offline Member
    Join Date
    Feb 2015
    Posts
    8
    Rep Power
    0

    Default Re: Need help, making my game to a multiplayer game.

    Quote Originally Posted by Norm View Post
    How are the players being saved so that it can show you all of them?
    Can you use a collection like an ArrayList to save references to more than one player?

    well yes i have an arry list in GameClient called "connectedPlayes" you can see in my explanation that I am using:
    Java Code:
    for(int i = 0; i <GameClient.connectedPlayers.size() ; i++){
                        Player player =  GameClient.connectedPlayers.get(i);                    
                        player.start(); //starting to render the player and making it movable
                    }
    to render ALL players...

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Need help, making my game to a multiplayer game.

    How are you debugging the code?
    Does the array list get longer as the players are added?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    nimrod46 is offline Member
    Join Date
    Feb 2015
    Posts
    8
    Rep Power
    0

    Default Re: Need help, making my game to a multiplayer game.

    Quote Originally Posted by Norm View Post
    How are you debugging the code?
    Does the array list get longer as the players are added?

    I am using Syso to debug the code and yes the array is getting bigger, maybe I cant use the same class over and over again?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,007
    Rep Power
    34

    Default Re: Need help, making my game to a multiplayer game.

    Are the values going into the ArrayList unique? Or are they references to the same object being used over and over?
    Are there any static members in the Player class? Using static means there is only one value for all the instances of the class.
    jim829 likes this.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    nimrod46 is offline Member
    Join Date
    Feb 2015
    Posts
    8
    Rep Power
    0

    Default Re: Need help, making my game to a multiplayer game.

    Quote Originally Posted by Norm View Post
    Are the values going into the ArrayList unique? Or are they references to the same object being used over and over?
    Are there any static members in the Player class? Using static means there is only one value for all the instances of the class.
    OMG I am such an idiot thank you so much for your help I had some value that were statics :))))

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help, making my game to a multiplayer game.

    Quote Originally Posted by Norm View Post
    Are the values going into the ArrayList unique? Or are they references to the same object being used over and over?
    Are there any static members in the Player class? Using static means there is only one value for all the instances of the class.
    Nice deduction Mr. Holmes!

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. multiplayer LAN game
    By ethomas92 in forum Networking
    Replies: 1
    Last Post: 12-14-2012, 09:54 PM
  2. Multiplayer Bingo game
    By js4learn in forum Java Gaming
    Replies: 1
    Last Post: 07-08-2011, 04:43 AM
  3. Multiplayer game - multiple instances
    By robs in forum Java Gaming
    Replies: 0
    Last Post: 04-18-2011, 10:33 AM
  4. Multiplayer Game(Sockets)
    By kevinnrobert in forum Java Gaming
    Replies: 1
    Last Post: 04-02-2010, 02:22 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
  •