Esempio n. 1
0
    // 匹配成功时,自动调用 onResync 方法
    protected override void onResync(byte fromIndex)
    {
        // 同步玩家的 名字
        {
            Debug.Log(GameManager.nickname);

            // 交换名字,头像,握手
            {
                Hashtable values = new Hashtable();
                values.Add("name", "handshake");
                values.Add("v", GameManager.nickname);
                values.Add("ImgStr", HeadManager.ImgStr);

                GobangClient.send(GameSerialize.toBytes(values));
            }

            // 先进入房间的玩家 为红方
            string chess = "";
            if (getInt("client-index") == 0)
            {
                chess = "红方";
            }
            else
            {
                chess = "黑方";
            }

            GameObject Player = GameObject.Find("PlayerName");
            UILabel    label  = Player.GetComponent <UILabel>();
            label.text = GameManager.nickname + " (" + chess + ")";
        }
    }
Esempio n. 2
0
    //拒绝悔棋
    public void DisAgree()
    {
        //发送回答
        Hashtable values = new Hashtable();

        values.Add("name", "piece");
        values.Add("FromX", -1);
        values.Add("FromY", -1);
        values.Add("ToX", -1);
        values.Add("ToY", -1);
        values.Add("Move", "str");
        values.Add("YidongOrChizi", "YidongOrChizi");
        values.Add("Regame", 0);
        values.Add("GoBack", 0);//申请悔棋,0不申请不同意,1申请,2同意

        GobangClient.send(GameSerialize.toBytes(values));
        gameObject.transform.parent.gameObject.SetActive(false);

        //拒绝悔棋开始计时
        TimeManager TM;
        GameObject  obj = GameObject.Find("Timer") as GameObject;

        TM           = obj.GetComponent <TimeManager>();
        TM.bStartCul = true;
    }
Esempio n. 3
0
    //同意悔棋
    public void Agree()
    {
        //发送回答
        Hashtable values = new Hashtable();

        values.Add("name", "piece");
        values.Add("FromX", -1);
        values.Add("FromY", -1);
        values.Add("ToX", -1);
        values.Add("ToY", -1);
        values.Add("Move", "str");
        values.Add("YidongOrChizi", "YidongOrChizi");
        values.Add("Regame", 0);
        values.Add("GoBack", 2);//申请悔棋,0不申请不同意,1申请,2同意
        // 悔棋后,切换回合
        if (GameManager.curTurn == "Red")
        {
            GameManager.curTurn = "Black";
        }
        else
        {
            GameManager.curTurn = "Red";
        }
        GobangClient.send(GameSerialize.toBytes(values));
        CC.IloveHUIQI();
        gameObject.transform.parent.gameObject.SetActive(false);

        //同意悔棋重置计时
        TimeManager TM;
        GameObject  obj = GameObject.Find("Timer") as GameObject;

        TM             = obj.GetComponent <TimeManager>();
        TM.bStartCul   = true;
        TM.Timer.value = 1;
    }
Esempio n. 4
0
    public void onButtonClick(string name)
    {
        if (name == "")
        {
            return;
        }

        GameObject mainObj = ui.transform.Find("Main").gameObject;

        switch (name)
        {
        case "level":
            // 昵称不能为空
            GameObject textObj     = mainObj.transform.Find("InputField/Text").gameObject;
            GameObject errorTipObj = mainObj.transform.Find("ErrorTip").gameObject;
            string     nickname    = textObj.GetComponent <Text> ().text;
            if (nickname == "")
            {
                errorTipObj.SetActive(true);
                return;
            }

            GameManager.nickname = nickname;

            // 记录 nickname
            PlayerPrefs.SetString("nickname", nickname);

            errorTipObj.SetActive(false);
            mainObj.SetActive(false);

            // 等级匹配
            GobangClient.connect(8);
            break;

        case "retry":
            //GobangClient.disconnect ();
            GameObject start = GameObject.Find("Start") as GameObject;
            ReGame     RG    = start.GetComponent <ReGame>();
            RG.ChessPostion();
            // 结果通知给对方
            Hashtable values = new Hashtable();
            values.Add("name", "piece");
            values.Add("FromX", -1);
            values.Add("FromY", -1);
            values.Add("ToX", -1);
            values.Add("ToY", -1);
            values.Add("Move", "红方走");
            values.Add("YidongOrChizi", "Yidong");
            values.Add("Regame", 1);
            values.Add("GoBack", 0);
            GobangClient.send(GameSerialize.toBytes(values));
            GameObject resultObj = ui.transform.Find("Result").gameObject;

            resultObj.SetActive(false);
            break;
        }
    }
