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

📄 chessroom.java~58~

📁 手机端游戏开发程序
💻 JAVA~58~
字号:
package chess;

public class ChessRoom
{
  static int LEFT = 0;
  static int RIGHT = 1;
  static int N = 4; //房间里面的桌子数
  static String TableInfo[];
  ChessTable tables = new ChessTable(N);
  String Info;

  public ChessRoom()
  {

    TableInfo = new String[N];
    for (int i = 0; i < N; i++)
    { //初始化大厅中的桌子信息
      TableInfo[i] = "00"; //00代表桌子左右两边都没坐人
    }
    Info = this.getTableInfo();
    //System.out.println("大厅出世信息"+Info);
  }
  public int size(){
    return N;
  }

/*  public boolean setTableBusy(int i)
  {
    if (TableInfo[i].equals("11"))
    {
      TableInfo[i] = "22";
      Info = this.getTableInfo();
      return true;
    }
    Info = this.getTableInfo();
    return false;
  }
*/
  public String leaveTable(String uname, int i) //return the side where the man leave  0=left  ;  1=right
  {
    if ( (tables.getName(i, 0)).equals(uname))
    { //if sits left
      TableInfo[i - 1] = "00";
      tables.sitLeft(i, "#");
      tables.sitRight(i, "#"); //set left and right empty
      //return "OK";
      return tables.getName(i, 1);
    }
    else if ( (tables.getName(i, 1)).equals(uname))
    { //if sits right
      TableInfo[i - 1] = "00";
      tables.sitLeft(i, "#");
      tables.sitRight(i, "#"); //set right empty
      return tables.getName(i, 0);
    }
    return "#";
  }

  public String isFull(int i)
  { //判断i号桌子是否已经做满
    //i--;
    //System.out.print(TableInfo[i]);
    if (TableInfo[i - 1].equals("11"))
    { //桌子两边都做了人
      String left = tables.getName(i, LEFT);
      String right = tables.getName(i, RIGHT);
      //通知左边的人先走棋
      // System.out.println(i+"桌子满了"+left + "." + right);
      return left + "." + right+"."; //如果i号桌子坐满了人,返回坐的人的id和桌子号
    }
    else
    {
      return "#";
    }

  }

  public boolean userSit(String uname, int chair)
  {
    int i;
    if(chair%2==1) i=chair/2+1;//将作为号变成桌子号
        else i=chair/2;
    if (!tables.isFull(i))
    {
      if (chair % 2 != 0)
      {
        if (tables.sitLeft(i, uname))
        {
          if (TableInfo[i - 1].equals("00"))
          {
            TableInfo[i - 1] = "10";
          }
          else
          {
            TableInfo[i - 1] = "11";
          }
        }
        Info = this.getTableInfo();
        return true;
      }
      else
      if (chair % 2 == 0)
      {
        if (tables.sitRight(i, uname))
        {
          if (TableInfo[i - 1].equals("00"))
          {
            TableInfo[i - 1] = "01";
          }
          else
          {
            TableInfo[i - 1] = "11";
          }
        }
        Info = this.getTableInfo();
        return true;

      }

    }
    return false;
  }

  public String getTableInfo()
  {
    String tf = TableInfo[0];

    for (int i = 1; i < N; i++)
    {
      tf +=TableInfo[i];
    }
    return tf;

  }
/*
  public void updateTableInfo(String tf)
  {
    int start = 0;
    int end = 2;
    for (int i = 0; i < N; i++)
    {

      TableInfo[i] = tf.substring(start, end);
      start += 3;
      end += 3;
    }
  }*/

}

⌨️ 快捷键说明

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