Пример #1
0
        public void Draw(SpriteBatch batch, float deltaTime)
        {
            UITransformComponent transform = GetComponent <UITransformComponent>();

            if (transform != null)
            {
                Rectangle bounds = transform.Bounds();
                batch.DrawString(m_Font, InterpolateDisplay(m_CurrentCoins, deltaTime, m_InterpolationTime).ToString(), new Vector2(bounds.Center.X, bounds.Y), Color.White);

                if (m_Interpolating)
                {
                    batch.Draw(
                        texture: m_CoinTexture,
                        sourceRectangle: new Rectangle(m_CoinWidthInCoinTexture * m_CoinTextureSpriteNumber - 1, 0, m_CoinWidthInCoinTexture, m_CoinTexture.Height),
                        destinationRectangle: new Rectangle(bounds.Center.X - (int)(m_CoinWidthInCoinTexture * m_CoinTextureScale), bounds.Y - (int)(m_CoinTexture.Height / 2 * m_CoinTextureScale) + 10, (int)(m_CoinWidthInCoinTexture * m_CoinTextureScale), (int)(m_CoinTexture.Height * m_CoinTextureScale)),
                        color: Color.White);
                }
                else
                {
                    batch.Draw(
                        texture: m_CoinTexture,
                        sourceRectangle: new Rectangle(0, 0, m_CoinWidthInCoinTexture, m_CoinTexture.Height),
                        destinationRectangle: new Rectangle(bounds.Center.X - (int)(m_CoinWidthInCoinTexture * m_CoinTextureScale), bounds.Y - (int)(m_CoinTexture.Height / 2 * m_CoinTextureScale) + 10, (int)(m_CoinWidthInCoinTexture * m_CoinTextureScale), (int)(m_CoinTexture.Height * m_CoinTextureScale)),
                        color: Color.White);
                }
            }
            else
            {
                AssertManager.Get().Show("UITransformComponent in CoinCollectionComponent is null");
            }
        }
Пример #2
0
        public void Verify_New_Booking_Test()
        {
            // Create new booking
            CreatedBooking newBooking = CreateBooking();

            // Validate new booking.
            AssertManager.Execute(() => Assert.IsTrue(newBooking.bookingid > 0),
                                  string.Format("Booking Id '{0}' of the bookings should not be 0.", newBooking.bookingid));

            // Validate complete booking details.
            Booking booking = client.Get <Booking>(string.Format("booking/{0}", newBooking.bookingid));

            AssertManager.Execute(() => Assert.IsTrue(booking.firstname.Equals(newBooking.booking.firstname)),
                                  string.Format("New booking first name '{0}' should match.", booking.firstname));
            AssertManager.Execute(() => Assert.IsTrue(booking.lastname.Equals(newBooking.booking.lastname)),
                                  string.Format("New booking last name '{0}' should match.", booking.lastname));
            AssertManager.Execute(() => Assert.IsTrue(booking.totalprice == newBooking.booking.totalprice),
                                  string.Format("New booking total price '{0}' should match.", booking.totalprice));
            AssertManager.Execute(() => Assert.IsTrue(booking.depositpaid.Equals(newBooking.booking.depositpaid)),
                                  string.Format("New booking deposit paid'{0}' should match.", booking.depositpaid));
            AssertManager.Execute(() => Assert.IsTrue(booking.bookingdates.checkin.Equals(newBooking.booking.bookingdates.checkin)),
                                  string.Format("New booking check-in date '{0}' should match.", booking.bookingdates.checkin));
            AssertManager.Execute(() => Assert.IsTrue(booking.bookingdates.checkout.Equals(newBooking.booking.bookingdates.checkout)),
                                  string.Format("New booking check-out date '{0}' should match.", booking.bookingdates.checkout));

            // Validate assertions.
            AssertManager.ValidateTest();
        }
Пример #3
0
        //---------------------------------------------------------------------------

        public static T CreateUI <T>(string name, Frame frame = null) where T : class, IEntity
        {
            if (AssertManager.Get().Show(typeof(T) == typeof(UIEntity) || typeof(T).IsSubclassOf(typeof(UIEntity)), "Wrong Create<T> called for entity. Please use Create<T>."))
            {
                return(Create <T>(name));
            }
            return(CreateUI <T>(Guid.Empty, name, frame));
        }
Пример #4
0
 public static T Create <T>(string name, Vector3?location = null) where T : class, IEntity
 {
     if (AssertManager.Get().Show(!typeof(T).IsSubclassOf(typeof(UIEntity)), "Wrong Create<T> called for UI entity. Please use CreateUI<T>."))
     {
         return(CreateUI <T>(name, null));
     }
     return(Create <T>(Guid.Empty, name, location));
 }
Пример #5
0
        //---------------------------------------------------------------------------

        public static T CreateUI <T>(Guid parent, string name, Frame frame = null) where T : class, IEntity
        {
            if (AssertManager.Get().Show(typeof(T) == typeof(UIEntity) || typeof(T).IsSubclassOf(typeof(UIEntity)), "Wrong Create<T> called for entity. Please use Create<T>."))
            {
                return(Create <T>(parent, name));
            }
            T entity = (T)Activator.CreateInstance(typeof(T), name, parent, frame);

            return(entity);
        }
