public void addPlayer(Player pl) { if (this.status != Stage.Ready) { return; } Players.Add(pl); //(position in game to calculate respective postion in display of each player) // check and prepair again #region Assign position for player int post = 0; Players.ForEach(p => { if (p.pos_in_room == -1 || p.pos_in_room != post) { p.pos_in_room = post; } post++; }); Players.ForEach(p => { this.Broadcast(p, StaticEvent.JOIN_OR_CREATE_ROOM_SERVER_to_CLIENT); p.Status = Player.Stage.Idle; }); #endregion // Send Start Button to the lastWinner or the player has min Score or the player minPostion in Game Player lastWinner = StaticEvent.FindLastWinner(this.Players); //lastWinner.Send(lastWinner, StaticEvent.TAKE_START_BUTTON_SERVER_to_CLIENT); if (lastWinner != null && this.Players.Count > 1) { lastWinner.Send(lastWinner, StaticEvent.TAKE_START_BUTTON_SERVER_to_CLIENT); } }
public void removePlayer(Player pl) { if (this.status == Stage.Playing) { // End game, left player pay a penanty to other in Game // the declare a winner in State.Finallizing return; } Players.Remove(pl); // SendEvent LEFT_ROOM to all players in Room Players.ForEach(p => { // 1. Send information of new player to everyone in room p.Send(pl, StaticEvent.PLAYER_LEFT_ROOM_SERVER_to_CLIENT); }); // Send Start Button to the lastWinner or the player has min Score or the player minPostion in Game Player lastWinner = StaticEvent.FindLastWinner(this.Players); if (lastWinner != null && this.Players.Count > 1) { lastWinner.Send(lastWinner, StaticEvent.TAKE_START_BUTTON_SERVER_to_CLIENT); } }