Ejemplo n.º 1
0
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }

            this._state = memento.GetState();
            Console.Write($"Originator: My state has changed to: {_state}");
        }
Ejemplo n.º 2
0
        private void UndoConfig_OnClickCallback()
        {
            caretaker.Undo();
            ConcreteMemento memento = caretaker.getCurrent() as ConcreteMemento;

            if (memento != null)
            {
                config = memento.GetState();
            }
            UpdateTank();
        }
Ejemplo n.º 3
0
        public override void Load()
        {
            config     = new TankConfig(0, 0, 0, 0);
            originator = new Originator(config);
            caretaker  = new Caretaker(originator);
            caretaker.Backup();
            logo = CreateEntity(new Sprite(Image.FromFile("../../res/logo.png"), new Vector2(380, 80), new Vector2(500, 250))) as Sprite;
            UpdateTank();
            //Color edits
            colorDown = CreateEntity(new Button(300, 260, 15, 15, null, "<")) as Button;
            colorUp   = CreateEntity(new Button(400, 260, 15, 15, null, ">")) as Button;
            colorDown.OnClickCallback += ColorDown_OnClickCallback;
            colorUp.OnClickCallback   += ColorUp_OnClickCallback;

            //Chassis edits
            chassisDown = CreateEntity(new Button(300, 300, 15, 15, null, "<")) as Button;
            chassisUp   = CreateEntity(new Button(400, 300, 15, 15, null, ">")) as Button;
            chassisDown.OnClickCallback += ChassisDown_OnClickCallback;
            chassisUp.OnClickCallback   += ChassisUp_OnClickCallback;

            //Turret edits
            turretDown = CreateEntity(new Button(300, 280, 15, 15, null, "<")) as Button;
            turretUp   = CreateEntity(new Button(400, 280, 15, 15, null, ">")) as Button;
            turretDown.OnClickCallback += TurretDown_OnClickCallback;
            turretUp.OnClickCallback   += TurretUp_OnClickCallback;

            //Tracks edits
            tracksDown = CreateEntity(new Button(300, 320, 15, 15, null, "<")) as Button;
            tracksUp   = CreateEntity(new Button(400, 320, 15, 15, null, ">")) as Button;
            tracksDown.OnClickCallback += TracksDown_OnClickCallback;
            tracksUp.OnClickCallback   += TracksUp_OnClickCallback;

            saveConfig = CreateEntity(new Button(300, 360, 120, 15, null, "Save tank configuration")) as Button;
            saveConfig.OnClickCallback += SaveConfig_OnClickCallback;

            undoConfig = CreateEntity(new Button(300, 390, 120, 15, null, "Undo tank configuration")) as Button;
            undoConfig.OnClickCallback += UndoConfig_OnClickCallback;


            showHistory = CreateEntity(new Button(300, 420, 120, 15, null, "Show config history")) as Button;
            showHistory.OnClickCallback += ShowHistory_OnClickCallback;;

            backButton = CreateEntity(new Button(10, 400, 40, 15, null, "BACK")) as Button;
            backButton.OnClickCallback += BackButton_OnClickCallback;
        }
Ejemplo n.º 4
0
 public Originator(TankConfig state)
 {
     this._state = state;
     Console.WriteLine("Originator: My initial state is: " + state.ToString());
 }
Ejemplo n.º 5
0
 public ConcreteMemento(TankConfig state)
 {
     this._state = state;
     this._date  = DateTime.Now;
 }