Example #1
0
        private void CreatRoom(IPackage package)
        {
            var conectionData   = (IConectionData)package.Data;
            var client_passport = package.Sender_Passport;
            var newGameSettings = conectionData.GameSetings;
            var player_name     = conectionData.PlayerName;

            // получить Gamer по id из списка ожидающих
            IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport);

            gamer.SetId(player_name, client_passport);

            // создать комнату
            IRoom newGameRoom = ManagerRoom.AddRoom(newGameSettings, client_passport);

            newGameRoom.CreatorPassport = gamer.Passport;

            // добавить в нее игрока
            var        room_endpoint = ManagerRoom.MooveGamerToRoom(gamer, newGameRoom.Passport);
            Addresssee addres        = new Addresssee(room_endpoint);


            var roominfo = new RoomInfo()
            {
                roomEndpoint = addres,
                mapSize      = newGameSettings.MapSize
            };

            Owner.Sender.SendMessage(new Package()
            {
                Data         = roominfo,
                MesseggeType = MesseggeType.RoomInfo
            }, gamer.RemoteEndPoint);


            newGameRoom.RUN();
            (newGameRoom as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData()
            {
                JoinedAddresssee = gamer
            });

            // инициировать начало игры (по крайней мере для теста - если создатель указывает колич.игроков =1 при создании)
            if (newGameRoom.Gamers.Count() == newGameRoom.GameSetings.MaxPlayersCount)
            {
                IPackage pack = new Package()
                {
                    MesseggeType = MesseggeType.StartGame,
                    Data         = null,
                };
                Owner.Sender.SendMessage(pack, newGameRoom.Gamers); //Управляющая комната отсылает участникам игровой комнаты

                //уведомляем игровую комнату о начале:
                (newGameRoom as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData()
                {
                    EnforceStartGame = true
                });
            }
        }
Example #2
0
        private void ConfirmJoinToRoom(IPackage package)
        {
            IConfirmJoinToRoom confirmJoinData = package.Data as IConfirmJoinToRoom;

            ManagerRoom = Owner as IManagerRoom;

            var client_passport = package.Sender_Passport;

            IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport);

            var room_passport = confirmJoinData.RoomPassport;
            var room          = ManagerRoom.GetRoomByGuid(room_passport);

            if (room != null)
            {
                if (room.Gamers.Count() < room.GameSetings.MaxPlayersCount)
                {
                    ManagerRoom.MooveGamerToRoom(gamer, room_passport);

                    //(room as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData() { JoinedAddresssee = gamer });

                    //// инициировать начало игры
                    //if (room.Gamers.Count() == room.GameSetings.MaxPlayersCount)
                    //{
                    //    IPackage pack = new Package()
                    //    {
                    //        MesseggeType = MesseggeType.StartGame,
                    //        Data = null,
                    //    };
                    //    Owner.Sender.SendMessage(pack, room.Gamers); //Управляющая комната отсылает участникам игровой комнаты

                    //    //уведомляем игровую комнату о начале:
                    //    (room as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData() { EnforceStartGame = true });
                    //}
                }
                else
                {
                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = "Room is full",
                        MesseggeType = MesseggeType.Error
                    }, gamer.RemoteEndPoint);
                }
            }
            else
            {
                Owner.Sender.SendMessage(new Package()
                {
                    Data         = "Room is not exist",
                    MesseggeType = MesseggeType.Error
                }, gamer.RemoteEndPoint);
            }
        }
Example #3
0
        private void RoomConnect(IPackage package)
        {
            ManagerRoom = Owner as IManagerRoom;

            var cd              = (IConectionData)package.Data;
            var name            = cd.PlayerName;
            var client_passport = package.Sender_Passport;

            IGamer gamer = ManagerRoom.GetGamerByGuid(client_passport);

            gamer.SetId(name, client_passport);
            var room_passport = cd.RoomPasport;

            var room     = ManagerRoom.GetRoomByGuid(room_passport);
            var map_Size = room.GameSetings.MapSize;

            if (room != null)
            {
                if (room.Gamers.Count() < room.GameSetings.MaxPlayersCount)
                {
                    IPEndPoint room_ipendpoint = ManagerRoom.MooveGamerToRoom(gamer, room_passport);
                    Addresssee addres          = new Addresssee(room_ipendpoint);

                    var roominfo = new RoomInfo()
                    {
                        roomEndpoint = addres,
                        mapSize      = map_Size
                    };

                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = roominfo,
                        MesseggeType = MesseggeType.RoomInfo
                    }, gamer.RemoteEndPoint);

                    (room as IGameRoom).NotifyGameRoomForEvent(new NotifyJoinedPlayerData()
                    {
                        JoinedAddresssee = gamer
                    });

                    // инициировать начало игры
                    if (room.Gamers.Count() == room.GameSetings.MaxPlayersCount)
                    {
                        IPackage pack = new Package()
                        {
                            MesseggeType = MesseggeType.StartGame,
                            Data         = null,
                        };
                        Owner.Sender.SendMessage(pack, room.Gamers); //Управляющая комната отсылает участникам игровой комнаты

                        //уведомляем игровую комнату о начале:
                        (room as IGameRoom).NotifyGameRoomForEvent(new NotifyStartGameData()
                        {
                            EnforceStartGame = true
                        });
                    }
                }
                else
                {
                    Owner.Sender.SendMessage(new Package()
                    {
                        Data         = "Room is full",
                        MesseggeType = MesseggeType.Error
                    }, gamer.RemoteEndPoint);
                }
            }
            else
            {
                Owner.Sender.SendMessage(new Package()
                {
                    Data         = "Room is not exist",
                    MesseggeType = MesseggeType.Error
                }, gamer.RemoteEndPoint);
            }
        }