// 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); } }
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; }
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); }
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()); }
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); }
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); }
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 (); }
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); } }
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); }
// 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); } }
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); }
// 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); } }
void onMatch(NetWork.Msg msg) { Debug.Log("match rsp"); }
void onEnter(NetWork.Msg msg) { UnityEngine.SceneManagement.SceneManager.LoadScene("playing"); }
void onMatch(NetWork.Msg msg) { Table.MatchRsp rsp = (Table.MatchRsp)msg.body; Debug.Log("Match rsp err no" + rsp.err_no.ToString()); }
void onEnter(NetWork.Msg msg) { Debug.Log("Enter Room...."); UnityEngine.SceneManagement.SceneManager.LoadScene("playing"); }