예제 #1
0
    // Update is called once per frame
    void Update()
    {
        NetWork.Msg msg = network.PeekMsg();
        if (msg == null)
        {
            return;
        }

        if (msg.name == "Table.MatchRsp")
        {
            onMatch(msg);
        }
        else if (msg.name == "Table.MatchResult")
        {
            onMatchResult(msg);
        }
        else if (msg.name == "Table.MoveNotify")
        {
            onMoveNotify(msg);
        }
        else if (msg.name == "Table.Winner")
        {
            gameOver(msg);
        }
    }
예제 #2
0
    void onMoveNotify(NetWork.Msg msg)
    {
        Table.MoveNotify notify = (Table.MoveNotify)msg.body;
        Table.Move       mv     = notify.move;

        if (game.is_red == false)
        {
            Debug.Log("move notify not red");
            mv.srow = 11 - mv.srow;
            mv.drow = 11 - mv.drow;
        }

        int index = (mv.srow - 1) * 9 + mv.scol - 1;
        // 遍历棋子,找到
        GameObject cm = cms[index];

        Single  r       = 0.89f;
        Vector3 old_pos = cm.transform.position;
        Vector3 pos     = new Vector3(old_pos.x + (mv.dcol - mv.scol) * r, old_pos.y + (mv.drow - mv.srow) * -r, 0);

        cm.transform.position = pos;
        game.Move(mv.srow, mv.scol, mv.drow, mv.dcol);

        selected_me.row = 0;
    }
예제 #3
0
    void onMoveNotify(NetWork.Msg msg)
    {
        Table.MoveNotify notify = (Table.MoveNotify)msg.body;
        Table.Move       mv     = notify.move;

        // 干掉目标棋子
        for (int i = 0; i < chesses.Count; ++i)
        {
            if (chesses[i].row == mv.drow && chesses[i].col == mv.dcol && chesses[i].visiable)
            {
                chesses[i].visiable = false;
                chesses[i].o.SetActive(false);
                break;
            }
        }
        // 移动待源棋子
        for (int i = 0; i < chesses.Count; ++i)
        {
            if (chesses[i].row == mv.srow && chesses[i].col == mv.scol && chesses[i].visiable)
            {
                chesses[i].row = mv.drow;
                chesses[i].col = mv.dcol;
                chesses[i].o.transform.localPosition = GetPos(mv.drow, mv.dcol);
                break;
            }
        }
        // select_1 select_2设置
        select_1.transform.localPosition = GetPos(mv.srow, mv.scol);
        select_2.transform.localPosition = GetPos(mv.drow, mv.dcol);
        select_1.SetActive(true);
        select_2.SetActive(true);
        selected_me.row = 0;

        game.Move(mv.srow, mv.scol, mv.drow, mv.dcol);
    }
예제 #4
0
    void gameOver(NetWork.Msg msg)
    {
        Debug.Log("gameOver....");
        Table.Winner winner = (Table.Winner)msg.body;
        bool         isRed  = winner.isred;

        Debug.Log("Winner... is red ?" + isRed.ToString());
    }
예제 #5
0
    void onMatchResult(NetWork.Msg msg)
    {
        Debug.Log("match result");
        Table.MatchResult result = (Table.MatchResult)msg.body;
        Debug.Log(result.i_am_red);

        game.init(result.i_am_red, result.i_am_red);
        loadAllChess(result.i_am_red);
    }
예제 #6
0
    void onRoomList(NetWork.Msg msg)
    {
        Room.RoomListRsp rsp = (Room.RoomListRsp)msg.body;

        Room.EnterReq req = new Room.EnterReq();
        req.room_id = 1;
        network.WriteMsg("Room.EnterReq", req);
        Debug.Log(rsp);
    }
예제 #7
0
    void onMoveNotify(NetWork.Msg msg)
    {
        Debug.Log("onMoveNotify....");
        Table.MoveNotify notify = (Table.MoveNotify)msg.body;
        Table.Move       mv     = notify.move;


        if (game.is_red == false)
        {
            mv.srow = 11 - mv.srow;
            mv.drow = 11 - mv.drow;
            mv.scol = 10 - mv.scol;
            mv.dcol = 10 - mv.dcol;
        }

        Single     r         = 0.89f;
        int        src_index = (mv.srow - 1) * 9 + mv.scol - 1;
        GameObject src_cm    = cms[src_index];
        Vector3    old_pos   = src_cm.transform.position;
        Vector3    pos       = new Vector3(old_pos.x + (mv.dcol - mv.scol) * r, old_pos.y + (mv.drow - mv.srow) * -r, 0);

        src_cm.transform.position = pos;

        int        dst_index = (mv.drow - 1) * 9 + mv.dcol - 1;
        GameObject dst_cm    = cms[dst_index];

        if (dst_cm != null)
        {
            hide_selector(dst_cm);
        }
        cms [dst_index] = src_cm;
        cms [src_index] = null;
        if (game.IsRedCM(mv.srow, mv.scol))
        {
            show_selector(red_move_src, mv.srow, mv.scol);
            show_selector(red_move_dst, mv.drow, mv.dcol);
            hide_selector(black_move_src);
            hide_selector(black_move_dst);
        }
        else
        {
            show_selector(black_move_src, mv.srow, mv.scol);
            show_selector(black_move_dst, mv.drow, mv.dcol);
            hide_selector(red_move_src);
            hide_selector(red_move_dst);
        }
        //恢复设置一下
        selected_me.row = 0;
        selected_me.col = 0;
        is_selected     = false;
        hide_selector(selected_me_obj);
        game.Move(mv.srow, mv.scol, mv.drow, mv.dcol);
        Debug.Log("!!!!!!  OnMouseDown ismyturn====>" + game.IsMyTurn().ToString());
        //Move中有改变
        //game.ChangeMyTurn ();
    }
