日期:2014-05-20  浏览次数:20749 次

求小游戏代码
   我是一个刚接触JAVA的新手,只懂一些简单的语句和语法,看的懂一些小程序,希望哪为好心人给点小游戏代码可以参考参考。另外如果可以的话给点大型程序的构建的思路。不胜感激。
------解决方案--------------------
网上有好多的,比如:俄罗斯方块、贪吃蛇、坦克大战等等的,你下下来看看
------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;


public class ChatCliend{

public static void main(String[] args){
MyFrame mf=new MyFrame();
mf.launchFrame();

}
}
class MyFrame extends Frame{

TextField text;

TextArea text2;
Socket s;
DataOutputStream dos=null;
DataInputStream dis=null;
boolean on = false;

public void launchFrame(){
this.setLocation( 400, 100);
this.setSize(320, 500);
text=new TextField(10);
text2=new TextArea(100,1);
text.addActionListener(new TextMonitor());
add(text,BorderLayout.SOUTH);
add(text2,BorderLayout.CENTER);
this.addWindowListener(new WindowMonitor());
this.setVisible(true);
net();
new Thread(new Server()).start();
}

//此方法联网
public void net (){

try {
s= new Socket("10.50.140.53",8888);
dos= new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
on=true;
text2.setText("亲,您已经连接到服务器了,可以和您的朋友聊天了  "+'\n');
} catch (UnknownHostException e) {

text2.setText("亲,您没有成功连接到服务器了 ,请与杨圣博联系... ");

} catch (IOException e) {

text2.setText("亲,您没有成功连接到服务器了 ,请与杨圣博联系... ");

}
}

//把内容发送给服务器
public  void sent(String str){

try {
dos.writeUTF(str);
dos.flush();
} catch (IOException e) {

e.printStackTrace();
}
}

//这个类用于监听text的行为,给予一定的响应。然后把内容发送给服务器
public class TextMonitor implements ActionListener{

//本地处理text中的内容 然后调用sent方法  把他发送给服务器
public void actionPerformed(ActionEvent e){

String str=text.getText().trim();
text.setText("");
sent(str);

}
}

//这个类用于窗口的关毕
class WindowMonitor extends WindowAdapter{
public void windowClosing(WindowEvent e){
off();
System.exit(0);
}
}

//用于起一个多线程  
class Server implements Runnable{


public void run(){
try {
while(on){
String s1=dis.readUTF();
text2.setText(text2.getText()+'\n'+s1+'\n');
}
} catch (IOException e) {

}
}
}
public void off(){
try {
if(s!=null)s.close();
if(dis!=null)dis.close();
if(dos!=null)dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

------解决方案--------------------
上面的是客户端
mport java.io.*;
  import java.net.*;
  import java.nio.CharBuffer;
  import java.util.*;


public class ChatServer {
ServerSocket ss=null;
Socket s=null;
boolean on =false;
List<Client> clients=new ArrayList<Client>();

public static void main(String[] args) {