private void onJoinRoom(CEvent evt) { UnityThreadHelper.Dispatcher.Dispatch(() => { RoomEvent parms = (RoomEvent)evt.eventParams; var room = parms.room; var playerData = parms.player; //这里是新玩家加入。你要构造new playercs 然后加倾听方法。 TinyRoomCS ts = ConvertTool.ConvertRoom(room); Debug.Log("加入房间" + JsonConvert.SerializeObject(ts)); }); }
//发牌 准备 private void onDispath(CEvent evt) { UnityThreadHelper.Dispatcher.Dispatch(() => { // throw new NotImplementedException(); RoomEvent parms = (RoomEvent)evt.eventParams; var room = parms.room; TinyRoomCS ts = ConvertTool.ConvertRoom(room); Debug.Log("房间发牌" + JsonConvert.SerializeObject(ts)); }); }
//有玩家离开了房间。 private void onLeaveRoom(CEvent evt) { UnityThreadHelper.Dispatcher.Dispatch(() => { RoomEvent parms = (RoomEvent)evt.eventParams; var room = parms.room; //这里判断房间的ID和当前的房间是否吻合,如果是,继续操作。 var playerData = parms.player; //这个玩家离开了房间。 TinyRoomCS ts = ConvertTool.ConvertRoom(room); Debug.Log("加入房间" + JsonConvert.SerializeObject(ts)); }); }
private void onCreateRoom(CEvent evt) { UnityThreadHelper.Dispatcher.Dispatch(() => { Debug.Log("创建房间成功" + evt.eventParams); // var c = (TinyRoomCS)evt.eventParams; RoomEvent e = (RoomEvent)evt.eventParams; TinyRoomCS c = ConvertTool.ConvertRoom(e.room); if (currentRoom != null) { TinyRoomCS c2 = ConvertTool.ConvertRoom(currentRoom.data); if (c.id == c2.id) { Debug.LogError("不能重复创建房间"); return; } } Debug.Log(c); var room = new RoomCS(e.room); room.addEvent(); //这里是内部倾听,不能删除,否则所有事件无效。 room.addEventListener(RoomEvent.JOIN_ROOM, onJoinRoom); room.addEventListener(RoomEvent.DESTORY, onDestoryRoom); //删除和退出一样。 room.addEventListener(RoomEvent.LEAVE_ROOM, onLeaveRoom); room.addEventListener(RoomEvent.GET_ROOM_INFO, onGetRoomInfo); room.addEventListener(RoomEvent.JOIN_ROOM, onJoinRoom); hall.removeEventListener(RoomEvent.JOIN_ROOM, onJoinRoom); room.addEventListener(RoomEvent.DISPATCH, onDispath); room.addEventListener(RoomEvent.RESULT, onGetResult); currentRoom = room; }); //room.addEventListener(RoomEvent, onDispath); //room.addEventListener(RoomEvent.); }
void OnGUI() { if (socketConnect == false) { return; } //进入/创建机器人房间 if (GUI.Button(new Rect(0, 0, 50, 50), "creat")) { if (currentPlayer != null) { TinyRoomCS room = new TinyRoomCS(); room.gameID = 2001; //机器人三公,参考文档 room.gambling = 10; // // 底注 不同房间准入不同,要计算player还有多少money. room.threshold = 1; //准入. room.owerID = (int)currentPlayer.id; //这个是当前玩家的id.这里测试随便填。 self.createRoom(ConvertTool.ToHaxeRoom(room)); } else { Debug.Log("请登录"); } } //开始游戏 if (GUI.Button(new Rect(60, 0, 50, 50), "start")) { if (currentRoom != null) { currentRoom.start(); } else { Debug.Log("请创建room"); } } if (GUI.Button(new Rect(120, 0, 50, 50), "getinfo")) { if (currentRoom != null) { currentRoom.getInfo(); } else { Debug.Log("请创建room"); } } //退出游戏 //下注 if (GUI.Button(new Rect(0, 60, 50, 50), "addbet")) { if (currentPlayer != null) { var data = currentRoom.data; self.gameAddBetCS(2); //这里是倍数。 } else { Debug.Log("请登陆"); } } //下注 if (GUI.Button(new Rect(60, 60, 50, 50), "quite")) { if (currentPlayer != null && currentRoom != null) { var data = currentRoom.data; TinyRoomCS c = ConvertTool.ConvertRoom(data); if ((int)c.status > 2) { Debug.Log("游戏进行中不能退出"); return; } if (self.data == null) { Debug.Log("请self.install data"); return; } self.leaveRoom((uint)c.id); } else { Debug.Log("请登陆和创建房间"); } } //获取用户信息,没有登陆的情况下 不要频繁调用 if (GUI.Button(new Rect(160, 60, 50, 50), "getinfo")) { JsonData cmd = new JsonData(); //demo.SetJsonType(JsonType.Object); // demo["id"] = 3302; cmd["openid"] = haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz"); //"01234567891234567891234567891"; cmd["cmd"] = 4002; var d = cmd.ToJson(); hall.excuteCMD(d); } if (GUI.Button(new Rect(260, 60, 50, 50), "insertOpenid")) { //先查找是否存在,后插入。 JsonData cmd = new JsonData(); //demo.SetJsonType(JsonType.Object); // demo["id"] = 3302; // cmd["openid"] = haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz"); //"01234567891234567891234567891"; cmd["cmd"] = 4005; JsonData player = new JsonData(); cmd["player"] = player; player["openID"] = haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz"); //填入真实的openid. player["referenceID"] = 0; //推荐人ID.//注册。 player["thirdPartID"] = 10086; //第三方ID. player["avatar"] = "1.jpg"; player["nick_name"] = "新用户"; //插入用户昵称 hall.excuteCMD(cmd.ToJson()); } if (GUI.Button(new Rect(360, 60, 50, 50), "login")) { //先查找是否存在,后插入。 self.Login("0002", "111111", false); //self.LoginWithOpenID("233f1ad58da76ef962af1b74979e40da"); } //充值,从交易所充入来 if (GUI.Button(new Rect(6, 160, 50, 50), "charge")) { //先查找是否存在,后插入。 JsonData cmd = new JsonData(); cmd["cmd"] = 4006; JsonData player = new JsonData(); cmd["player"] = player; cmd["value"] = 100; //充值金额 player["id"] = 3302; // haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz");//填入真实的openid. hall.excuteCMD(cmd.ToJson()); } //购买道具,充值入游戏 if (GUI.Button(new Rect(100, 160, 50, 50), "buy")) { //先查找是否存在,后插入。 JsonData cmd = new JsonData(); cmd["cmd"] = 4007; JsonData player = new JsonData(); cmd["value"] = 1; //这里是传索引 [100,200,500] 1是200 cmd["nums"] = 1; //购买多少次 player["id"] = 3302; // haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz");//填入真实的openid. cmd["player"] = player; hall.excuteCMD(cmd.ToJson()); } //提取 if (GUI.Button(new Rect(200, 160, 50, 50), "draw")) { //先查找是否存在,后插入。 JsonData cmd = new JsonData(); cmd["cmd"] = 4008; JsonData player = new JsonData(); cmd["value"] = 100; //要提取多少币? player["id"] = 3302; // haxe.root.Random.@string(32, "123456789abcdefghijklnmopqrstuvwxyz");//填入真实的openid. cmd["player"] = player; hall.excuteCMD(cmd.ToJson()); } if (GUI.Button(new Rect(260, 160, 50, 50), "getinfo")) { //先查找是否存在,后插入。 self.getUserInfo(); } if (GUI.Button(new Rect(360, 160, 50, 50), "tearm")) { //先查找是否存在,后插入。 self.getUserIncomeAndSize(); // } if (GUI.Button(new Rect(360, 260, 50, 50), "getBuyList")) { //获取购买游戏币历史 self.getBuyList(); } if (GUI.Button(new Rect(460, 260, 50, 50), "getChargeList")) { //获取购买游戏币历史 self.getChargeList(); } if (GUI.Button(new Rect(560, 260, 50, 50), "getDrawList")) { //获取购买游戏币历史 self.getDrawOutist(); } if (GUI.Button(new Rect(160, 360, 50, 50), "getLastCharge")) { //获取购买游戏币历史 self.getLastChargeTime(); } if (GUI.Button(new Rect(260, 410, 50, 50), "joinRoom")) //加入专区房间 { self.joinRoom(1000); //房间ID. } if (GUI.Button(new Rect(310, 410, 50, 50), "DestoryRoom")) //加入专区房间 { self.destryRoom(1000); //删除房间 } if (GUI.Button(new Rect(310, 410, 50, 50), "changeStatus"))//改变状态 { // var UP = 0; // 站起//主动 // var SIT = 1; // 游戏没有安装。//被动 // var READY = 2; // 准备。//主动 // var QUIT = -2; // 用户退出 // var Wipeout = -1; // 没钱。//被动 self.changeStatus(2, 1001);//1001是你加入房间或者创建房间的id. } if (GUI.Button(new Rect(310, 470, 50, 50), "getRate"))// { //获取BCCM汇率 self.getRate(); } if (GUI.Button(new Rect(350, 470, 50, 50), "getRate"))// { //获取BCCM汇率 //txt_log.text = "开始插入账号操作"; JsonData cmd = new JsonData(); cmd["cmd"] = 4005; JsonData player = new JsonData(); cmd["player"] = player; player["referenceID"] = 5001;//推荐人ID player["openID"] = "233f1ad58da76ef962af1b74979e40da"; player["nick_name"] = "1"; //插入用户昵称 player["avatar"] = "2"; hall.excuteCMD(cmd.ToJson()); } }
private void onGetRoomInfo(CEvent evt) { UnityThreadHelper.Dispatcher.Dispatch(() => { RoomEvent parms = (RoomEvent)evt.eventParams; var room = parms.room; Debug.Log("room" + room); TinyRoomCS ts = ConvertTool.ConvertRoom(room); var idle = 0; // 空闲; var ready = 1; // 准备状态 var playing = 2; // 玩; var start = 2; var dispath = 3; var qiangzhuang = 4; // 抢庄 var settingZhuang = 5; //设置庄 var gamebling = 6; // 下注 var switchTimes = 7; ////设置倍数。如:两点一倍,炸弹四倍 var roundFinish = 8; // 一局结束 var over = 9; // 游戏结束; Debug.Log("获取信息房间" + JsonConvert.SerializeObject(ts)); switch (ts.status) { case 0: Debug.Log("<color=#9400D3>空闲</color>"); break; case 1: Debug.Log("<color=#9400D3>准备</color>"); break; case 2: Debug.Log("<color=#9400D3>开始</color>"); break; case 3: Debug.Log("<color=#9400D3>发牌</color>"); break; case 4: Debug.Log("<color=#9400D3>抢庄</color>"); break; case 5: Debug.Log("<color=#9400D3>设置庄</color>"); break; case 6: Debug.Log("<color=#9400D3>下注</color>"); break; case 7: Debug.Log("<color=#9400D3>设置倍数</color>"); //用于开房间,一共有几局 break; case 8: Debug.Log("<color=#9400D3>本轮结束</color>"); //用于开房间,一共有几局 break; case 9: Debug.Log("<color=#9400D3>游戏结束</color>"); //用于开房间,一共有几局 break; } var ps = ts.players; //2019-11-27 foreach (TinyPlayerCS cs in ps) { if (dic == null) { dic = new Dictionary <int, PlayerCS>(); } if (!dic.ContainsKey(cs.id)) { dic[cs.id] = new PlayerCS(null); var player = dic[cs.id]; if (player.data == null) { player.installDataCS(JsonConvert.SerializeObject(cs)); } player.addEvent(); player.addEventListener(PlayerEvent.ADD_BET, onAddBet); //倾听下注,还可以倾听用户 的表情,语音,等。 } } }); }