示例#1
0
 public BoardRoute(City origin, City destination, TrainColor color, int length)
 {
     Origin      = origin;
     Destination = destination;
     Color       = color;
     Length      = length;
 }
示例#2
0
 public void CollectCars(TrainColor color, int cars)
 {
     CollectedCarsScore.TryGetValue(color, out int score);
     CollectedCarsScore[color] = score + cars;
     OnScoreUpdated?.Invoke();
     CheckVictory();
 }
示例#3
0
 public BoardRoute(City origin, City destination, TrainColor color, int length, bool isTunnel)
 {
     Origin      = origin;
     Destination = destination;
     Color       = color;
     Length      = length;
     IsTunnel    = isTunnel;
 }
示例#4
0
 public BoardRoute(City origin, City destination, TrainColor color, int length, int locomotiveCount)
 {
     Origin          = origin;
     Destination     = destination;
     Color           = color;
     Length          = length;
     LocomotiveCount = locomotiveCount;
 }
示例#5
0
 public CityConnection(int id, CityName city1, CityName city2, TrainColor trainColor, int length)
 {
     Id         = id;
     City1      = city1;
     City2      = city2;
     TrainColor = trainColor;
     Length     = length;
 }
示例#6
0
    public TrainColorSettings GetColorSettings(TrainColor trainColor)
    {
        foreach (var type in SettingsPerTrainColor)
        {
            if (type.TrainColor == trainColor)
            {
                return(type);
            }
        }

        return(default);
        private List <TrainCard> CreateSingleColorCollection(TrainColor color, int count)
        {
            List <TrainCard> cards = new List <TrainCard>();

            for (int i = 0; i < count; i++)
            {
                cards.Add(new TrainCard()
                {
                    Color = color
                });
            }
            return(cards);
        }
示例#8
0
        public static List <TrainCard> GetMatching(this List <TrainCard> cards, TrainColor color, int count)
        {
            if (cards.Where(x => x.Color == color).Count() >= count)
            {
                var selectedCards = cards.Where(x => x.Color == color).Take(count).ToList();
                foreach (var card in selectedCards)
                {
                    cards.Remove(card);
                }

                return(selectedCards);
            }

            return(new List <TrainCard>());
        }
示例#9
0
文件: Train.cs 项目: JammedGame/LD47
 public Train(GameWorld world, TrainSpawn trainSpawn)
 {
     this.world              = world;
     this.tile               = world.GetTile(trainSpawn.X, trainSpawn.Y) ?? throw new Exception($"Train at invalid position: [{trainSpawn.X}, {trainSpawn.Y}]");
     this.spawnTile          = tile;
     this.progressInsideTile = 0.5f;
     this.direction          = trainSpawn.Direction;
     this.tileEnterDirection = direction.Opposite();
     this.positionHistory    = new PositionStateHistory(1000, GetSnapshot());
     this.type               = trainSpawn.Type;
     this.color              = trainSpawn.Color;
     this.cars               = trainSpawn.InitialCars;
     this.initialCars        = this.cars;
     this.speed              = trainSpawn.Type.GetSpeed();
 }
示例#10
0
    /// <summary>
    /// Removes all cargos for color and returns how much train should get.
    /// </summary>
    public int RemoveAllFor(TrainColor color)
    {
        int count = 0;

        for (int i = 0; i < Cargos.Count; i++)
        {
            Cargo cargo = Cargos[i];
            if (cargo.Color == color)
            {
                Cargos.RemoveAt(i--);
                count++;
            }
        }

        if (count > 0)
        {
            OnUpdate?.Invoke();
            SoundManager.Instance.PlaySoundCargoPickUp();
        }

        return(count);
    }
        public bool ClaimRoute(BoardRoute route, TrainColor color)
        {
            //If we don't have enough train cars remaining to claim this route, we cannot do so.
            if (route.Length > RemainingTrainCars)
            {
                return(false);
            }

            //First, see if we have enough cards in the hand to claim this route.
            var colorCards = Hand.Where(x => x.Color == color).ToList();

            //If we don't have enough color cards for this route...
            if (colorCards.Count < route.Length)
            {
                //...see if we have enough Locomotive cards to fill the gap
                var gap             = route.Length - colorCards.Count;
                var locomotiveCards = Hand.Where(x => x.Color == TrainColor.Locomotive).ToList();
                if (locomotiveCards.Count < gap)
                {
                    return(false); //Cannot claim this route.
                }

                var matchingWilds = Hand.GetMatching(TrainColor.Locomotive, gap);
                Board.DiscardPile.AddRange(matchingWilds);

                if (matchingWilds.Count != route.Length)
                {
                    var matchingColors = Hand.GetMatching(colorCards.First().Color, colorCards.Count);
                    Board.DiscardPile.AddRange(matchingColors);
                }


                Board.Routes.ClaimRoute(route, this.Color);

                //Add the cities to the list of connected cities
                ConnectedCities.Add(route.Origin);
                ConnectedCities.Add(route.Destination);

                ConnectedCities = ConnectedCities.Distinct().ToList();

                RemainingTrainCars = RemainingTrainCars - route.Length;

                Console.WriteLine(Name + " claims the route " + route.Origin + " to " + route.Destination + " (" + color + ")!");

                return(true);
            }

            //If we only need color cards to claim this route, discard the appropriate number of them
            var neededColorCards = Hand.Where(x => x.Color == color).Take(route.Length).ToList();

            foreach (var colorCard in neededColorCards)
            {
                Hand.Remove(colorCard);
                Board.DiscardPile.Add(colorCard);
            }

            //Mark the route as claimed on the board
            Board.Routes.ClaimRoute(route, this.Color);

            RemainingTrainCars = RemainingTrainCars - route.Length;

            Console.WriteLine(Name + " claims the route " + route.Origin + " to " + route.Destination + " (" + color + ")!");

            return(true);
        }
示例#12
0
 public void AddRoute(City origin, City destination, TrainColor color, int length)
 {
     Routes.Add(new BoardRoute(origin, destination, color, length));
 }
示例#13
0
 public static Texture LoadLocomotiveTexture(this TrainColor trainColor)
 {
     return(GameSettings.Instance.SettingsPerTrainColor.Find(s => s.TrainColor == trainColor)?.LocomotiveIcon);
 }
示例#14
0
 public static Color ToColor(this TrainColor trainColor)
 {
     return(GameSettings.Instance.SettingsPerTrainColor.Find(s => s.TrainColor == trainColor)?.Color ?? Color.black);
 }
示例#15
0
 public static Texture LoadCarTexture(this TrainColor trainColor)
 {
     return(GameSettings.Instance.SettingsPerTrainColor.Find(s => s.TrainColor == trainColor)?.CarIcon);
 }
示例#16
0
文件: Cargo.cs 项目: JammedGame/LD47
 public Cargo(TrainColor color, float secondsUntilDespawn)
 {
     Color = color;
 }