t.image.BufferedImage;java.io.DataInputStream;java.io.DataOutputStream;java.io.IOException;java.ServerSocket;java.Socket;javax.swing.JFrame;javax.swing.JOptionPane;class CreateServer extends Canvas implements Runnable, KeyListener {static final long serialVersionUID=1L; b; out; in; serverSocket; socket; serverPort; frame; width=600; height=400; final Dimension gameDim=new Dimension (width, height); image =new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB); pWidth=15; pHeight=45; xPos; yPos; cXPos; int cYPos; moveUp=false; moveDown=false; serverRect; clientRect; serverScore=0; clientScore=0; int ticks=0; int frames=0; int FPS=0; int UPS=0; double delta; limitFrameRate=false; shouldRender; void requestInformation () {{= Integer.parseInt (JOptionPane.showInputDialog ( Який порт задіяти? (переконайтеся, що він відкритий) ));
} catch (Exception e) {.printStackTrace ();
}
} void run () {lastTime=System.nanoTime (); nsPerTick=1000000000D/60D; lastTimer=System.currentTimeMillis ();=0D; (true) {now=System.nanoTime () ; +=(now - lastTime)/nsPerTick;=now;=false; (delta gt;=1) {++; (); -=1;=true;
} (! limitFrameRate amp; amp; ticks gt; 0)=true; (shouldRender) {++; ();
} (System.currentTimeMillis () - lastTimer gt;=1000) {+=1000;=frames;=ticks;=0;=0;
}
}
} void createFrame () {(gameDim); (gameDim); (gameDim);=new JFrame ( Сервер ) ;. setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) ;. setLayout (new BorderLayout ( )) ;. add (this, BorderLayout.CENTER) ;. pack () ;. setResizable (false) ;. setLocationRelativeTo (null) ;. setVisible (true);=15;=frame.getHeight ()/2 - pHeight; =frame.getWidth () - pWidth - 15;=frame.getHeight ()/2 - pHeight;=new Rectangle (xPos, yPos, pWidth, pHeight);=new Rectangle (cXPos, cYPos, pWidth, pHeight);=new Ball (this); (this); (); thread=new Thread (this) ;. start ();
} void handShake () {{= new ServerSocket (serverPort);=serverSocket.accept (); (out == null || in == null) {= new DataOutputStream (socket.getOutputStream ( ));=new DataInputStream (socket.getInputStream ());
} cp=new ConnectedPlayer (out, in); userThread=new Thread (cp) ;. out.println ( Користувач підключений ) ;. start ();
} catch (IOException e) {.printStackTrace ();
}
} CreateServer () {(); (); ();
} void movement () {(moveUp amp; amp; yPos gt; 0) {-=3;
} (moveDown amp; amp; yPos + pHeight lt; getHeight ()) {+=3;
}
} void tick () {() ;. setBounds (xPos, yPos, pWidth, pHeight) ;. setBounds (cXPos, cYPos, pWidth, pHeight);.tick();{.writeInt(b.x);.writeInt(b.y);.writeInt(yPos);.writeInt(serverScore);.writeInt(clientScore);
} catch (Exception e) {}
} void render () {bs=getBufferStrategy (); (bs == null) {(3) ;;
} g=bs.getDrawGraphics () ;. drawImage (image, 0, 0, getWidth (), getHeight (), null) ;. setColor (Color.WHITE) ;. fillRect (xPos, yPos, pWidth, pHeight) ;. fillRect (cXPos, cYPos, pWidth, pHeight) ;. render (g) ;. drawString ( Рахунок гравця 1: + serverScore, 40, 10) ;. drawString ( Рахунок гравця 2: + clientScore, getWidth () - 105, 10) ;. dispose () ;. show ();
} void keyPressed (KeyEvent e) {(e.getKeyCode () == KeyEvent.VK_W) {= true;
} (e.getKeyCode () == KeyEvent.VK_S) {= true;
}
} void keyReleased (KeyEvent e) {(e.getKeyCode () == KeyEvent.VK_W) {= false;
} (e.getKeyCode () == KeyEvent.VK_S) {= false;
}
} void keyTyped (KeyEvent e) {
}
}