public ActionResult Room(string id) { var playroom = PlayRoomsManager.Get(id); ViewBag.RoomID = id; ViewBag.Rule = id.StartsWith("A") ? "A" : "B"; return(View(playroom)); }
public override void OnOpen() { // nameパラメータの取り出し var playerName = this.WebSocketContext.QueryString["name"]; if (string.IsNullOrWhiteSpace(playerName)) { SendMessageAsJson("URL Parameter 'name' is not specified."); Close(); } var mc = Regex.Matches(this.WebSocketContext.RequestUri.OriginalString, @"/test/practice/([\-A-Z0-9]+)"); if (mc.Count > 0) { sessionId = mc[0].Groups[1].Success ? mc[0].Groups[1].Value.ToString() : ""; if (!string.IsNullOrWhiteSpace(sessionId)) { room = PlayRoomsManager.Get(sessionId); } } if (room == null || !sessionId.StartsWith(ROOM_ID_PREFIX)) { SendMessageAsJson("Invalid session ID"); base.Close(); return; } _startTimer(PLAYROOM_LIFETIME * 1000); var key = this.WebSocketContext.CreatePlayerKey(playerName); pAdapter = room.FindRemotePlayer(key) as GamePlayerAdapter; if (pAdapter != null && !pAdapter.IsConnected) { // 再接続とみなす pAdapter.Reconnect(playerName, (str) => Send(str)); } else { // プレイヤー通信ハンドラを作成 pAdapter = new GamePlayerAdapter(room, playerName, (str) => Send(str)); pAdapter.TurnTimeoutSec = TIMEOUT_SEC; room.AddPlayer(key, pAdapter); } if (room.Master.NumOfPlayers == 1) { // 他のプレイヤーを追加 room.DoComplementPlayers(4); // ゲーム開始 room.Master.Start(); } }
internal static ViewModel Create() { var vm = new ViewModel(); for (int i = 1; i <= 10; i++) { string id = string.Format("A-{0:00}", i); vm.RoomsA[id] = PlayRoomsManager.Get(id); } for (int i = 1; i <= 5; i++) { string id = string.Format("B-{0:00}", i); vm.RoomsB[id] = PlayRoomsManager.Get(id); } return(vm); }
public override void OnOpen() { var mc = Regex.Matches(this.WebSocketContext.RequestUri.OriginalString, @"/monitor/([\-A-Z0-9]+)"); if (mc.Count > 0) { sessionId = mc[0].Groups[1].Success ? mc[0].Groups[1].Value.ToString() : ""; if (!string.IsNullOrWhiteSpace(sessionId)) { room = PlayRoomsManager.Get(sessionId); } } if (room == null) { base.Close(); return; } room.AddObserver(this); }
public override void OnOpen() { // nameパラメータの取り出し var playerName = this.WebSocketContext.QueryString["name"]; if (string.IsNullOrWhiteSpace(playerName)) { SendMessageAsJson("URL Parameter 'name' is not specified."); Close(); } var mc = Regex.Matches(this.WebSocketContext.RequestUri.OriginalString, @"/test/ruletest/([\-A-Z0-9]+)"); if (mc.Count > 0) { sessionId = mc[0].Groups[1].Success ? mc[0].Groups[1].Value.ToString() : ""; if (!string.IsNullOrWhiteSpace(sessionId)) { room = PlayRoomsManager.Get(sessionId); } } if (room == null || !sessionId.StartsWith(ROOM_ID_PREFIX)) { SendMessageAsJson("Invalid session ID"); base.Close(); return; } _startTimer(PLAYROOM_LIFETIME * 1000); var key = this.WebSocketContext.CreatePlayerKey(playerName); pAdapter = room.FindRemotePlayer(key) as GamePlayerAdapter; if (pAdapter != null && !pAdapter.IsConnected) { // 再接続とみなす pAdapter.Reconnect(playerName, (str) => Send(str)); } else { // プレイヤー通信ハンドラを作成 pAdapter = new GamePlayerAdapter(room, playerName, (str) => Send(str)); pAdapter.TurnTimeoutSec = TIMEOUT_SEC; room.AddPlayer(key, pAdapter); } if (room.Master.NumOfPlayers == 1) { // 他のプレイヤーを追加 p1 = new TestcasePlayer("革命マシン", (c) => room.Master.PutCards(p1, c), TestSettings.Player1Hands); p2 = new TestcasePlayer("早あがり太郎", (c) => room.Master.PutCards(p2, c), TestSettings.Player2Hands); room.AddPlayer("1", p1); room.AddPlayer("2", p2); room.Master.CardDistributer = new TestCardDistributer(TestSettings.Player0InitialDeck, p1.GetInitialDeck(), p2.GetInitialDeck()); // ゲーム開始 room.Master.Start(); } }