Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public double GetTotalScoreForRobot(RobotAvatar robot)
        {
            double score = 0;

            foreach (var turnScore in _totalScoreDictionary.Values)
            {
                score += turnScore[robot];
            }
            return(score);
        }
Exemplo n.º 3
0
 public PlayerMoveArgs(Map Map, RobotAvatar RobotAvatar, Move Mv)
 {
     this.robotAvatar = RobotAvatar;
     this.map         = Map;
     this.move        = Mv;
 }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="user"></param>
        public void Login(string user)
        {
            var client = OperationContext.Current.GetCallbackChannel <IArenaCallback>();

            EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " want to log in");

            if (!avatarDictionary.Values.ToList().Exists(c => c.Login.Equals(user)) && !_isGameStarted && avatarDictionary.Count <= 8)
            {
                if (_currentMap != null)
                {
                    if (_currentMap.StartingPositionList.Count < _numberOfLoggedRobots)
                    {
                        client.reciveInitialData(InitialServerResponse.Exception("Too many players, no place for you"));
                        EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + user + " cannot log in because there are too many players");
                        return;
                    }
                }

                string color = "default";
                if (colorList.Count > 0)
                {
                    color = colorList.First();
                    colorList.Remove(color);
                }

                var robotAvatar = new RobotAvatar(user, color, null);
                PlayerLoginEvent(this, new PlayerLoginArgs(robotAvatar));
                Map mapForUser = null;

                avatarDictionary.Add(client, robotAvatar);
                _numberOfLoggedRobots++;
                OperationContext.Current.Channel.Faulted += new EventHandler(Channel_Faulted);
                OperationContext.Current.Channel.Closed  += new EventHandler(Channel_Faulted);

                if (_currentMap != null)
                {
                    if (_currentMap.StartingPositionNumber < _numberOfLoggedRobots)
                    {
                        client.reciveInitialData(InitialServerResponse.Exception("Too many players, no place for you"));
                        EventLog.WriteMessageToLog(strLogPath, "ERROR: Client: " + user + " cannot log in because there are too many players");

                        return;
                    }

                    robotAvatar.CurrentMapForRobot = CreateStartingPack(client, robotAvatar);
                    client.reciveInitialData(InitialServerResponse.PlayerRegistered(robotAvatar.Color, (int)_roundTime, robotAvatar.RobotPosition, new MapSize(_currentMap.MapWidth, _currentMap.MapHeight)));
                    EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " logged in and recieved Color " + color + " and Starting Position: " + robotAvatar.RobotPosition.ToString());
                }
                else
                {
                    client.reciveInitialData(InitialServerResponse.Exception("Wait for map"));
                    EventLog.WriteMessageToLog(strLogPath, "Client: " + user + " has to wait for map");
                }
            }
            else if (avatarDictionary.Values.ToList().Exists(c => c.Login.Equals(user)))
            {
                client.reciveInitialData(InitialServerResponse.LoginAlreadyExists());
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Login of Client: " + user + " already exists");
            }
            else if (_isGameStarted)
            {
                client.reciveInitialData(InitialServerResponse.Exception("Game already started, wait for the end!"));
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Game Started!");
            }
            else
            {
                client.reciveInitialData(InitialServerResponse.Exception("Maximal number of players 9. Sorry no place for you!"));
                EventLog.WriteMessageToLog(strLogPath, "ERROR: Too many players");
            }
        }
Exemplo n.º 5
0
 public PlayerLoginArgs(RobotAvatar RobotAvatar)
 {
     this.RobotAvatar = RobotAvatar;
 }