Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 34

Thread: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exclamation 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Hello Folks,

    my name is MdeeY......i am new to this forum i just registered......i really need some help with 2d game TCP multiplayer.....the is about Spaceship Multiplayer i want to use TCP client and server to enable two people to control the spaceships from two computers or one computer by running the instance of the server then two instance of the client.......any help will be greatly appreciated


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    What have you done so far? Do you have code and any specific questions about your project?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Yes i have written the program everything is work...i can drive the spaceship on one computer but i haven't implemented the network part.........if u have skype or any other IM we can chat and i will show u my code......thanks

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Sorry, no private communications.

    Write a SSCCE and post it here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    ok i understand.....what does SSCCE stands for please ?

    --- Update ---

    I'm new here Norm please help me........the Program is school assessment and is due to be submitted in 1 week time.....thanks!

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Sorry, this defines a SSCCE: Short, Self Contained, Correct Example

    How will the client and server communicate? What messages will be sent between them? How can those messages be used to drive the playing of the game? You should be able to write the message sending/receiving code without having to work with the game playing code. Design an interface in the game code to use the messaging done over the network.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

     
    //Import PACKAGES
    import java.net.*;
    import java.io.*;
    import java.util.logging.Logger;
    import javax.swing.Timer;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import java.lang.*;
    import javax.swing.*;
    import java.applet.*;
     
     
    public class SpaceshipClient extends JPanel implements ActionListener, KeyListener
    {
     
           public ImageIcon pictures0[];// This is the array of pictures0 that will be animated
           public ImageIcon pictures1[];// This is the array of pictures0 that will be animated
     
           public int player1spaceship = 13, player2spaceship = 13;
           public int x = 500, y = 368, x0 = 550, y0 = 368;// X and Y Cordinates for Positioning the Space ships
           public Timer AnimationTimer;//Timer to drive the animation and start the races
           public int Velocity = 0, Velocity1 = 0;// This keeps track of the two Space ships speed
           public String send = null;
     
     
       public SpaceshipClient()
       {
          try //Try Block to Display the Welcome Screen
     
             {
                //display a welcome dialog (JOptionPane) that includes the rules
     
              JOptionPane.showMessageDialog(null,"GAME INSTRUCTIONS \n\n" +"This game is a multiplayer space ship game\n" + "Player 1 space ship is Red\n" + "Player 2 space ship is Blue\n\n" + "The Object of this game is to\n" + "drive the two space ships around\n" + "the race track and try to reach\n" + "the finishing line as quick as possible\n" + "to gain first position while avoiding\n"+ "collision with the wall, center astroid and each other.\n\n" + "PLAYER 1 CONTROLS\n\n" + "W = Accelaration\n" + "S = Decelaration\n" + "D = Turn right\n" + "A = Turn left\n\n" + "PLAYER 2 CONTROLS\n\n" + "I = Accelaration\n" + "K = Decelaration\n" + "L = Turn right\n" + "J = Turn left\n");
     
             }
     
     
     
           catch(Exception e){
             }
     
     
     
     
           try //Try Block to Play the Sound
             {
                URL eng = this.getClass().getResource ("Sounds/hotidle.wav");// This Loads the Sound Effect from the Directory
                AudioClip snd = JApplet.newAudioClip(eng);//Creating Instance of the Audio Clip
                snd.play();//This will play the sound effect only once
     
             }
     
     
     
           catch(Exception e){
             }
     
     
     
     
        }     
     
     
     
     
     
     
     
       {
               int i = 0;//This sets the number of pictures0 to Zero since its an array
               pictures0 = new ImageIcon[16];//Creating the instance of pictures0
               pictures1 = new ImageIcon[16];//Creating the instance of pictures0
     
     
               //This will allow the Key Presses 
               addKeyListener(this);
               setFocusable(true);
               setFocusTraversalKeysEnabled(false);
     
               // Method to load the 16 pictures0
               while(i < 16){
     
                   pictures0[i] = new ImageIcon("player1/spaceship"+i+".png"); // This loads the pictures0 from the directory 
     
                   pictures1[i] = new ImageIcon("player2/spaceship"+i+".png");// This loads the pictures0 from the directory 
     
                   i++;// starts the animation of the pictures0
               } 
     
       }
     
     
     
     
    	  public void paintComponent( Graphics g ) {
     
     
    	  super.paintComponent(g);// This calls the super class paintComponent
     
    	   Color c1 = Color.black;
          g.setColor( c1 );    
          g.fillRect(50, 100, 750, 500);  // surrounding space  
     
         // Color c2 = new Color(210, 105, 30);
          //g.setColor( c2 );
          //g.fillRect( 150, 200, 550, 300 ); // asteroid
     
          Color c3 = Color.white;
          g.setColor( c3 );
          g.drawLine( 425, 500, 425, 700 ); // finish line
     
          g.setColor(Color.white);
          g.drawRect(100, 150, 650, 400);// mid-lane marker
     
    		Color c4 = Color.blue;
          g.setColor( c4 );
          g.drawLine( 200, 250, 570, 325 );     
     
               //draw the two Space ships to the screen, at the white line 
          pictures0[player1spaceship-1].paintIcon(this, g, y, x);
     
          pictures1[player2spaceship-1].paintIcon(this, g, y0, x0);
     
    		Image image;
     
      		ImageIcon i = new ImageIcon("images/near1.jpg");
      		image = i.getImage();
      		g.drawImage(image,150, 200, 520, 280, null);
     
     
     }
     
     
     
     
     
            //This method is used to respond to Timers' event
           public void actionPerformed( ActionEvent e )
           {
     
                //Using Rectangles to detect collision between the Space ships and the Wall walls
                Rectangle  Wall = new Rectangle(49, 100, 715, 452);
                Rectangle  Asteroid = new Rectangle(150, 200, 520, 280);
                Rectangle Finishline = new Rectangle(425, 500, 1, 615);
     
                int cordinate_x = x;
                int cordinate_y = y;
                int cordinate_x0 = x0;
                int cordinate_y0 = y0;
     
                //Move the Space ship forward base on the direction its facing
                if(player1spaceship == 1)
     
                { 
     
                cordinate_x -=Velocity1;
     
                }
     
     
     
                else  if(player1spaceship == 5)
                { 
     
                cordinate_y +=Velocity1; 
     
                }
     
     
     
               else if (player1spaceship == 9)
     
                 { 
     
                 cordinate_x +=Velocity1;
     
                 }
     
     
     
     
     
                else if (player1spaceship == 13)
     
                { 
     
                cordinate_y -=Velocity1;
     
                }
     
     
     
     
                if(player2spaceship == 1)
     
                { 
     
                cordinate_x0 -=Velocity; 
     
                }
     
     
     
     
                else if(player2spaceship == 5)
     
                  { 
     
                  cordinate_y0 +=Velocity;
     
                  }
     
     
     
     
                else if (player2spaceship == 9)
     
                { 
     
                cordinate_x0 +=Velocity;
     
                 }
     
     
     
     
     
     
                else if (player2spaceship == 13)
     
                 {
     
                 cordinate_y0 -=Velocity;
     
                  }
     
     
     
     
     
                //Using Rectangles to detect collision between the two Space ships
                Rectangle  spaceship1 = new Rectangle(cordinate_y, cordinate_x, 50, 50);
                Rectangle  spaceship2 = new Rectangle(cordinate_y0, cordinate_x0, 50, 50);
     
                   //This Detects the Collision between the Walls of the race track and the two Space ships                        
                if(!Asteroid.intersects(spaceship1) && Wall.inside(cordinate_y,cordinate_x) && (!spaceship1.intersects(spaceship2)))
                   {
     
                      y = cordinate_y;
                      x = cordinate_x;
     
                      //This checks and see if Player 1 hits Player 2 then the game ends
                      if(spaceship1.intersects(spaceship2))
                         System.exit(0);  
                   }  
     
     
     
     
     
                      if(spaceship1.intersects(spaceship2))
                   {
     
                   URL eng = this.getClass().getResource ("Sounds/CARCRASH.WAV");// This Loads the Sound Effect from the Directory
                   AudioClip snd = JApplet.newAudioClip(eng);//Creating Instance of the Audio Clip
                   snd.play();//Message to be displayed when the two Space ships crashed / collide
                   System.out.println("Space ships Crashed Game Over \n" + "Connection Lost fROM server" );
     
                   //Displays the a Message when the two Space ships crashed
                   JOptionPane.showMessageDialog(null,"Space ships crashed!! \n\n" + "*****Game Over***\n\n" + "hit OK to Exit");
     
                   System.exit(0);//Terminates the Game if Collision happens    
                   }
     
     
     
     
     
     
    					 if(!Asteroid.intersects(spaceship1) && Wall.inside(cordinate_y,cordinate_x) && (!spaceship1.intersects(spaceship2)))
                   {
     
                      y = cordinate_y;
                      x = cordinate_x;
     
                      //This checks and see if Player 1 hits Player 2 then the game ends
                      //if(Asteroid.intersects(spaceship2))
                         //System.exit(0);  
                   }
     
     
     
     
     
     
     
                      if(Asteroid.intersects(spaceship2))
                   {
     
    					Velocity  = 0;
    					Velocity1 = 0; 
     
                   URL eng = this.getClass().getResource ("Sounds/geardown.WAV");// This Loads the Sound Effect from the Directory
                   AudioClip snd = JApplet.newAudioClip(eng);//Creating Instance of the Audio Clip
                   snd.play();//Message to be displayed when the two Space ships crashed / collide
     
     
                   }
     
     
     
     
     
     
    					 if(!Asteroid.intersects(spaceship1) && Wall.inside(cordinate_y,cordinate_x) && (!spaceship1.intersects(spaceship2)))
                   {
     
                      y = cordinate_y;
                      x = cordinate_x;
     
                      //This checks and see if Player 1 hits Player 2 then the game ends
                      //if(Asteroid.intersects(spaceship2))
                         //System.exit(0);  
                   } 
     
     
     
     
     
     
    					  if(spaceship1.intersects(Finishline))
                   {
     
                   URL eng = this.getClass().getResource ("Sounds/ClappingCrowd.wav");
                   AudioClip snd = JApplet.newAudioClip(eng);               
    					snd.play();
     
     
                   JOptionPane.showMessageDialog(null,"CONGRATULATIONS!!\n\n" + "Player 1\n\n"+ "YOU PLACED FIRST");
     
                   System.exit(0);   
                   }
     
     
     
     
     
     
    						  if(spaceship2.intersects(Finishline))
                   {
     
                   URL eng = this.getClass().getResource ("Sounds/ClappingCrowd.wav");
                   AudioClip snd = JApplet.newAudioClip(eng);               
    					snd.play();
     
     
                   JOptionPane.showMessageDialog(null,"CONGRATULATIONS!!\n\n" + "Player 2\n\n"+ "YOU PLACED FIRST");
     
                   System.exit(0);   
                   }
     
     
     
     
     
     
                      if(Asteroid.intersects(spaceship1))
                   {
                       Velocity = 0;
    					    Velocity1 =0; 
     
                   URL eng = this.getClass().getResource ("Sounds/geardown.WAV");
                   AudioClip snd = JApplet.newAudioClip(eng);               
    					snd.play();
     
     
                   }
     
     
     
     
     
     
     
     
                //This Detects the Collision between the Walls of the race track and the two Space ships
                if(!Asteroid.intersects(spaceship2) && Wall.inside(cordinate_y0,cordinate_x0) && (!spaceship2.intersects(spaceship1)))
                {
     
                      y0 = cordinate_y0;
                      x0 = cordinate_x0;
     
                      //This checks and see if Player 2 hits Player 1 then the game ends
                      if(spaceship2.intersects(spaceship1))
                         System.exit(0);                       
                   }
     
     
     
     
     
                repaint();//Refresh the Screen
     
     
     
     
             }
     
          //Method to start the animation / Race    
          public void Start_Accelaration()
     
             {
             AnimationTimer = new Timer(40, this);
             AnimationTimer.start();
     
             }
     
     
     
     
     
     
     
     
     
       //Returns the minimum size of the animation  
           public Dimension getMinimumSize()
     
              { 
              return getPreferredSize(); 
              }
       //Ends getMinimumsize method
     
     
     
     
     
     
     
    	//Returns the preferred size of the animation
          public Dimension getPreferredSize()
     
              {
     
              return new Dimension( 850, 650); 
     
     
    			 }
     
     
     
     
     
     
     
       //end getPreferredsize method
    // Get Key pressed by user
       public void keyTyped(KeyEvent e)
       {
     
     
    		throw new UnsupportedOperationException("Not supported yet.");
     
     
    	}
     
     
     
       //Invoked when a key has been pressed.     
          public void keyPressed(KeyEvent e) 
              {
     
             int Code = e.getKeyCode();
              {  
     
    			 if(Code == KeyEvent.VK_R){
     
    				Restart_Accelaration();
     
     
    			 }
     
     
     
     
     
     
              //Player 2
     
                if (Code == KeyEvent.VK_I)//If Player 2 pressed I, Space ship speed increases by 10
                   {
     
     
    					URL eng = this.getClass().getResource ("Sounds/tirespin.wav");// This Loads the Sound Effect from the Directory and play it when I key is pressed
                   AudioClip snd = JApplet.newAudioClip(eng);
                   snd.play();
     
     
                      Velocity +=1;
     
     
                      if(Velocity1>10) 
     
                      Velocity1 = 10;
     
                   }
     
     
     
     
     
     
                if (Code == KeyEvent.VK_K)//If Player 2 pressed K, Space ship speed decreases by 10
                   {
                      Velocity -=1;
     
                         if(Velocity1<0) 
     
                         Velocity1 = 0;
     
                   }
     
     
     
     
     
     
                if (Code == KeyEvent.VK_L)//If Player 2 pressed L, Space ship turns 22.5 Degrees Right           
                   player2spaceship = (((player2spaceship+1)>16)? 1 : (player2spaceship+1));
     
     
     
     
     
                if  (Code == KeyEvent.VK_J)//If Player 2 pressed J, Space ship turns 22.5 Degrees Left
     
                   player2spaceship =  (((player2spaceship-1)<1)? 16 : (player2spaceship-1));
     
     
     
     
    				//Player 1
     
     
                if (Code == KeyEvent.VK_W)//If Player 1 pressed W, Space ship speed increases by 10
                   {
     
     
    					URL eng = this.getClass().getResource ("Sounds/tirespin.wav");// This Loads the Sound Effect from the Directory
                   AudioClip snd = JApplet.newAudioClip(eng);//Creating Instance of the Audio Clip
                   snd.play();
     
     
                     Velocity1 +=1;
     
                         if(Velocity1>10)
     
                          Velocity1 = 10;
     
                   }
     
     
     
     
     
     
                if (Code == KeyEvent.VK_S)//If Player 1 pressed S, Space ship speed decreases by 10
                   {
     
    					URL eng = this.getClass().getResource ("Sounds/geardown.wav");// This Loads the Sound Effect from the Directory
                   AudioClip snd = JApplet.newAudioClip(eng);//Creating Instance of the Audio Clip
                   snd.play();
     
     
                      Velocity1 -=1;
     
                         if(Velocity1<0)
     
     
     
                         Velocity = 0;
     
                   }
     
     
     
     
     
     
                if (Code == KeyEvent.VK_D)
     
                   player1spaceship = (((player1spaceship+1)>16)? 1 : (player1spaceship+1));//If Player 1 pressed D, Space ship turns 22.5 Degrees Right
     
     
                 if (Code == KeyEvent.VK_A)
     
                   player1spaceship =  (((player1spaceship-1)<1)? 16 : (player1spaceship-1));//If Player 1 pressed A, Space ship turns 22.5 Degrees Left
     
             }
         } 
     
     
     
     
     
     
       //Invoked when a key has been Released.
          public void keyReleased(KeyEvent e) 
          {
     
          }
       }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    SSCCE standards for Short, Self Contained, Correct Example. The post looks like the whole thing.

    For the networking part you won't need the whole thing.
    You should be able to write the message sending/receiving code without having to work with the game playing code. Design an interface in the game code to use the messaging done over the network.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    import java.io.*;
    import java.net.*;
     
    class TCPserver
    {
    public static void main(String args[]) throws Exception 
    {
    String line;
    String mySentence;
    ServerSocket service = new ServerSocket(5000);
     
    while(true)
    {
    Socket server = service.accept();
    BufferedReader is =
    new BufferedReader(new InputStreamReader(server.getInputStream()));
    DataOutputStream os = new DataOutputStream(server.getOutputStream());
    line = is.readLine();
    System.out.println("Received: " + line);
    mySentence = line.toUpperCase() + '\n';
    os.writeBytes(mySentence);
    }
    }
    }


    --- Update ---

     
    import java.io.*;
    import java.net.*;
     
    class TCPclient
    {
    public static void main(String argv[]) throws Exception
    {
    String sentence;
    String modifiedSentence;
     
    while (true)
    {
    BufferedReader is = new BufferedReader( new InputStreamReader(System.in));
    Socket clientSocket = new Socket("localhost", 5000);
    DataOutputStream os = new DataOutputStream(clientSocket.getOutputStream());
    BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    sentence = is.readLine();
    os.writeBytes(sentence + '\n');
    modifiedSentence = inFromServer.readLine();
    System.out.println("FROM SERVER: " + modifiedSentence);
    clientSocket.close();
    }
    }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Please edit the posted code and add proper indentations. The statements should NOT all start in the first column.
    Code inside {}s should be indented 3-4 spaces.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    ok.....i edited it

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    ok.....i edited it
    Where? What post? The code in Post #9 needs to be fixed.

    What was the purpose of posting the code in post#9?

    Are you working on a design for the communications between the client and the server?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    yes......code #9 is the client/server program i coded.....so i need u to help me to make the #9 work with #7 two clients should be able to control their space ship over a network in realtime while both players can see the movement of each other's spaceships........

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    What design items do you have so far for the communications between the client and the server?
    The code in post#7 will have to be rewritten to work with the network code.
    The networking code will NOT be part of the code in post#7.
    The classes and methods for the networking will be used by #7.
    There will be special drivers written to test the networking code before integrating it with #7
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    what kind of drivers Norm? i normally run the client/server program from Command prompt in Windows......run the server first then client.....and then they both send/receive message vice versa........and what part of post #7 will have to be rewritten ?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    The drivers are simple programs to send and receive fixed messages for testing the network code. They would not be used after the testing.

    what part of post #7 will have to be rewritten
    The part that gets the input from the network instead of from a local user at the keyboard.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    ok.....i get it......
     public void keyPressed(KeyEvent e) 
              {
     
    }

    please point me to the right direction.....give me some guides or examples

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    What does the program need to get through the network communications to play the game?
    What response does the program need to make to a message received from the other player?

    For example:
    player1 moves his ship to x,y
    player2 says close but no damage
    player2 moves his ship to x,y
    player1 says you got me.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Firstly I know coordinates is probably the wrong terminology? I'd assume i'd simply be passing the x and y variables, but coordinates describe it better I feel.

    Now I need to have a Server which can be accessed by 2 clients, it is a racing game and it requires each client to be able to maneuver a racecar simultaniously, each using a different control scheme but that's neither here nor there.

    I was hoping you would be able to assist me when it came to sending the x and y positions of a racecar to the server and having the server send them onto the next player and vice versa to allow both racecars to move at the same time on each clients window. So far i've only done the simple server stuff, such as the knock knock server on the sun website, and a simple echo server which repeats a string I send to the server.

    When I tried to use int instead of string I recieved an error that the int I wanted to pass was dynamic (obviously changes with each movement) and cannot be passed as static (using readInt and writeInt).

    So any help on how to create the wanted movement on both client windows through the server would be appreciated.

    Thanks

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Are you saying that the only thing a client sends to the server and the other client is two values: x and y?

    Have you designed and written any code yet?

    I recieved an error
    Please post the full text of the error message and the code. The code should be in separate classes with simple testing drivers to send and receive the data and show that is was sent and received.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    is not only X and Y........the space ship (player 1 ) is driven with W,A,S,D keys W to accelerate......A to turn left......S to decelerate....and D to turn right............so the objective now is to create a one Server to host two Client......the Server receives the keystroke from Client one and then send it to Client two and vice versa.....while the both Clients can see the movement of each other in realtime.......i did some research today i realised this can be done with "Serialisation " but i don't know how to implement that......i really need some help with this Norm...........

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    First decide what data needs to be sent between the clients and the work on how to send it.
    Sending Strings is easier to debug. What information needs to be sent?
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    The Server should be able to send ( co-ordinates, space ship crash and exit communications; concurrent controls)

    --- Update ---

    which i believe they are all integers.....

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    Would the int values need any description? if "30,444" is sent, would the receiver know what that meant?
    Or would there need to be a descriptor: "moveTo 30,444"
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Mar 2013
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: 2D JAVA GAME TCP SERVER/CLEINT SUPPORT HELP?

    these are the two codes i want them to be serialized between the two clients through the server

     
     int cordinate_x = x;
                int cordinate_y = y;
                int cordinate_x0 = x0;
                int cordinate_y0 = y0;
     
                //Move the Space ship forward base on the direction its facing
                if(player1spaceship == 1)
     
                { 
     
                cordinate_x -=Velocity1;
     
                }
     
     
     
                else  if(player1spaceship == 5)
                { 
     
                cordinate_y +=Velocity1; 
     
                }






     
    * * * * * *if (Code == KeyEvent.VK_K)//If Player 2 pressed K, Space ship speed decreases by 10
    * * * * * * * *{
    * * * * * * * * * Velocity -=1;
    * * * * * * * * **
    * * * * * * * * * * *if(Velocity1<0)*
    * * * * * * * * **
    * * * * * * * * * * *Velocity1 = 0;
    * * * * * * * * **
    * * * * * * * *}

Page 1 of 2 12 LastLast

Similar Threads

  1. Handling TCP and UDP in same server
    By ToshX in forum Java Networking
    Replies: 2
    Last Post: December 2nd, 2011, 03:19 PM
  2. TCP/IP java client, c++ server
    By akboyd88 in forum Java Networking
    Replies: 0
    Last Post: March 24th, 2011, 10:46 AM
  3. Replies: 0
    Last Post: February 24th, 2011, 06:31 AM
  4. Replies: 1
    Last Post: September 30th, 2010, 02:36 PM
  5. TCP Client Server: Object Oriented
    By nffc luke in forum Object Oriented Programming
    Replies: 2
    Last Post: April 28th, 2010, 06:39 PM

Tags for this Thread