Пример #1
0
        public Map CreateStartingPack(IArenaCallback client, RobotAvatar robotAvatar)
        {
            Map mapForUser;
            var rnd = new Random();

            _currentMap.StartingPositionList = _currentMap.StartingPositionList.OrderBy(item => rnd.Next()).Select(c => c).ToList();;
            //  this.OrderBy(x => Guid.NewGuid());

            try
            {
                Position st = this._currentMap.StartingPositionList.First(start => start.Used == false);
                robotAvatar.RobotPosition   = st;
                robotAvatar.InitialPosition = st.Copy();

                _currentMap.GlobalMap[st.Y, st.X].Robot = new Robot(robotAvatar.HealthPoints, robotAvatar.RobotPosition, robotAvatar.Color);;
                mapForUser = _currentMap.getSmallerPartForRobot(new Position(st.X, st.Y));
                //mapForUser.GlobalMap[st.Y, st.X].IsRobot = true;
                st.Used = true;

                return(mapForUser);
            }
            catch (Exception e)
            {
                EventLog.WriteErrorToLog(strErrorLogPath, e);
            }
            return(new Map(0, 0));
        }
Пример #2
0
        protected void Disconnect(IArenaCallback client)
        {
            if (avatarDictionary.Keys.ToList <IArenaCallback>().Exists(cl => cl.Equals(client)))
            {
                if (_isGameStarted)
                {
                    RobotAvatar robot;
                    avatarDictionary.TryGetValue(client, out robot);
                    removeRobotFromMap(robot.Color);

                    _disconnectedRobotAvatarList.Add(robot);
                    try
                    {
                        if (_currentMovesQueue.Exists(m => m.Client.Equals(client)))
                        {
                            _currentMovesQueue.Remove(_currentMovesQueue.Find(m => m.Client.Equals(client)));
                        }
                    }
                    catch (Exception e)
                    {
                        EventLog.WriteErrorToLog(strErrorLogPath, e);
                    }
                    _currentMovesQueue.Add(new Move(MoveType.Disconnect, _currentMap, client, avatarDictionary, avatarDictionary[client], Directions.Down, _currentRound));
                }

                try
                {
                    _currentMap.StartingPositionList.Find(pos => pos.X == avatarDictionary[client].InitialPosition.X && pos.Y == avatarDictionary[client].InitialPosition.Y).Used = false;
                }
                catch (Exception e)
                {
                    EventLog.WriteErrorToLog(strErrorLogPath, e);
                }
                colorList.Add(avatarDictionary[client].Color);
                PlayerDisconnectEvent(this, new PlayerLoginArgs(avatarDictionary[client]));
                EventLog.WriteMessageToLog(strLogPath, "Login of Client: " + avatarDictionary[client].Login + " DISCONNECTED");
                avatarDictionary.Remove(client);
                _numberOfLoggedRobots--;
            }
        }