elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 01:27  


Tema destacado: Últimos eventos sobre seguridad/inseguridad

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java (Moderadores: Debci, Leyer)
| | | |-+  Ayuda con sockets
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con sockets  (Leído 189 veces)
delirio

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Ayuda con sockets
« en: 24 Agosto 2011, 05:15 »

Alguien podria ayudarme a como implementar sockets a este codigo, he intentado pero no me sale.....necesito implementar el cliente y servidor....h


Código
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
 
 
public class Main extends JFrame
{
 
   // Ancho y alto de la ventana
   public static final int ANCHO = 600;
   public static final int ALTO  = 350;
 
   // Constantes
   public final int PLAYER_VS_PLAYER = 0;
   public final int PLAYER_VS_COMP   = 1;
 
   // Controlador de pantallas
   private Pantallas pantallas;
 
   // Las paletas
   private Paleta paleta1;
   private Paleta paleta2;
 
   // La pelota
   private Pelota pelota;
 
   // El marcador
   private Marcador marcador;
 
 
   /***************************************************************************
    ***************************     INICIALIZAR     ***************************
    ***************************************************************************/

 
   public static void main(String[] args) { new Main(); }
 
   public Main()
   {
       // Comprobamos que las imágenes estén en su sitio
       Archivos.comprobarRutaImagenes();
 
       // Propiedades de la ventana
       this.setTitle("Pong!");
       this.setDefaultCloseOperation(EXIT_ON_CLOSE);
       this.setSize(ANCHO, ALTO+20); // +20 por el borde de la ventana
       this.setLocation(150,150);
       this.setResizable(false);
 
       // Listeners del teclado
       this.addKeyListener(new KeyAdapter(){
           public void keyPressed(KeyEvent evt) {
               formKeyPressed(evt);
           }
           public void keyReleased(KeyEvent evt) {
               formKeyReleased(evt);
           }
       });
 
       // Creamos el controlador de pantallas
       pantallas = new Pantallas();
 
       this.setVisible(true);
   }
 
   private void iniGame(int tipoJuego)
   {
       pantallas.setFalse();
       pantallas.pantallaJuego = true;
 
       if (tipoJuego == PLAYER_VS_PLAYER)
       {
           paleta1 = new Paleta(Paleta.MANEJA_PLAYER, Paleta.PLAYER1);
           paleta2 = new Paleta(Paleta.MANEJA_PLAYER, Paleta.PLAYER2);
       } else {
           paleta1 = new Paleta(Paleta.MANEJA_PLAYER, Paleta.PLAYER1);
           paleta2 = new Paleta(Paleta.MANEJA_MAQUINA, Paleta.PLAYER2);
       }
 
       pelota = new Pelota(ANCHO/2-Pelota.anchoImagen/2, ALTO/2-Pelota.altoImagen/2);
 
       marcador = new Marcador();
   }
 
 
   /***************************************************************************
    ***************************     LEER TECLADO    ***************************
    ***************************************************************************/

 
   public void formKeyPressed(KeyEvent evt)
   {
           // Selección Player vs Player o Player vs Computer
           if (evt.getKeyCode() == KeyEvent.VK_1 && pantallas.pantallaPrincipal == true)
                   this.iniGame(PLAYER_VS_PLAYER);
 
           if (evt.getKeyCode() == KeyEvent.VK_2 && pantallas.pantallaPrincipal == true)
                   this.iniGame(PLAYER_VS_COMP);
 
           // Mover paletas
           if (pantallas.pantallaJuego == true)
           {
               paleta1.keyPressed(evt);
               paleta2.keyPressed(evt);
           }
 
   }
 
   public void formKeyReleased(KeyEvent evt)
   {
       // Mover paletas
       if (pantallas.pantallaJuego == true)
       {
           paleta1.keyReleased(evt);
           paleta2.keyReleased(evt);
       }
   }
 
 
   /***************************************************************************
    ***************************       DIBUJAR       ***************************
    ***************************************************************************/

 
   public void dobleBuffer(Graphics2D g2)
   {
 
       /***********************
        ******  CHOCAR   ******
        ***********************/

       if (pantallas.pantallaJuego == true)
       {
           // Pelota <=> Paleta 1
           if (paleta1.getRectangulo().intersects(pelota.getRectangulo())==true)
           {
               if (paleta1.abajo==true)
                   pelota.setDireccion(Pelota.PALETA1, Pelota.DIR_PALETA_ABAJO);
               if (paleta1.arriba==true)
                   pelota.setDireccion(Pelota.PALETA1, Pelota.DIR_PALETA_ARRIBA);
               if (paleta1.abajo==false && paleta1.arriba==false)
                   pelota.setDireccion();
           }
 
           // Pelota <=> Paleta 2
           if (paleta2.getRectangulo().intersects(pelota.getRectangulo())==true)
           {
               if (paleta2.abajo==true)
                   pelota.setDireccion(Pelota.PALETA2, Pelota.DIR_PALETA_ABAJO);
               else if (paleta2.arriba==true)
                   pelota.setDireccion(Pelota.PALETA2, Pelota.DIR_PALETA_ARRIBA);
               else if (paleta2.abajo==false && paleta2.arriba==false)
                   pelota.setDireccion();
           }
       }
 
       /***********************
        ******   MOVER   ******
        ***********************/
 
       if (pantallas.pantallaJuego == true)
       {
           paleta1.mover(pelota.posY);
           paleta2.mover(pelota.posY);
 
           // Comporbamos los goles
           int n = pelota.mover();
 
           if (n!=Pelota.NO_GOL)
           {
               marcador.addPunto(n);
               pelota.setCentrada();      
               try{ Thread.sleep(1000); } catch(Exception e) {}
           }
       }
 
       /***********************
        ******  DIBUJAR  ******
        ***********************/
       
       pantallas.dibujar(g2);
       if (pantallas.pantallaJuego == true)
       {
           paleta1.dibujar(g2);
           paleta2.dibujar(g2);
           pelota.dibujar(g2);
           marcador.dibujar(g2);
       }
 
       try{ Thread.sleep(10); }catch(Exception e) {}
       repaint();
   }
 
   public void paint(Graphics g)
   {
       Graphics2D g2 = (Graphics2D) g;
 
       Image mImage = createImage(ANCHO, ALTO);
       dobleBuffer((Graphics2D)mImage.getGraphics());
 
       g2.drawImage(mImage, 0, 20, this);
   }
 
}
 







En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con Sockets
Programación C/C++
falcatin 6 739 Último mensaje 17 Agosto 2006, 00:27
por Ole
Ayuda con sockets
PHP
[KMT] 2 557 Último mensaje 30 Abril 2007, 02:10
por дٳŦ٭
Ayuda con Sockets
Programación C/C++
ella. 4 592 Último mensaje 19 Marzo 2010, 06:56
por Littlehorse
Ayuda Sockets en C
Programación C/C++
sinsombra_666 2 799 Último mensaje 25 Septiembre 2010, 14:27
por sinsombra_666
Ayuda con Sockets
Programación Visual Basic
Elemental Code 2 564 Último mensaje 25 Enero 2011, 21:06
por ::: Devil :::
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines