毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 论文 >> 正文

J2ME基于手机平台的智能客户端游戏设计 第9页

更新时间:2007-11-14:  来源:毕业论文

一、连接服务器端代码:

1,客户端首先进行初始化:

public boolean initNet() {

                   try { // 打开两个连接(一个上一个下),并使它们联结

                            sc = (SocketConnection) Connector.open(url);

                            System.out.println("cnnect to server...");

                            io_is = sc.openInputStream();

                            io_os = sc.openOutputStream();                          

                            return true;

                   } catch (Exception e) {

                            netWork = false ;

                            System.out.println(e.getMessage() + "初始化网络错误");

                            return false;

                   }

         }

       2,与服务器端进行发包收包动作:

public void sendMessage(String str) {

                   try {

                            os.write(str.getBytes());

                            os.write("\r\n".getBytes());

                   } catch (IOException ioe) {

                            ioe.printStackTrace();

                   }

         }

        

public InputStream getMessage(){

                   try{

                            is.read();

                   }catch(Exception e){

                            System.out.println("null message");

                            e.printStackTrace();

                   }

                   return is;

         }

public synchronized void run() {

                   System.out.println("run send");

                   while (true) {

                            // If no client to deal, wait until one connects

                            if (message == null) {

                                     try {

                                               wait();

                                     } catch (InterruptedException e) {

                                     }

                            }

                            if (message == null) {

                                     break;

                            }

                            try {

                                     os.write(message.getBytes());

                                     os.write("\r\n".getBytes());

                            } catch (IOException ioe) {

                                     ioe.printStackTrace();

                            }

                            // Completed client handling, return handler to pool and

                            // mark for wait

                            message = null;

                   }

         }

二、运行游戏的代码:

public void run() {             

                            if (start1 && first) {

                                     System.out.println("start1 and first");

                                     Random rand = new Random();

                                     int count;

                                     for (int i = 0; i < 14; i++) {

                                               // 拿牌

                                               if (mah[0][0][i] == 0) {

                                                        // 随机取牌添加到最后

                                                        do {

                                                                 count = abs(rand.nextInt() % 136);

                                                        } while (initmah[count] == 0);

                                                        initmah[count] = 0;

                                                        if (count < 108) {

                                                                 mah[0][0][i] = count % 9 + 1;

                                                        } else {

                                                                 mah[0][0][i] = (count - 108) % 7 + 1;

                                                        }

                                                        mah[0][1][i] = count / 36;

                                                        if (mah[0][0][i] == magic1 && mah[0][1][i] == magic2) {

                                                                 mah[0][0][i] = -1;

                                                                 mah[0][1][i] = 0;

                                                        }

                                                        if (mah[0][0][i] == 7 && mah[0][1][i] == 3) {

                                                                 mah[0][0][i] = magic1;

                                                                 mah[0][1][i] = magic2;

                                                        }

                                                        mahcount--;

                                                        break;

                                               }

                                     }

                                     // 进行胡牌判断,还应该进行杠判断

                                     // 如果可以胡了的话,提示可以胡了

                                     winnum = win(0);

                                     if (winnum > 0) {

                                               eat1 = 6;

                                     }

                                     first = false;}

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] 

J2ME基于手机平台的智能客户端游戏设计 第9页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。