예제 #8
0
 public void onUpdate()
 {
     NetWork.Msg msg = NetClient.Instance().PeekMsg();
     if (msg == null)
     {
         return;
     }
     Debug.Log("收到协议" + msg.name);
     if (dic.ContainsKey(msg.name))
     {
         dic[msg.name].Invoke(msg);
     }
 }
예제 #9
0
    void onMoveNotify(NetWork.Msg msg)
    {
        Table.MoveNotify notify = (Table.MoveNotify)msg.body;
        Table.Move       mv     = notify.move;


        if (game.is_red == false)
        {
            mv.srow = 11 - mv.srow;
            mv.drow = 11 - mv.drow;
            mv.scol = 10 - mv.scol;
            mv.dcol = 10 - mv.dcol;
        }

        Single     r         = 0.89f;
        int        src_index = (mv.srow - 1) * 9 + mv.scol - 1;
        GameObject src_cm    = cms[src_index];
        Vector3    old_pos   = src_cm.transform.position;
        Vector3    pos       = new Vector3(old_pos.x + (mv.dcol - mv.scol) * r, old_pos.y + (mv.drow - mv.srow) * -r, 0);

        src_cm.transform.position = pos;

        int dst_index = (mv.drow - 1) * 9 + mv.dcol - 1;

        Debug.Log("dst index: " + dst_index);
        GameObject dst_cm = cms[dst_index];

        if (dst_cm != null)
        {
            hide_selector(dst_cm);
        }
        cms [dst_index] = src_cm;
        cms [src_index] = null;
        if (game.IsRedCM(mv.srow, mv.scol))
        {
            show_selector(red_move_src, mv.srow, mv.scol);
            show_selector(red_move_dst, mv.drow, mv.dcol);
            hide_selector(black_move_src);
            hide_selector(black_move_dst);
        }
        else
        {
            show_selector(black_move_src, mv.srow, mv.scol);
            show_selector(black_move_dst, mv.drow, mv.dcol);
            hide_selector(red_move_src);
            hide_selector(red_move_dst);
        }
        selected_me.row = 0;
        hide_selector(selected_me_obj);
        game.Move(mv.srow, mv.scol, mv.drow, mv.dcol);
    }
예제 #10
0
파일: Loading.cs 프로젝트: mengtest/chess-1
    // Update is called once per frame
    void Update()
    {
        UpdateTip();

        NetWork.Msg msg = network.PeekMsg();
        if (msg == null)
        {
            return;
        }

        if (msg.name == "Login.LoginRsp")
        {
            onLogin(msg);
        }
    }
예제 #11
0
    void onRoomList(NetWork.Msg msg)
    {
        Room.RoomListRsp rsp = (Room.RoomListRsp)msg.body;
        Debug.Log("Room.RoomListRsp..." + rsp);
        Debug.Log("Get Room List....");
        foreach (Room.RoomInfo room in rsp.list)
        {
            Debug.Log("Room:" + room.ToString());
        }
        Debug.Log("Over....");

        Room.EnterReq req = new Room.EnterReq();
        req.room_id = 1;
        network.WriteMsg("Room.EnterReq", req);
    }
예제 #12
0
    // Update is called once per frame
    void Update()
    {
        NetWork.Msg msg = network.PeekMsg();
        if (msg == null)
        {
            return;
        }

        if (msg.name == "Room.RoomListRsp")
        {
            onRoomList(msg);
        }
        else if (msg.name == "Room.EnterRsp")
        {
            onEnter(msg);
        }
    }
예제 #13
0
 void onMatch(NetWork.Msg msg)
 {
     Debug.Log("match rsp");
 }
예제 #14
0
 void onEnter(NetWork.Msg msg)
 {
     UnityEngine.SceneManagement.SceneManager.LoadScene("playing");
 }
예제 #15
0
 void onMatch(NetWork.Msg msg)
 {
     Table.MatchRsp rsp = (Table.MatchRsp)msg.body;
     Debug.Log("Match rsp err no" + rsp.err_no.ToString());
 }
예제 #16
0
 void onEnter(NetWork.Msg msg)
 {
     Debug.Log("Enter Room....");
     UnityEngine.SceneManagement.SceneManager.LoadScene("playing");
 }