Ejemplo n.º 1
0
        static void Main()
        {
            DisplayStartingMessage();
            InitializeFields();

            if (!LoadFromFile()) //Attempt to load from file. If failed, generating new figures
            {
                shapes     = GenerateRandomShapes();
                originator = new Originator(new Checkpoint(ConvertShapesToString()));
                caretaker  = new Caretaker(originator);
                CreateCheckpoint();
            }

            Scene.Window.KeyPressed         += WindowOnKeyPressed; //Event subscriptions
            Scene.Window.MouseButtonPressed += WindowOnMouseButtonPressed;
            Scene.Window.Closed             += WindowOnClosed;

            while (Scene.Window.IsOpen) //Mainloop
            {
                Scene.Window.DispatchEvents();
                Vector2f offset = new Vector2f(0, 0);

                if (IsKeyPressed(Key.Up)) //Located here because these buttons can be held for a long time
                {
                    offset += new Vector2f(0, -1);
                }

                if (IsKeyPressed(Key.Down))
                {
                    offset += new Vector2f(0, 1);
                }

                if (IsKeyPressed(Key.Left))
                {
                    offset += new Vector2f(-1, 0);
                }

                if (IsKeyPressed(Key.Right))
                {
                    offset += new Vector2f(1, 0);
                }

                if (offset != new Vector2f(0, 0))
                {
                    MoveShapes(offset);
                }

                if (IsKeyPressed(Key.R))
                {
                    foreach (IShape shape in shapes.Where(shape => shape.Activated))
                    {
                        shape.MoveRound(degrees, new Vector2f(1, 1));
                    }
                    degrees++;
                }

                CheckCollisions();  //Also switches colors
                scene.LockWindow(); //Makes window impossible to remove or resize

                if (!trailEnabled)  //Clear window before every frame?
                {
                    Scene.Window.Clear();
                }

                for (int i = shapes.Count - 1; i >= 0; i--) //Display every figure in reversed order
                {
                    Scene.Window.Draw(shapes[i] as Drawable);
                }

                originator.Load(new Checkpoint(ConvertShapesToString())); //Change Originator state to relevant
                Scene.Window.Display();
            }

            Scene.Window.KeyPressed         -= WindowOnKeyPressed; //Event unsubscriptions
            Scene.Window.MouseButtonPressed -= WindowOnMouseButtonPressed;
            Scene.Window.Closed             -= WindowOnClosed;
        }
Ejemplo n.º 2
0
 public Caretaker(Originator originator)
 {
     this.originator = originator;
 }