public override Train CreateTrain(TrainInfo element)
        {
            TrainElement locomotive = locomotivesPool.RealeseObject().GetComponent <TrainElement>();

            locomotive.Position = element.headPosition.position;
            locomotive.Rotation = element.headPosition.rotateDegree;

            Train train = null;

            if (element.type == TypeTrain.Suburban)
            {
                train = new SuburbanTrain(locomotive, element.trainColor, element.fromArrive, element.turnsDelayCount);
            }
            else if (element.type == TypeTrain.Express)
            {
                train = new ExpressTrain(locomotive, element.trainColor, element.fromArrive, element.turnsDelayCount);
            }

            for (int i = 0; i < element.carriagePositions.Count; i++)
            {
                TrainElement carriage = carriagesPool.RealeseObject().GetComponent <TrainElement>();
                train.AddCarriage(carriage, element.carriagePositions[i]);
            }

            return(train);
        }
示例#2
0
 // --------------- Manage of carriage ---------------------
 public void AddCarriage(TrainElement carriage, StateTrainElement state)
 {
     carriage.SetColor(trainColor);
     carriage.Position = state.position;
     carriage.Rotation = state.rotateDegree;
     head.AddCarriage(carriage);
 }
示例#3
0
 // -------------- Initialize ------------------
 public Train(TrainElement head, Color color, TileSides from, int rate)
 {
     this.head    = head;
     trainColor   = color;
     fromArrive   = from;
     isEnable     = true;
     clockPerTurn = rate;
     head.SetColor(color);
 }
示例#4
0
 public virtual void DisconnectBackCarriage()
 {
     if (backTrainElement == null)
     {
         return;
     }
     backTrainElement.DisconnectFrontCarriage();
     backTrainElement = null;
 }
示例#5
0
 // --------------------- Connection ----------------------
 public virtual void AddCarriage(TrainElement carriage)
 {
     if (backTrainElement != null)
     {
         backTrainElement.AddCarriage(carriage);
     }
     else
     {
         ConnectBackCarriage(carriage);
     }
 }
示例#6
0
 public SuburbanTrain(TrainElement head, Color color, TileSides from, int rate) : base(head, color, from, rate)
 {
 }
示例#7
0
 protected override void ConnectFrontCarriage(TrainElement carriage)
 {
     frontTrainElement = carriage;
 }
示例#8
0
 public virtual void ConnectBackCarriage(TrainElement carriage)
 {
     backTrainElement = carriage;
     carriage.ConnectFrontCarriage(this);
 }
示例#9
0
 protected virtual void ConnectFrontCarriage(TrainElement carriage)
 {
 }
示例#10
0
 public ExpressTrain(TrainElement head, Color color, TileSides from, int rate) : base(head, color, from, rate)
 {
 }