Ejemplo n.º 1
0
 private bool GetNewDirection()
 {
     Rotation[] rotations = TrainNetworkRegistry.GetDirections(this);
     if (rotations.Length == 0)
     {
         RotateTrain();
         TMConsole.Log("Train turned due to not being able to move further.", this);
         return(false);
     }
     else
     {
         Direction = rotations[tempRandom.Next(rotations.Length)];
         return(true);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiate an object of the given type
        /// </summary>
        /// <param name="type">The type to instantiate</param>
        /// <param name="x">The x location where this new item needs to be</param>
        /// <param name="y">The y location where this new item needs to be</param>
        /// <param name="width">The width of the item, can be omitted if not needed</param>
        /// <param name="height">The height of the item, can be omitted if not needed</param>
        /// <returns>A GridObject if successfull, otherwise null</returns>
        public static GridObject InstantiateObject(Type type, int x, int y, int width = 1, int height = 1, Rotation rotation = Rotation.Top)
        {
            switch (type.Name)
            {
            case "Rail": return(new Rail(x, y, rotation));

            case "Station": return(new Station(x, y, width, height, rotation));

            case "CurvedRail": return(new CurvedRail(x, y, rotation));

            default:
                TMConsole.LogError("Failed to instantiate type " + type.FullName + ". It is not know in the method GridObject.InstantiateObject");
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static Rotation Rotate(Rotation rotate, bool clockwise = true)
        {
            switch (rotate)
            {
            case Rotation.Top:
                return(clockwise ? Rotation.Right : Rotation.Left);

            case Rotation.Bottom:
                return(clockwise ? Rotation.Left : Rotation.Right);

            case Rotation.Right:
                return(clockwise ? Rotation.Bottom : Rotation.Top);

            case Rotation.Left:
                return(clockwise ? Rotation.Top : Rotation.Bottom);

            default:
                TMConsole.LogError("Invalid value received in RailUtils.Rotate", rotate);
                return(Rotation.Top);
            }
        }
Ejemplo n.º 4
0
        public static Rotation OppositeRotation(Rotation rotation)
        {
            switch (rotation)
            {
            case Rotation.Top:
                return(Rotation.Bottom);

            case Rotation.Left:
                return(Rotation.Right);

            case Rotation.Right:
                return(Rotation.Left);

            case Rotation.Bottom:
                return(Rotation.Top);

            default:
                TMConsole.LogError("Invalid value received in RailUtils.OppositeRotation", rotation);
                return(Rotation.Top);
            }
        }
Ejemplo n.º 5
0
 public void StopGame()
 {
     graphics.Stop();
     TMConsole.Log("Waiting for graphics to stop");
     while (graphics.IsRunning)
     {
         System.Threading.Thread.Sleep(5);
     }
     TMConsole.Log("Waiting for console to stop");
     if (GlobalVars.CONSOLE)
     {
         TMConsole.Stop();
         while (TMConsole.IsStarted)
         {
             System.Threading.Thread.Sleep(5);
         }
     }
     if (!form.Stopping)
     {
         form.Close();
     }
     InputHandler.OnClick -= OnClick;
 }