public PointerTool(ITrainController gameState, IGameBoard gameBoard, IPixelMapper pixelMapper, ILayout <Track> trackLayout) { _gameState = gameState; _gameBoard = gameBoard; _pixelMapper = pixelMapper; _trackLayout = trackLayout; }
public ControlPanel() { InitializeComponent(); journey = new TrainJourney(); controller = new TrainController(journey); }
public MainPage(IGame game, IPixelMapper pixelMapper, OrderedList <ITool> tools, OrderedList <ILayerRenderer> layers, OrderedList <ICommand> commands, ITrainController trainControls, ITrackParameters trackParameters, ITrackLayout trackLayout, IGameStorage gameStorage) { this.Title("Trains - " + ThisAssembly.AssemblyInformationalVersion); var controlDelegate = new TrainsDelegate(game, pixelMapper); _miniMapDelegate = new MiniMapDelegate(trackLayout, trackParameters, pixelMapper); this.Body = () => { return(new HStack() { new VStack() { new ToggleButton("Configuration", _configurationShown, () => _configurationShown.Value = !_configurationShown.Value), new Spacer(), _configurationShown ? CreateConfigurationControls(layers) : CreateToolsControls(tools, controlDelegate), new Spacer(), _configurationShown ? null : CreateCommandControls(commands), new Spacer(), new DrawableControl(_miniMapDelegate).Frame(height: 100) }.Frame(100, alignment: Alignment.Top), new VStack() { new TrainControllerPanel(trainControls), new DrawableControl(controlDelegate) } }.FillHorizontal()); }; _timer = new GameTimer(); _timer.Interval = 16; _timer.Elapsed += (s, e) => { game.AdjustViewPortIfNecessary(); ThreadHelper.Run(async() => { await ThreadHelper.SwitchToMainThreadAsync(); controlDelegate.Invalidate(); _miniMapDelegate.Invalidate(); }); }; _timer.Start(); _trackLayout = trackLayout; _gameStorage = gameStorage; }
/// <summary> /// Train arrived at a station /// </summary> /// <param name="train">Train</param> /// <param name="stationName">Name of the station</param> private void OnTrainAtStation(ITrainController train, string stationName) { if (stationName != null && train != null) { if (stationName.Contains(Constants.TRAINYARD)) { //Train arrived at the train yard. Destroy it. m_log.LogInfo("Train has arrived at the train yard"); m_trainControllerList.Remove(train); train.Dispose(); } } }
public TrainControllerPanel(ITrainController trainControls) : base(VerticalAlignment.Center, null) { Add(new HStack() { new Text(trainControls.Display), new Button("Stop", trainControls.Stop), new Button("Slower", trainControls.Slower), new Text(trainControls.SpeedDisplay), new Button("Faster", trainControls.Faster), new Button("Go", trainControls.Start), new Button("Delete", trainControls.Delete) }); }
private const int _maxCapacity = 222; // 74 seated, 148 standing #endregion #region Constructors /// <summary> /// This constructor is used when passenger, crew, and temperature information is not given. /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius. /// </summary> /// <param name="trainID">The ID to give to the train.</param> /// <param name="startingBlock">The starting block of the train.</param> /// <param name="environment">The environment being used by the entire simulation.</param> public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment) { _environment = environment; _environment.Tick += _environment_Tick; _trainID = trainID; _totalMass = calculateMass(); _informationLog = ""; _informationCount = 0; _lightsOn = false; _doorsOpen = false; _temperature = 32; _currentAcceleration = 0; _currentVelocity = 0; _currentPosition = 0; _numPassengers = 0; _numCrew = 0; _brakeFailure = false; _engineFailure = false; _signalPickupFailure = false; _emergencyBrakePulled = false; _positionWarningGiven = false; _velocityWarningGiven = false; _accelerationWarningGiven = false; _decelerationWarningGiven = false; _currentBlock = startingBlock; _previousBlockID = 0; _currentBlockID = _currentBlock.BlockID; _blockLength = _currentBlock.BlockSize; _trackCircuitID = _currentBlock.TrackCirID; _trackModel = environment.TrackModel; _trainController = new TrainController.TrainController(_environment, this); // set allTrains equal to list contained in environment allTrains = environment.AllTrains; _timeInterval = (environment.GetInterval() / 1000.0); appendInformationLog("Created on block " + _currentBlockID + "."); }
public MainPage(IGame game, IPixelMapper pixelMapper, ITrackParameters trackParameters, OrderedList <ITool> tools, OrderedList <ILayerRenderer> layers, OrderedList <ICommand> commands, ITrainController trainControls) { this.Title("Train.NET - " + ThisAssembly.AssemblyInformationalVersion); var controlDelegate = new TrainsDelegate(game, pixelMapper); this.Body = () => { return(new HStack() { new VStack() { new ToggleButton("Configuration", _configurationShown, () => _configurationShown.Value = !_configurationShown.Value), new Spacer(), _configurationShown ? CreateConfigurationControls(trackParameters, layers) : CreateToolsControls(tools, controlDelegate), new Spacer(), _configurationShown ? null : CreateCommandControls(commands), new Spacer() }.Frame(100, alignment: Alignment.Top), new VStack() { new TrainControllerPanel(trainControls), new DrawableControl(controlDelegate).FillVertical() } }.FillHorizontal()); }; _timer = new Timer((state) => { ThreadHelper.Run(async() => { await ThreadHelper.SwitchToMainThreadAsync(); controlDelegate.Invalidate(); }); }, null, 0, 16); }
public TrainTool(IGameBoard gameBoard, ILayout <Track> trackLayout, ITrainController gameState) { _gameBoard = gameBoard; _trackLayout = trackLayout; _gameState = gameState; }
public PointerTool(ITrainController gameState, IGameBoard gameBoard, IPixelMapper pixelMapper) { _gameState = gameState; _gameBoard = gameBoard; _pixelMapper = pixelMapper; }
public MainPage(IGame game, IPixelMapper pixelMapper, OrderedList <ITool> tools, OrderedList <ILayerRenderer> layers, OrderedList <ICommand> commands, ITrainController trainControls, ITrackParameters trackParameters, ITrackLayout trackLayout, IGameStorage gameStorage, ITimer gameTimer, Factory <IToolPreviewer> previewerFactory) { this.Title("Trains - " + ThisAssembly.AssemblyInformationalVersion); var controlDelegate = new TrainsDelegate(game, pixelMapper, previewerFactory); _miniMapDelegate = new MiniMapDelegate(trackLayout, trackParameters, pixelMapper); this.Body = () => { return(new HStack() { new VStack() { _configurationShown?null: new Button(trainControls.BuildMode ? "Building" : "Playing", () => SwitchGameMode()), new Spacer(), _configurationShown ? CreateConfigurationControls(layers) : CreateToolsControls(tools, controlDelegate, trainControls.BuildMode.Value), new Spacer(), _configurationShown || !trainControls.BuildMode ? null : CreateCommandControls(commands), new Spacer(), new Button("Configuration", () => _configurationShown.Value = !_configurationShown.Value), new DrawableControl(_miniMapDelegate).Frame(height: 100) }.Frame(100, alignment: Alignment.Top), new VStack() { new TrainControllerPanel(trainControls), new DrawableControl(controlDelegate) } }.FillHorizontal()); }; _gameTimer = gameTimer; _gameTimer.Elapsed += (s, e) => { game.AdjustViewPortIfNecessary(); controlDelegate.FlagDraw(); _miniMapDelegate.FlagDraw(); ThreadHelper.Run(async() => { await ThreadHelper.SwitchToMainThreadAsync(); controlDelegate.Invalidate(); _miniMapDelegate.Invalidate(); }); }; _trackLayout = trackLayout; _gameStorage = gameStorage; void SwitchGameMode() { trainControls.ToggleBuildMode(); if (controlDelegate == null) { return; } controlDelegate.CurrentTool.Value = tools.FirstOrDefault(t => ShouldShowTool(trainControls.BuildMode, t)); } }
private void ControlPanel_Load(object sender, EventArgs e) { journey = new TrainJourney(); controller = new TrainController(journey); }
public PointerTool(ITrainController gameState, IGameBoard gameBoard) { _gameState = gameState; _gameBoard = gameBoard; }
public TrainTool(IGameBoard gameBoard, ITrainController gameState) { _gameBoard = gameBoard; _gameState = gameState; }
void myTrainController_TrainAtStation(ITrainController trainController, string stationName) { station = stationName; }
public MainPage(IGame game, IEnumerable <ITool> tools, IEnumerable <ILayerRenderer> layers, IEnumerable <ICommand> commands, ITrainController trainControls, ILayout trackLayout, IGameStorage gameStorage, ITerrainMap terrainMap, MiniMapDelegate miniMapDelegate, TrainsDelegate trainsDelegate) { this.Title("Trains - " + ThisAssembly.AssemblyInformationalVersion); _game = game; _controlDelegate = trainsDelegate; _miniMapDelegate = miniMapDelegate; this.Body = () => { return(new HStack() { new VStack() { _configurationShown?null: new Button(trainControls.BuildMode ? "Building" : "Playing", () => SwitchGameMode()), new Spacer(), _configurationShown ? CreateConfigurationControls(layers) : CreateToolsControls(tools, _controlDelegate, trainControls.BuildMode.Value), new Spacer(), _configurationShown || !trainControls.BuildMode ? null : CreateCommandControls(commands), new Spacer(), new HStack() { new Button(" - ", () => _game.Zoom(-1)) .Frame(40), new Spacer(), new Button(" + ", () => _game.Zoom(1)) .Frame(40), }, new Spacer(), new Button("Snapshot", () => Snapshot()), new Button("Configuration", () => _configurationShown.Value = !_configurationShown.Value), new DrawableControl(_miniMapDelegate).Frame(height: 100) }.Frame(100, alignment: Alignment.Top), new VStack() { new TrainControllerPanel(trainControls), new DrawableControl(_controlDelegate) } }.FillHorizontal()); }; _trackLayout = trackLayout; _gameStorage = gameStorage; _ = PresentLoop(); void SwitchGameMode() { trainControls.ToggleBuildMode(); if (_controlDelegate == null) { return; } _controlDelegate.CurrentTool.Value = tools.FirstOrDefault(t => ShouldShowTool(trainControls.BuildMode, t)); } void Snapshot() { (int width, int height) = _game.GetSize(); using var bitmap = new SKBitmap(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul); using var skCanvas = new SKCanvas(bitmap); using (ICanvas canvas = new SKCanvasWrapper(skCanvas)) { canvas.Save(); _game.Render(canvas); canvas.Restore(); } Clipboard.SetImage(bitmap.ToWriteableBitmap()); } _terrainMap = terrainMap; }
/// <summary> /// This constructor is used when passenger, crew, and temperature information is not given. /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius. /// </summary> /// <param name="trainID">The ID to give to the train.</param> /// <param name="startingBlock">The starting block of the train.</param> /// <param name="environment">The environment being used by the entire simulation.</param> public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment) { _environment = environment; _environment.Tick += _environment_Tick; _trainID = trainID; _totalMass = calculateMass(); _informationLog = ""; _informationCount = 0; _lightsOn = false; _doorsOpen = false; _temperature = 32; _currentAcceleration = 0; _currentVelocity = 0; _currentPosition = 0; _numPassengers = 0; _numCrew = 0; _brakeFailure = false; _engineFailure = false; _signalPickupFailure = false; _emergencyBrakePulled = false; _positionWarningGiven = false; _velocityWarningGiven = false; _accelerationWarningGiven = false; _decelerationWarningGiven = false; _currentBlock = startingBlock; _previousBlockID = 0; _currentBlockID = _currentBlock.BlockID; _blockLength = _currentBlock.BlockSize; _trackCircuitID = _currentBlock.TrackCirID; _trackModel = environment.TrackModel; _trainController = new TrainController.TrainController(_environment, this); // set allTrains equal to list contained in environment allTrains = environment.AllTrains; _timeInterval = (environment.GetInterval() / 1000.0); appendInformationLog("Created on block " + _currentBlockID + "."); }