Exemple #1
0
        public TrenElement AddTrack(TrenColor color, TrackPosition position, int length, TrenElement[] cities)
        {
            if (State != StateMachineStates.Setup)
            {
                throw new Exception("Must be in setup state");
            }
            if (cities == null || cities.Length == 0)
            {
                throw new Exception("Must provide a valid list of cities");
            }

            // create a track
            var row = Elements.Count;

            Elements.Add(new List <TrenElement>());
            var track = new TrenElement()
            {
                Type = TrenElementType.Track, Color = color, Position = position, Length = length, Row = row, Column = Elements[row].Count, InUse = true
            };

            // add the connecting cities
            for (int i = 0; i < cities.Length; i++)
            {
                if (cities[i].Type != TrenElementType.City)
                {
                    throw new Exception("Must provide valid cities");
                }
                track.Connections.Add(cities[i]);
            }
            // add
            Elements[row].Add(track);
            return(track);
        }
 public static TrenElement SetCoordinates(this TrenElement tren, int top, int left, int width, int height)
 {
     // construct points
     tren.Dimension = new BoardCell(new Point[]
     {
         new engine.Common.Point(x: left, y: top, z: 0),
         new engine.Common.Point(x: left, y: top + height, z: 0),
         new engine.Common.Point(x: left + width, y: top + height, z: 0),
         new engine.Common.Point(x: left + width, y: top, z: 0)
     });
     return(tren);
 }
Exemple #3
0
        //
        // Setup
        //
        public TrenElement AddCity(string cityName)
        {
            if (State != StateMachineStates.Setup)
            {
                throw new Exception("Must be in setup state");
            }

            // create a city
            var row  = (int)SpecialRows.Cities;
            var city = new TrenElement()
            {
                Type = TrenElementType.City, Name = cityName, Row = row, Column = Elements[row].Count
            };

            Elements[row].Add(city);
            return(city);
        }
Exemple #4
0
        public TrenElement AddDestination(TrenElement city1, TrenElement city2)
        {
            if (State != StateMachineStates.Setup)
            {
                throw new Exception("Must be in setup state");
            }
            if (city1 == null || city1.Type != TrenElementType.City ||
                city2 == null || city2.Type != TrenElementType.City)
            {
                throw new Exception("Must have two valid cities");
            }

            // create a new destination
            var elem = new TrenElement()
            {
                Type = TrenElementType.Destination
            };

            elem.Connections.Add(city1);
            elem.Connections.Add(city2);
            Elements[(int)SpecialRows.Destinations].Add(elem);

            return(elem);
        }
 public static TrenElement SetCoordinates(this TrenElement tren, Point[] points)
 {
     tren.Dimension = new BoardCell(points);
     return(tren);
 }