⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analysemsg.java~392~

📁 手机端游戏开发程序
💻 JAVA~392~
📖 第 1 页 / 共 2 页
字号:
package chess;

import java.net.URL;
import javax.swing.ImageIcon;

//刘超飞修改于2005年7月25号,加入三四桌的处理
public class AnalyseMsg
{
  String username, second, third; //解析字符串得到的值
  //  static ChessRoom cr ;//= new ChessRoom();
  //××××××××××××××××××××××××××××××××××××××××××××××
//此处为加入三四桌多人协同游戏补加变量,所有对象公用这些变量
  private static int chair_user_num = 0; //代表桌上的人数
  private static String[] group_user_name =
      {
      "qq", "dover", "zhao", "zhsn"};
  private static String message_received;

  private static String qq_chess;
  private static String dover_chess;
  private static String zhao_chess;
  private static String zhsn_chess;
  private static int count_group1 = 0;
  private static int count_group2 = 0;
  private static String user_send;
  private static String feed_back;
//××××××××××××××××××××××××××××××××××××××××××××××
//协同可视化变量
public static  VisualCoordinate vc;
  URL u1 = this.getClass().getResource("/image/d1.gif");
  URL u2 = this.getClass().getResource("/image/d2.gif");
  URL u3 = this.getClass().getResource("/image/d3.gif");
  URL u4 = this.getClass().getResource("/image/d4.gif");
  URL u5 = this.getClass().getResource("/image/d5.gif");
  URL u7 = this.getClass().getResource("/image/P4.PNG");
  URL u8 = this.getClass().getResource("/image/P5.PNG");

  URL u6=this.getClass().getResource("/image/P1.PNG");


  public  ImageIcon  user_icon=new ImageIcon(u6);

  public ImageIcon transfer_left_icon = new ImageIcon(u2);
  public ImageIcon transfer_right_icon = new ImageIcon(u1);
  public ImageIcon broadcast_icon = new ImageIcon(u3);
  public ImageIcon gather_icon = new ImageIcon(u4);
  public ImageIcon coordinate_icon = new ImageIcon(u5);
  public ImageIcon user_act_icon = new ImageIcon(u7);
  public ImageIcon user_stop_icon = new ImageIcon(u8);