Пример #6
0
        //---------------------------------------------------------------------------

        private List <TextSegment> ParseToSegments()
        {
            List <TextSegment> segments = new List <TextSegment>();

            MatchCollection matches = Regex.Matches(Text, "<[A-Za-z/]+>");
            Stack <Match>   open    = new Stack <Match>();

            int index = 0;

            foreach (Match match in matches)
            {
                if (match.Value.Contains('/'))
                {
                    if (AssertManager.Get().Show(open.Count > 0 && IsClosingTag(open.Peek().Value, match.Value), "Tags in TextComponent don't match."))
                    {
                        return(new List <TextSegment>()
                        {
                            new TextSegment(Text)
                        });
                    }
                    Match tag = open.Pop();
                    if (match.Index > index)
                    {
                        segments.Add(TextSegment.Parse(Text.Substring(index, match.Index - index), tag.Value));
                    }
                    index = match.Index + match.Length;
                }
                else
                {
                    if (match.Index > index)
                    {
                        if (open.Count > 0)
                        {
                            segments.Add(TextSegment.Parse(Text.Substring(index, match.Index - index), open.Peek().Value));
                        }
                        else
                        {
                            segments.Add(new TextSegment(Text.Substring(index, match.Index - index)));
                        }
                    }
                    open.Push(match);
                    index = match.Index + match.Length;
                }
            }
            if (index < Text.Length)
            {
                segments.Add(new TextSegment(Text.Substring(index)));
            }

            return(segments);
        }
Пример #7
0
        public void Verify_GetBookings_Returns_Valid_Data_Test()
        {
            // Create new booking.
            CreatedBooking newBooking = CreateBooking();

            // Get all bookings post creation of new booking.
            List <Bookings> actBookings = client.Get <List <Bookings> >("booking");

            // Validate get all bookings
            AssertManager.Execute(() => Assert.AreEqual(actBookings.Where(b => b.Bookingid == newBooking.bookingid).Count(), 1),
                                  string.Format("Booking Id '{0}' of the bookings should exist when get all bookings fetched.", newBooking.bookingid));

            // Validate assertions.
            AssertManager.ValidateTest();
        }
Пример #8
0
        public void Verify_Delete_Booking_Test()
        {
            // Create new booking
            CreatedBooking newBooking = CreateBooking();

            // Delete the created booking.
            client.Delete(string.Format("booking/{0}", newBooking.bookingid));

            // Get all bookings post deletion of new booking.
            List <Bookings> actBookings = client.Get <List <Bookings> >("booking");

            // Validate get all bookings
            AssertManager.Execute(() => Assert.AreEqual(actBookings.Where(b => b.Bookingid == newBooking.bookingid).Count(), 0),
                                  string.Format("Get all bookings should not have deleted '{0}' booking id.", newBooking.bookingid));

            // Validate assertions.
            AssertManager.ValidateTest();
        }
Пример #9
0
        //---------------------------------------------------------------------------

        public T AddComponent <T>(bool isRequiredComponent = false) where T : IComponent
        {
            AddRequirements <T>();

            if (!HasComponent <T>())
            {
                AssertManager.Get().Show(!isRequiredComponent, string.Format("{0} is missing {1}.", Name, typeof(T).Name));
                T component = ComponentFactory.Create <T>(GUID);
                if (component != null)
                {
                    Components.Add(component.GUID, typeof(T));
                }
                return(component);
            }
            else
            {
                return(GetComponent <T>());
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            if (args != null)
            {
                foreach (string arg in args)
                {
                    switch (arg)
                    {
                    case "ShowDebugView": CollisionManager.Get().IsDebugViewActive = true; break;

                    case "HideAsserts": AssertManager.Get().HideAsserts = true; break;

                    case "ShowUIDebugView": UIManager.Get().IsUIDebugViewActive = true; break;
                    }
                }
            }

            using (var game = new Game1())
                game.Run();
        }
Пример #11
0
        //---------------------------------------------------------------------------

        public static Pickup Create(EPickups pickupType, Vector3 location, Vector3 force)
        {
            Pickup pickup = Create(pickupType.ToString(), location, force);

            IPickupComponent pickupComponent = null;

            Sprite sprite = m_Sprites[pickupType];

            pickup.AddComponent <SpriteComponent>().Init(sprite, Vector2.Zero, Vector2.One * 2);
            pickup.AddComponent <ShadowComponent>().Init(sprite, Vector2.One * 2, new Vector2(0, 3));
            pickup.AddComponent <LightingComponent>().Init(sprite, Vector2.Zero, Vector2.One * 2, Color.White, 0.5f);

            switch (pickupType)
            {
            case EPickups.Health:
                pickupComponent = pickup.AddComponent <HealthPickupComponent>();
                break;

            case EPickups.Mana:
                pickupComponent = pickup.AddComponent <ManaPickupComponent>();
                break;

            case EPickups.Coin:
                pickupComponent = pickup.AddComponent <CoinPickupComponent>();
                break;

            default:
                AssertManager.Get().Show("Value used by 'Create' does not fit range of EPickups");
                break;
            }

            if (pickupComponent != null)
            {
                pickup.GetComponent <CircleColliderComponent>().Enter += (source, target) =>
                {
                    pickupComponent.OnPickup(target);
                };
            }

            return(pickup);
        }