Здравствуйте форумчане хотел бы у вас спросить что я не так сделал?Я хотел написать чтобы спрайт ставился на те координаты которые я передам, но для начала просто сообщение послываю но оно не работает
Вот код:
Код
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
public class Game extends BasicGame {
public Game(String title) { super(title); }
static String Message;
static int port = 65534;
static String line;
static DataInputStream in;
static DataOutputStream out;
public static void main(String[] args) throws SlickException, IOException
{
AppGameContainer app = new AppGameContainer(new Game("Test Game"));
app.setDisplayMode(1440, 900, false);
app.start();
}
@Override
public void render(GameContainer container, Graphics g) throws SlickException
{
g.drawString("Message : "+line, 0, 20);
}
@Override
public void init(GameContainer container) throws SlickException
{
try
{
ServerSocket ss = new ServerSocket(port);
Socket socket = ss.accept();
System.out.println("Client connected!");
InputStream sin = null;
sin = socket.getInputStream();
OutputStream sout = null;
sout = socket.getOutputStream();
in = new DataInputStream(sin);
out = new DataOutputStream(sout);
line = null;
}
catch (IOException e)
{
e.printStackTrace();
}
}
@Override
public void update(GameContainer container, int delta) throws SlickException
{
try {
line = in.readUTF();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Это клиент
Код
import java.net.*;
import java.io.*;
public class Client {
public static void main(String[] ar)
{
int serverPort = 65534;
String address = "127.0.0.1";
try
{
InetAddress ipAddress = InetAddress.getByName(address);
System.out.println("Any of you heard of a socket with IP address " + address + " and port " + serverPort + "?");
Socket socket = new Socket(ipAddress, serverPort);
System.out.println("Yes! I just got hold of the program.");
InputStream sin = socket.getInputStream();
OutputStream sout = socket.getOutputStream();
DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
String line = null;
System.out.println("Type in something and press enter. Will send it to the server and tell ya what it thinks.");
System.out.println();
while (true)
{
line = keyboard.readLine();
System.out.println("Sending this line to the server...");
out.writeUTF(line);
out.flush();
line = in.readUTF();
System.out.println("The server was very polite. It sent me this : " + line);
System.out.println("Looks like the server is pleased with us. Go ahead and enter more lines.");
System.out.println();
}
}
catch (Exception x)
{
x.printStackTrace();
}
}
}
Добавлено (08.01.2013, 21:43)
---------------------------------------------
Игра падает
Добавлено (08.01.2013, 22:42)
---------------------------------------------
Использую SLICK2D
Добавлено (09.01.2013, 14:13)
---------------------------------------------
Я так понял помочь некому....