  MainFrame mf;
  public AnalyseMsg(String s, ThreadPool Queue, MainFrame mf, ChessRoom cr)
  { //s一般格式为:from.to.message--<
    this.mf = mf;
    message_received = s;
    MessageClass mc = new MessageClass(s, '.');
    username = mc.first; //第一部分肯定是username
    second = mc.second; //根据第二部分判断
    third = mc.third;
    System.out.println("用户名" + username);
    System.out.println(message_received);

    System.out.println(second);
    System.out.println(third);
    // Queue = Queue;
    int tag = 0;
    if (second.equals("#"))
    {
      tag = 1; //如果是和电脑下棋
      if (third.equals("mode:single"))
      {
        this.SendOneMsg("wzq.#." + username + ".single start");
        tag = 0;
      }
      else if (third.equals("mode:vs"))
      {
        this.SendOneMsg("wzq.#." + username + ".vs start");
        tag = 0;
      }
      else if (third.equals("Win"))
      {
        tag = 0;
        int seat = Queue.getUList().indexOf(username);
        Queue.getUList().remove(seat); //移出该用户
      }

    }
    else if (second.equals("#sit#"))
    {
      tag = 2; //如果是在某人来了,等待或与一等待的人直接开始
    }
    else if (second.equals("#leave#"))
    {
      tag = 3; //如果是离开某桌子
    }
    else if (second.equals("#getRoom#"))
    { //在否则,second就是另一个客户的id了
      tag = 4;
    }
    else if (second.equals("#updateRoom#"))
    {
      tag = 5;
    }
    else tag = 6;

    switch (tag)
    {
      case 1: //*人机下:1111.#.3.4	//A在3,4落子
        int index = -1;

        //mf.log.AddLine("用户名是:" + username);
        mf.log.AddLine("用户名是:" + username);
        if (Queue.capacity() > 0)
        { //如果用户列表不空,作查找
          index = Queue.getIndex(username); //查找用户所在位置
        }
        if (index < 0)
        { //如果没找到,则添加
          mf.log.AddLine("列表中没有该用户,添加:" + username);
          index = Queue.addUser(username); //index是刚添加进来的元素的下标
        }

        //将消息传给指定的线程
        //从消息中提取用户的x和y
        mf.log.AddLine("用户:" + username + "在列表中的位置是" + index);

        //mf.log.AddLine(third + ". ");

        MessageClass temp = new MessageClass(third + ". ");

        int x = new Integer(temp.first).intValue();
        int y = new Integer(temp.second).intValue();

        mf.log.AddLine("传入的坐标是:" + x + "," + y);
        ChessCompute now = Queue.getThreadAt(index); //从线程池里面找到需要的线程
        now.setInput(x, y);
        mf.log.AddLine("计算开始");
        now.run();
        mf.log.AddLine("计算完毕");
        x = now.getBestX();
        y = now.getBestY();

        System.out.println("这是单机版做的");

        mf.log.AddLine("传出的坐标将是:" + x + "," + y);

        //此处为单人游戏发送棋盘信息
        SendOneMsg("wzq.#." + username + ".POT:" + new Integer(x).toString() +
                   "." +
                   new Integer(y).toString()); ////给服务器的反馈
        break;
      case 2: //1111.#come#.3
        int chairid = new Integer(third).intValue();

        cr.userSit(username, chairid); //用户坐在在座位上
        int tableid;
        if (chairid % 2 == 1)
        {
          tableid = chairid / 2 + 1; //将坐位为号变成桌子号
        }
        else
        {
          tableid = chairid / 2;
        }

        //System.out.println(cr.isFull(tableid).equals("#"));
        if (! (cr.isFull(tableid).equals("#")) && tableid < 3) //此处为
        {
          String rt = cr.isFull(tableid);
          MessageClass amc = new MessageClass(rt);
          String left = amc.first;
          String right = amc.second;

          System.out.println("wzq.#connect#." + cr.isFull(tableid));

          SendOneMsg("wzq.#connect#." + right + ".USER:" + left);
          SendOneMsg("wzq.#connect#." + left + ".USER:" + right); //坐满了   通知服务器让两个用户建立连接
          //
          mf.log.AddLine(cr.isFull(tableid) + "坐在了" + tableid + "号桌,准备开始游戏");
          for (int i = 0; i < 2; i++)
          {
            cr.TableInfo[i] = "00"; //此处把两个人的大厅信息去掉
          }
        }
        else if ( (cr.isFull(tableid).equals("#") && tableid < 3))
        {
          //前两桌对战游戏
          System.out.println("wzq.#wait#." + username);
          SendOneMsg("wzq.#wait#." + username); //没坐满   让座好的人等待
          mf.log.AddLine(username + "坐在了" + tableid + "号桌,等待另一用户的加入");
        }
        else if (chair_user_num == 3)
        {
          //这里发送准备好信息,即四个人集齐的时候,通知开始下棋
          SendOneMsg("wzq.#connect#." + "qq" + ".USER:" +
                     "zhao");
          SendOneMsg("wzq.#connect#." + "dover" + ".USER:" +
                     "zhsn");
          SendOneMsg("wzq.#connect#." + "zhsn" + ".USER:" +
                     "dover");
          SendOneMsg("wzq.#connect#." + "zhao" + ".USER:" + "qq");
          mf.log.AddLine(group_user_name[0] + group_user_name[1] +
                         group_user_name[2] + username +
                         "坐在了" + tableid + "号桌,准备开始游戏");
          //调用协同可视化窗口
          vc = new VisualCoordinate();
          vc.setVisible(true);
        }
        else
        { //没坐满时等其它认得到来//把群组用户列表发送过去//用户规定死
          System.out.println("wzq.#wait#." + username);
          // group_user_name[chair_user_num] = username;
          chair_user_num++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -