public void CanAddElement()
        {
            PinballMachine pbm = new PinballMachine();
            Flipper flipper = new LeftFlipper() { X = 5, Y = 5 };

            pbm.Add(flipper);

            Assert.IsTrue(pbm.Elements.Contains(flipper));
        }
Ejemplo n.º 2
0
 // Tries to find entries that still need a destinatoin.
 protected override void EnterEditor(PinballMachine machine)
 {
     if (machine.DynamicElements == null) return; // if we're deserializing
     foreach (WormholeEntry entry in machine.DynamicElements.OfType<WormholeEntry>())
     {
         if (entry.WormholeExit == null) {
             entry.WormholeExit = this;
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// CLoses the currently managed form  and opens an editor.
        /// </summary>
        /// <param name="pbm"></param>
        public void OpenEditor(PinballMachine pbm = null)
        {
            CloseManagedForm();
            Hide();

            if (pbm == null)
                childForm = new EditorForm(this);
            else
                childForm = new EditorForm(pbm, this);

            childForm.Show();
            childForm.FormClosed += onChildClose;
        }
        public PinballGameMachine(PinballMachine machine)
            : base(machine.Layout.Clone() as IMachineLayout)
        {
            this.boundingRaster = new BoundingRaster((int)Math.Ceiling(Width / 60f), (int)Math.Ceiling(Height / 60f), Width, Height);

            // Copy constructor
            foreach (PinballElement element in machine.DynamicElements)
            {
                DynamicElements.Add((PinballElement)element.Clone());
            }
            Angle = machine.Angle;
            Gravity = machine.Gravity;
        }
Ejemplo n.º 5
0
        public Game(PinballMachine machine, string userName)
        {
            Status = GameStatus.Setup;

            OriginalMachine = machine;
            this.userName = userName;

            UpdateLoop = new Thread(new ThreadStart(BeginUpdate));
            UpdateLoop.Name = "Updater";
            UpdateLoop.Start();

            Start();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Closes the currently managed form and opens a game.
        /// </summary>
        /// <param name="pbm"></param>
        /// <param name="fileName"></param>
        public void OpenGame(PinballMachine pbm, string fileName)
        {
            CloseManagedForm();

            this.Hide();

            childForm = new PlayForm(pbm, this);
            ((PlayForm)childForm).ActivateScoreTracking(fileName);

            childForm.WindowState = FormWindowState.Maximized;
            childForm.Show();

            childForm.FormClosed += onChildClose;
        }
        public void CanSerializeTwiceIntoSameFile()
        {
            // Arrange
            var mShorter = new PinballMachine();
            var mLonger = new PinballMachine();
            string file = Path.GetTempFileName();
            mLonger.Add(new Bumper());

            // Act
            mLonger.Save(file);
            mShorter.Save(file);

            var newMachine = PinballMachine.FromFile(file);
            Assert.IsTrue(newMachine.IsValid());
        }
        public void CanDeserialize()
        {
            PinballMachine pbm = new PinballMachine();
            PinballMachine pbm2;
            string fileName = Path.GetTempFileName();

            pbm.Save(fileName);
            pbm2 = PinballMachine.FromFile(fileName);

            Assert.IsNotNull(pbm2);
            Assert.AreEqual(pbm.Elements.Count(), pbm2.Elements.Count());

            // Cleanup
            File.Delete(fileName);
        }
        public PinballEditControl()
            : base()
        {
            PinballMachine = new PinballMachine();
            History = new Sketchball.History();

            SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
            //Effect = new DropShadowEffect();

            selectionPen = new Pen(Brushes.Black, 1);
            selectionPen.DashStyle = DashStyles.Dash;
            //SelectionPen.DashStyle = DashStyle.Dash;

            UpdateSize();

            History.Change += () => { Invalidate(); };
        }
        public void CanSerialize()
        {
            // Arrange
            PinballMachine pbm = new PinballMachine();
            string fileName = Path.GetTempFileName();
            FileInfo info;

            // Act
            pbm.Save(fileName);
            info = new FileInfo(fileName);

            // Assert
            Assert.IsTrue( info.Length > 0 );

            // Cleanup
            File.Delete(fileName);
        }
Ejemplo n.º 11
0
        // Try to find an exit that fits our needs.
        protected override void EnterEditor(PinballMachine machine)
        {
            if (machine.DynamicElements == null) return; // may happen if we're deserializing
            if (WormholeExit == null)
            {
                // Let's search for one
                var exits = machine.DynamicElements.OfType<WormholeExit>();
                var occupiedExits = machine.DynamicElements.OfType<WormholeEntry>()
                                                           .Where((el) => { return el.WormholeExit != null; })
                                                           .Select((el) => { return el.WormholeExit; });

                var freeExits = exits.Except(occupiedExits).ToList();

                if (freeExits.Count > 0)
                {
                    WormholeExit = freeExits.Last();
                }
            }
        }
Ejemplo n.º 12
0
        public PlayForm(PinballMachine pbm, SelectionForm selectionForm)
        {
            InitializeComponent();

            // Initialize game
            originalMachine = pbm;
            game = new Game(pbm, Environment.UserName);
            gameView = new GameView(game);
            gameContainer = new WPFContainer(gameView);
            game.GameOver += onGameOver;
            //this.MinimumSize = gameView.MinimumSize;
            gameView.MouseUp += onMouseUp;
            gameView.MouseMove += onMouseMove;
            // Fill entire space
            gameContainer.Dock = DockStyle.Fill;

            mainContainer.ContentPanel.Controls.Add(gameContainer);

            this.selectionForm = selectionForm;

            debugModeButton.Checked =  Properties.Settings.Default.Debug;
        }
Ejemplo n.º 13
0
 public PlayForm(PinballMachine pbm)
     : this(pbm, null)
 {
 }
Ejemplo n.º 14
0
        public object Clone()
        {
            PinballMachine machine = new PinballMachine(Layout);

            machine.Angle = Angle;
            machine.Gravity = Gravity;

            // Clone elements
            // (clone static ones just to be sure their settings are OK)
            machine.StaticElements = new ElementCollection(machine);
            foreach (PinballElement element in StaticElements)
            {
                machine.StaticElements.Add((PinballElement)element.Clone());
            }

            machine.DynamicElements = new ElementCollection(machine);
            foreach (PinballElement element in DynamicElements)
            {
                machine.DynamicElements.Add((PinballElement)element.Clone());
            }

            machine.Layout = Layout.Clone() as IMachineLayout;
            machine.Highscores = new HighscoreList();
            foreach (var entry in Highscores)
            {
                machine.Highscores.Add(new HighscoreEntry(entry.Player, entry.Score, entry.Date));
            }
            return machine;
        }
        public void ShouldBeValidForParallelLines()
        {
            var machine = new PinballMachine();
            var line1 = new Line(100, 100, 100, 200);
            var line2 = new Line(105, 100, 105, 200);

            machine.Add(line1);
            machine.Add(line2);

            Assert.IsTrue(machine.IsValid());
        }
Ejemplo n.º 16
0
 protected virtual void EnterEditor(PinballMachine machine)
 {
 }
Ejemplo n.º 17
0
 // Loads a machine
 private void loadMachine(PinballMachine pbm)
 {
     PlayFieldEditor.LoadMachine(pbm);
     machineInspector.SelectedObject = pbm;
 }
        public void CanSerializeWithUserObject()
        {
            PinballMachine pbm = new PinballMachine();
            PinballMachine pbm2;
            Flipper flipper = new LeftFlipper() { X = 5, Y = 5 };
            Stream stream = new MemoryStream();

            pbm.Add(flipper);
            pbm.Save(stream);
            stream.Position = 0;
            pbm2 = PinballMachine.FromStream(stream);

            Assert.AreEqual(1, pbm2.DynamicElements.Count);
            Assert.AreEqual(flipper.X, pbm2.DynamicElements.Last().X, 0.1);
            Assert.AreEqual(flipper.Y, pbm2.DynamicElements.Last().Y, 0.1);
        }
        public void ShouldMaintainCorrectRelationship()
        {
            var machine = new PinballMachine();
            var flipper = new LeftFlipper();

            Assert.IsNull(flipper.World);

            machine.Add(flipper);

            Assert.AreEqual(machine, flipper.World);

            machine.Remove(flipper);

            Assert.IsNull(flipper.World);
        }
        public void HasBidirectionalConsistencyAfterDeserialization()
        {
            PinballMachine pbm = new PinballMachine();
            PinballMachine pbm2;
            Stream stream = new MemoryStream();

            pbm.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);
            pbm2 = PinballMachine.FromStream(stream);

            Assert.AreSame(pbm2, pbm2.DynamicElements.Owner);
        }
        public void ShouldDeepCloneReferences()
        {
            var machine = new PinballMachine();
            var element = new Bumper();
            var entry = new HighscoreEntry("Simon", 1, DateTime.Now);

            machine.Add(element);
            machine.Highscores.Add(entry);
            var copy = machine.Clone() as PinballMachine;

            Assert.AreNotSame(copy, machine);
            Assert.AreNotSame(copy.Balls, machine.Balls);
            Assert.AreNotSame(copy.Highscores, machine.Highscores);
            Assert.AreNotSame(copy.Highscores.First(), machine.Highscores.First());
            Assert.AreNotSame(copy.Layout, machine.Layout);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Loads a fresh machine into the editor.
        /// </summary>
        /// <param name="machine">Machine to be loaded.</param>
        public void LoadMachine(PinballMachine machine)
        {
            PinballMachine = machine;
            History.Clear();
            SelectedElement = null;

            Invalidate();
        }
Ejemplo n.º 23
0
 protected PinballControl(PinballMachine machine)
     : base()
 {
 }
Ejemplo n.º 24
0
 public void Setup()
 {
     user = "******";
     pbm = new PinballMachine();
     game = new Game(pbm, user);
 }
Ejemplo n.º 25
0
 // Removes itself from the references of entries.
 protected override void LeaveEditor(PinballMachine machine)
 {
     foreach (WormholeEntry entry in Entries)
     {
         entry.WormholeExit = null;
     }
 }
Ejemplo n.º 26
0
 public EditorForm(PinballMachine pbm, SelectionForm selectionForm)
     : this()
 {
     this.selectionForm = selectionForm;
     loadMachine(pbm);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes the machine with a layout.
 /// !!! Only use once on a machine !!!
 /// </summary>
 /// <param name="machine"></param>
 public void Apply(PinballMachine machine)
 {
     machine.StaticElements.Clear();
     foreach (PinballElement el in _elements) machine.StaticElements.Add(el);
 }
Ejemplo n.º 28
0
 protected virtual void LeaveEditor(PinballMachine machine)
 {
 }
        public void ShouldBeInvalidForCrossingLines()
        {
            var machine = new PinballMachine();
            var line1 = new Line(100, 100, 100, 200);
            var line2 = new Line(50, 150, 150, 150);

            machine.Add(line1);
            machine.Add(line2);

            Assert.IsFalse(machine.IsValid());
        }