Esempio n. 5
0
    //
    public void updateChess()
    {
        // 胜利
        if (blackclick.str == "红色方胜利" || blackclick.str == "黑色方胜利")
        {
            // 结果通知给对方
            Hashtable values = new Hashtable();
            values.Add("name", "lose");
            values.Add("v", (byte)1);
            GobangClient.send(GameSerialize.toBytes(values));
            // UI
            GameObject ui          = GameObject.Find("UI");
            GameObject resultObj   = ui.transform.Find("Result").gameObject;
            GameObject gameoverObj = resultObj.transform.Find("GameOver").gameObject;
            gameoverObj.GetComponentInChildren <Text>().text = "完胜";

            TM.bStartCul   = false;
            TM.Timer.value = 1;

            resultObj.SetActive(true);
        }
        // 超时失败
        if (TM.bGameOver)
        {
            // 结果通知给对方
            Hashtable values = new Hashtable();
            values.Add("name", "lose");
            values.Add("v", (byte)2);
            GobangClient.send(GameSerialize.toBytes(values));
            // UI
            GameObject ui          = GameObject.Find("UI");
            GameObject resultObj   = ui.transform.Find("Result").gameObject;
            GameObject gameoverObj = resultObj.transform.Find("GameOver").gameObject;
            gameoverObj.GetComponentInChildren <Text>().text = "超时失败";

            TM.bStartCul   = false;
            TM.Timer.value = 1;

            resultObj.SetActive(true);
        }
    }
Esempio n. 6
0
    // GobangClient 主要重写 Nanolink实时对战服务已封装的 onMessage, onResync, onStatusChanged, onConnected, onDisconnected 方法。

    // 重写接受到数据的响应函数,在GameManager.recvMessage()中统一处理接收到数据
    protected override void onMessage(byte[] data, byte fromIndex)
    {
        // Hashtable values = GameSerialize.fromBytes (data);

        GameObject gameObj = GameObject.Find("Game");

        if (gameObj == null)
        {
            return;
        }

        GameManager gameManager = gameObj.GetComponent <GameManager> ();

        if (gameManager == null)
        {
            return;
        }

        // 同意处理 接收到的数据
        gameManager.recvMessage(GameSerialize.fromBytes(data), fromIndex);
    }
Esempio n. 7
0
    public void RequestGoBack()
    {
        //己方落子对方未落子时可以申请悔棋
        if (GameManager.curTurn != GameManager.userColor)
        {
            //发送请求
            Hashtable values = new Hashtable();
            values.Add("name", "piece");
            values.Add("FromX", -1);
            values.Add("FromY", -1);
            values.Add("ToX", -1);
            values.Add("ToY", -1);
            values.Add("Move", "str");
            values.Add("YidongOrChizi", "YidongOrChizi");
            values.Add("Regame", 0);
            values.Add("GoBack", 1);//申请悔棋,0不申请不同意,1申请,2同意

            Label.gameObject.SetActive(true);
            Label.text = "对方考虑中...";

            GobangClient.send(GameSerialize.toBytes(values));
        }
    }
Esempio n. 8
0
    public void SendMoveMessage(int x1, int y1, int x2, int y2)
    {
        //停止计时
        TM.StopTime();
        YidongOrChizi = "Yidong";
        if ((GameManager.curTurn == GameManager.userColor) && TrueOrFalse)
        {
            // 发送消息通知对手,落子位置
            {
                KingPosition.JiangJunCheck();
                Hashtable values = new Hashtable();
                values.Add("name", "piece");
                values.Add("FromX", x1);
                values.Add("FromY", y1);
                values.Add("ToX", x2);
                values.Add("ToY", y2);
                values.Add("Move", str);
                values.Add("YidongOrChizi", YidongOrChizi);
                values.Add("Regame", 0);
                values.Add("GoBack", 0);

                GobangClient.send(GameSerialize.toBytes(values));
            }
            //检查游戏是否结束
            Game.updateChess();
            // 落子后,切换回合
            if (GameManager.curTurn == "Red")
            {
                GameManager.curTurn = "Black";
            }
            else
            {
                GameManager.curTurn = "Red";
            }
        }
    }