Exemplo n.º 1
0
        public int CalculatePoints(Traveler traveler)
        {
            int result = this.Points;

            foreach (var item in this.TravelersHistory)
            {
                if (item == traveler)
                {
                    result += this.BonusPoints;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Método de actualización, se ejecuta cuando un Viajero se mueve.
        /// </summary>
        /// <param name="observable"> Viajero que se movió</param>
        public override void Update(Traveler observable)
        {
            if (observable.Position == this.Position)
            {
                if (this.Capacity > this.Travelers.Count)
                {
                    EnterTraveler(observable);

                    if (this.Capacity == this.Travelers.Count)
                    {
                        WinnerTravelers();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void MoveTravelerToStation(int wantedStationIndex, Traveler traveler)
        {
            int currentIndex = -1;

            foreach (var station in this.Stations)
            {
                if (station.Travelers.Contains(traveler))
                {
                    currentIndex = this.Stations.IndexOf(station);
                    break;
                }
            }

            if (currentIndex == -1)
            {
                throw new Exception("Traveler not found.");
            }

            else if (wantedStationIndex <= currentIndex)
            {
                throw new Exception("Traveler already visited this station.");
            }

            else if (wantedStationIndex >= this.Stations.Count)
            {
                throw new Exception("Station not found.");
            }

            else
            {
                foreach (var station in this.Stations)
                {
                    if (station.Travelers.Contains(traveler))
                    {
                        station.RemoveTraveler(traveler);
                    }
                }

                Station wantedStation = this.Stations[wantedStationIndex];
                wantedStation.AddTraveler(traveler);

                if ((int)wantedStation.Type == 2)
                {
                    Traveler winner = this.TheWinnerIs();
                    Console.WriteLine("The winner is: " + winner.Name);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Método que recibe un objeto tipo Traveler por parámetro, verifica que no sea null y lo agrega al diccionario PlayersRegistry si no está,
        /// y si está aumenta en 1 su valor.
        /// </summary>
        /// <param name="player"></param>
        public override void RegisterPlayer(Traveler player)
        {
            if (player == null)
            {
                throw new TravelerNullException();
            }

            if (PlayersRegistry.ContainsKey(player))
            {
                PlayersRegistry[player]++;
            }
            else
            {
                PlayersRegistry.Add(player, 1);
            }
        }
Exemplo n.º 5
0
 public void AddTraveler(Traveler trav)
 {
     if ((int)this.Type != 1)
     {
         this.Travelers.Add(trav);
     }
     else
     {
         if (this.Travelers.Count == this.Exp.TravelersLimit)
         {
             throw new Exception("To many travelers in this experience.");
         }
         else
         {
             this.Travelers.Add(trav);
         }
     }
 }
Exemplo n.º 6
0
        public Traveler TheWinnerIs()
        {
            Traveler winner = null;

            foreach (var traveler in this.Players)
            {
                if (winner == null)
                {
                    winner = traveler;
                }
                else if (traveler.Points > winner.Points)
                {
                    winner = traveler;
                }
            }

            return(winner);
        }
Exemplo n.º 7
0
        /// <summary>
        /// En el método Host en este caso se verifica que el traveler que se recibió por parámetro no sea null.
        /// Luego se le pasa el objeto tipo Traveler como argumento al método RegisterPlayer de la superclase Landscape.
        /// Luego se calcula cuantos puntos se le van a asignar al viajero dependiendo de la cantidad de veces que haya pasado por la experiencia.
        /// </summary>
        /// <param name="player"></param>
        public override void Host(Traveler player)
        {
            if (player == null)
            {
                throw new TravelerNullException();
            }

            RegisterPlayer(player);

            if (PlayersRegistry[player] == 1)
            {
                player.AddScore(1);
            }
            else if (PlayersRegistry[player] > 1)
            {
                int suma = 1;

                for (int n = 1; n < PlayersRegistry[player]; n++)
                {
                    suma += 2;
                }
                player.AddScore(suma);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Método que permite movel al traveler.
        /// Recibe un objeto tipo traveler y una condición que de ser True le va a permitir al viajero entrar
        /// a las experiencias y sumar puntos y monedas, y de ser false se va a quedar en la "puerta" de la experiencia sin ganar nada.
        /// MakeMove utiliza un objeto Step pero funcionará correctamente si se utiliza un subtipo de step por lo que el método cumple con LSP.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="decision"></param>
        public void MakeMove(Traveler player, bool decision)
        {
            if (player == null)
            {
                throw new TravelerNullException("No puedes mover un Traveler null");
            }

            if (AreThereMovementsLeft())
            {
                Step actualStep = FindStepWithPlayer(player);
                if (actualStep == null)
                {
                    Data.GetFirstStep().PlayerArrival(player, decision);
                }
                else
                {
                    if (actualStep.NextStep != null)
                    {
                        actualStep.PlayerDeparture(player);
                        actualStep.NextStep.PlayerArrival(player, decision);
                    }
                }
            }
        }
Exemplo n.º 9
0
 public void AddTravelerToHistory(Traveler traveler)
 {
     this.TravelersHistory.Add(traveler);
 }
Exemplo n.º 10
0
 abstract public void DoExperience(Traveler trav);
Exemplo n.º 11
0
 override public void DoExperience(Traveler traveler)
 {
     traveler.Points += this.Points;
 }
Exemplo n.º 12
0
 override public void DoExperience(Traveler traveler)
 {
     traveler.Points += this.CalculatePoints(traveler);
     this.AddTravelerToHistory(traveler);
 }
Exemplo n.º 13
0
 public void RemoveTraveler(Traveler trav)
 {
     this.Travelers.Remove(trav);
 }
Exemplo n.º 14
0
 public void RealizeExperience(Traveler trav)
 {
     this.Exp.DoExperience(trav);
 }
Exemplo n.º 15
0
 override public void DoExperience(Traveler traveler)
 {
     traveler.Coins += this.Coins;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Método para expulsar a un Viajero de la Experiencia.
 /// </summary>
 /// <param name="traveler"> Recibe un Viajero por parametro</param>
 public void ExitTraveler(Traveler traveler)
 {
     this.Travelers.Remove(traveler);
     this.TravelersWithPoint.Remove(traveler);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Método abstracto que recibe un por parámetro un objeto tipo Traveler.
 /// </summary>
 /// <param name="player"></param>
 public abstract void RegisterPlayer(Traveler player);
Exemplo n.º 18
0
 /// <summary>
 /// Método que se ejecuta cuando un Viajero cambia de posición.
 /// </summary>
 /// <param name="observable"></param>
 public abstract void Update(Traveler observable);
Exemplo n.º 19
0
 /// <summary>
 /// Este método controla si el viajero quiere entrar al step.
 /// En caso de no querer, se tiene que especificar, sino entra por defecto.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="decision"></param>
 public abstract void PlayerArrival(Traveler player, bool decision = true);