예제 #1
0
        public void opponentQuitWhileInGame()
        {
            if (CurrentRoom.FirstUser != null && CurrentRoom.FirstUser.Username == Message)
            {
                Singleton.Singleton.Instance.ListOfUsersLogged.Remove(CurrentRoom.FirstUser);
                CurrentRoom.SendGameOver(CurrentRoom.SecondUser,
                                         "You won!\n Your opponent got disconnected.");
                foreach (User user in Singleton.Singleton.Instance.ListOfUsersLogged)
                {
                    if (user.Username == CurrentRoom.SecondUser.Username)
                    {
                        MessagePacket pack = new MessagePacket(GameProtocol.OpponentQuitWhileInGame(), CurrentRoom.FirstUser.Username);
                        Othello.Server.SendPacket(user.Socket, pack.getData());
                        continue;
                    }
                    MessagePacket p = new MessagePacket(GameProtocol.UserDisconnected(), CurrentRoom.FirstUser.Username);
                    Othello.Server.SendPacket(user.Socket, p.getData());
                }
                CurrentRoom.FirstUser = null;
            }
            else if (CurrentRoom.SecondUser != null && CurrentRoom.SecondUser.Username == Message)
            {
                CurrentRoom.SendGameOver(CurrentRoom.FirstUser,
                                         "You won!\n Your opponent got disconnected.");
                Singleton.Singleton.Instance.ListOfUsersLogged.Remove(CurrentRoom.SecondUser);
                foreach (User user in Singleton.Singleton.Instance.ListOfUsersLogged)
                {
                    if (user.Username == CurrentRoom.FirstUser.Username)
                    {
                        MessagePacket pack = new MessagePacket(GameProtocol.OpponentQuitWhileInGame(), CurrentRoom.SecondUser.Username);
                        Othello.Server.SendPacket(user.Socket, pack.getData());
                        continue;
                    }
                    MessagePacket p = new MessagePacket(GameProtocol.UserDisconnected(), CurrentRoom.SecondUser.Username);
                    Othello.Server.SendPacket(user.Socket, p.getData());
                }
                CurrentRoom.SecondUser = null;
            }

            if (CurrentRoom.FirstUser == null && CurrentRoom.SecondUser == null)
            {
                Singleton.Singleton.Instance.ListOfRooms.Remove(CurrentRoom);
            }
        }