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

            pbm.Add(flipper);

            Assert.IsTrue(pbm.Elements.Contains(flipper));
        }
Exemplo n.º 2
0
        private void Init()
        {
            _elements = new List<PinballElement>();
            _elements.Add(new Frame());

            // Add ramp
            _ramp = new StartingRamp();
            _elements.Add(_ramp);

            _ramp.X = Width - _ramp.Width -4;
            _ramp.Y = Height - _ramp.Height;

            // Add flippers
            Flipper lflipper = new LeftFlipper() { X = 148, Y = Height - 100 };
            _elements.Add(lflipper);

            Flipper rflipper = new RightFlipper() { X = 227, Y = Height - 100 };
            _elements.Add(rflipper);

            //Add Hole
            Hole h = new WideHole() { X = 148-40, Y = Height - 15 };
            h.Scale = .4f;
            _elements.Add(h);
        }
        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);
        }