private void startRound(RoomInfo roomInfo) { // get all players var playersInGame = this.getPlayersInGame(roomInfo); // get random player, that begins the first round var drawerCandidates = this.getRemainingDrawerCandidates(roomInfo); /////////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: if only one player left in room => kick him var nextDrawer = drawerCandidates.Pick(); roomInfo.Drawer = (nextDrawer.UserData as ClientUserData).PlayerName; (nextDrawer.UserData as ClientUserData).IsDrawing = true; this.sendRankListToAll(roomInfo); roomInfo.RoundInfo.PlayersThatDrawed.Add(roomInfo.Drawer); // set round info roomInfo.RoundInfo.Number++; roomInfo.RoundInfo.StartTime = DateTime.Now.Ticks; var choosingWordInfo = new ChoosingWordInfo { PlayerName = (nextDrawer.UserData as ClientUserData).PlayerName }; var simpleRoundInfo = new SimpleRoundInfo { Current = roomInfo.RoundInfo.Number, Total = roomInfo.TotalRoundCount }; foreach (var p in playersInGame) { if (p != nextDrawer) { p.send(choosingWordInfo); } p.send(simpleRoundInfo); } // send word choice this.sendWordChoice(nextDrawer, roomInfo); /////////////////////////////////////////////////////////////////////////////////////////////////////// }
private void nextDrawer(RoomInfo roomInfo) { // reset current drawer to normal player //try { //var drawingPlayer = Server.Clients.First(c => //{ // var u = c.UserData as ClientUserData; // return u != null && u.RoomName == roomInfo.Name && u.PlayerName == roomInfo.Drawer; //}); //(drawingPlayer.UserData as ClientUserData).IsDrawing = false; var drawer = this.getCurrentDrawer(roomInfo); if (drawer != null) { (drawer.UserData as ClientUserData).IsDrawing = false; } } //catch { } // evaluate current drawing-round (update player points) foreach (var item in roomInfo.RoundInfo.PlayerTimes) { var player = Server.Clients.First(c => { var u = c.UserData as ClientUserData; return(u != null && u.PlayerName == item.Key); }); if (player != null) { (player.UserData as ClientUserData).Points += item.Value; } } // reset drawing-round-info roomInfo.RoundInfo.StartTime = 0; roomInfo.RoundInfo.PlayerTimes.Clear(); // TODO: create and send evalution (show evalution-overview on client) // send updated ranklist this.sendRankListToAll(roomInfo); var drawerCandidates = this.getRemainingDrawerCandidates(roomInfo); // check if there are remaing drawers in this round if (drawerCandidates.Count() > 0) { // get all players var playersInGame = this.getPlayersInGame(roomInfo); /////////////////////////////////////////////////////////////////////////////////////////////////////// var nextDrawer = drawerCandidates.Pick(); roomInfo.Drawer = (nextDrawer.UserData as ClientUserData).PlayerName; (nextDrawer.UserData as ClientUserData).IsDrawing = true; this.sendRankListToAll(roomInfo); roomInfo.RoundInfo.PlayersThatDrawed.Add(roomInfo.Drawer); var choosingWordInfo = new ChoosingWordInfo { PlayerName = (nextDrawer.UserData as ClientUserData).PlayerName }; var simpleRoundInfo = new SimpleRoundInfo { Current = roomInfo.RoundInfo.Number, Total = roomInfo.TotalRoundCount }; foreach (var p in playersInGame) { if (p != nextDrawer) { p.send(choosingWordInfo); } p.send(simpleRoundInfo); } // set round info //roomInfo.RoundInfo.Number++; roomInfo.RoundInfo.StartTime = DateTime.Now.Ticks; // send word choice this.sendWordChoice(nextDrawer, roomInfo); /////////////////////////////////////////////////////////////////////////////////////////////////////// } else { // check if rounds remaining if (roomInfo.RoundInfo.Number < roomInfo.TotalRoundCount) { roomInfo.RoundInfo.PlayersThatDrawed.Clear(); // start next round this.startRound(roomInfo); } else { // TODO: create and send final evalution var allPlayers = this.getPlayersInGame(roomInfo); foreach (var p in allPlayers) { p.send(new FinalEvaluation { }); } } } }