Ejemplo n.º 1
0
        public void Currency_TrySpendReturnsFalse()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            Assert.That(currency.TrySpend(1000) == false);
        }
Ejemplo n.º 2
0
 private void Update()
 {
     if (drawDebugGrid)
     {
         MUtils.DrawDebugGrid(_debugGridPosition, 1, rows, columns, Color.white);
     }
 }
Ejemplo n.º 3
0
        public void Economy_RemoveCurrencyNotExisting()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            Assert.Throws <InvalidOperationException>(() => MEconomy.Instance.RemoveCurrency(currency));
        }
Ejemplo n.º 4
0
            /*
             *         . v0
             *        / \
             * v1 /___\ v2
             *
             */
            void BlitUpperTriangle(Vector2 v0, Vector2 v1, Vector2 v2, Vector2 uv0, Vector2 uv1, Vector2 uv2, PlotDelegate plotDelegate)
            {
                if (v1.x > v2.x)
                {
                    MUtils.Swap(ref v1, ref v2);
                }

                var L1 = new RasterizedLine(v1, v0);
                var i1 = L1.CreatePixelIterator();
                int y0 = int.MinValue;
                int x0;
                int x1;

                float dx = v2.x - v0.x;
                float dy = v0.y - v2.y;

                Vector2 newUv0 = Vector2.zero;
                Vector3 newUv1 = Vector2.zero;

                if (dy != 0)
                {
                    while (NextY(i1, y0, out x0, out y0))
                    {
                        x1 = Mathf.RoundToInt(v2.x - dx * (y0 - v2.y) / dy);
                        BlitHorizontalLine(x0, x1, y0, newUv0, newUv1, plotDelegate);
                    }
                }
            }
Ejemplo n.º 5
0
        public void Currency_AddNegative()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            Assert.Throws <ArgumentException>(() => currency.Add(-1000));
            Assert.That(currency.Value == 0);
        }
Ejemplo n.º 6
0
        public void Currency_TrySpendResultsInZero()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            currency.TrySpend(1000);

            Assert.That(currency.Value == 0);
        }
Ejemplo n.º 7
0
        public void Economy_AddCurrency()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            MEconomy.Instance.AddCurrency(currency);

            Assert.That(MEconomy.Instance[name].Name.Equals(name));
        }
Ejemplo n.º 8
0
        public void Currency_AddValueCorrect()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            currency.Add(1000);

            Assert.That(currency.Value == 1000);
        }
Ejemplo n.º 9
0
        public void Activate()
        {
            gameObject.SetActive(true);
            _activeTurnLength = 0;
            var localPosition = GetMouseLocalGridPosition();

            _cellSelectorRenderer =
                MUtils.CreateSpriteObject2D(transform, localPosition, cellSelectorObject.visual, Color.white, 10);
        }
Ejemplo n.º 10
0
        public void AddingEventCategory_Multiple()
        {
            var name = MUtils.GetRandomString();

            MEvents.Instance.AddEventsCategory(name);
            MEvents.Instance.AddEventsCategory(name);

            LogAssert.Expect(LogType.Log, $"Events category [{name}] already exists!");
        }
Ejemplo n.º 11
0
        public void Economy_AddCurrencyAlreadyExistingNonIdentical()
        {
            var       name      = MUtils.GetRandomString();
            ICurrency currency  = new MCurrency(name);
            ICurrency currency2 = new MCurrency(name);

            MEconomy.Instance.AddCurrency(currency);
            Assert.Throws <InvalidOperationException>(() => MEconomy.Instance.AddCurrency(currency2));
        }
Ejemplo n.º 12
0
        public void CurrencyEvent_CurrencyAdded()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            MEvents.Add(new MEvents.EventDelegate <CurrencyAddedEvent>(e => Debug.Log(e.Currency.Name)));

            currency.Add(5);

            LogAssert.Expect(LogType.Log, name);
        }
Ejemplo n.º 13
0
        public void CurrencyEvent_UpgradableCurrencyUpgraded()
        {
            var name     = MUtils.GetRandomString();
            var capacity = new CappedCurrencyCapacity(5, 10);
            IUpgradableCurrency currency = new MCappedCurrency(name, capacity);

            MEvents.Add(new MEvents.EventDelegate <UpgradableCurrencyUpgradeSuccessEvent>((e => { Debug.Log(e.Currency.Name); })));

            currency.TryUpgradeCapacity();

            LogAssert.Expect(LogType.Log, name);
        }
Ejemplo n.º 14
0
        public void CurrencyEvent_CurrencyInsufficient()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            MEvents.Add(new MEvents.EventDelegate <CurrencyInsufficientEvent>((e => { Debug.Log(e.AmountAttempted); })));

            currency.Add(5);
            currency.TrySpend(7);

            LogAssert.Expect(LogType.Log, "7");
        }
Ejemplo n.º 15
0
        public void AddingEventListener()
        {
            var category = MUtils.GetRandomString();

            MEvents.Instance.AddEventsCategory(category);

            MEvents.Instance[category].Raise(new TestEvent(0));
            LogAssert.NoUnexpectedReceived();
            MEvents.Instance[category].Add <TestEvent>(TestEventListener);
            MEvents.Instance[category].Raise(new TestEvent(0));

            LogAssert.Expect(LogType.Log, "TestEvent0");
            LogAssert.NoUnexpectedReceived();
        }
Ejemplo n.º 16
0
        public void Economy_RemoveCurrency()
        {
            var       name     = MUtils.GetRandomString();
            ICurrency currency = new MCurrency(name);

            MEconomy.Instance.AddCurrency(currency);

            MEconomy.Instance.RemoveCurrency(currency);

            Assert.Throws <KeyNotFoundException>(() =>
            {
                var curr = MEconomy.Instance[name];
            });
        }
Ejemplo n.º 17
0
            void BlitHorizontalLine(int x0, int x1, int y, Vector2 uv0, Vector2 uv1, PlotDelegate plotDelegate)
            {
                if (x0 > x1)
                {
                    MUtils.Swap(ref x0, ref x1);
                }
                float   xx0, yy0;
                Vector2 newUv = Vector2.zero;

                for (int x = x0; x <= x1; ++x)
                {
                    ToWorldSpace(x, y, out xx0, out yy0);
                    plotDelegate(new Vector2(xx0, yy0), newUv);
                }
            }
        private void ToggleSelectedGridObject()
        {
            _selectedObjectIndex = (_selectedObjectIndex + 1) % prepareForBattleObjects.Count;

            while (prepareForBattleObjects[_selectedObjectIndex].empty)
            {
                _selectedObjectIndex = (_selectedObjectIndex + 1) % prepareForBattleObjects.Count;
            }

            if (_selectedObjectRenderer != null)
            {
                Destroy(_selectedObjectRenderer.gameObject);
            }

            _selectedObjectRenderer = MUtils.CreateSpriteObject2D(transform, Vector2.zero,
                                                                  gridObjectData.visual, Color.white, 3);
        }
Ejemplo n.º 19
0
            /*
             *      v0  ----  v1
             \  /
             \/
             \               v2
             */
            void BlitTriangle(Vector2 v0, Vector2 v1, Vector2 v2, Vector2 uv0, Vector2 uv1, Vector2 uv2, PlotDelegate plotDelegate)
            {
                if (v0.x > v1.x)
                {
                    MUtils.Swap(ref v0, ref v1);
                }

                var L1 = new RasterizedLine(v0, v2);
                var L2 = new RasterizedLine(v1, v2);
                var i1 = L1.CreatePixelIterator();
                var i2 = L2.CreatePixelIterator();

                Vector2 newUv0 = Vector2.zero;
                Vector3 newUv1 = Vector2.zero;

                var pList1 = ArrayPool <RasterizedLine.Pixel> .Get();

                var pList2 = ArrayPool <RasterizedLine.Pixel> .Get();

                CacheYOnChanged(i1, pList1);
                CacheYOnChanged(i2, pList2);

                if (CheckSequence(pList1, pList2))
                {
                    for (int i = 0; i < pList1.length; ++i)
                    {
                        var a = pList1[i];
                        var b = pList2[i];
                        BlitHorizontalLine(a.x, b.x, a.y, newUv0, newUv1, plotDelegate);
                    }
                }
                else
                {
                    for (int i = 0; i < pList1.length; ++i)
                    {
                        var a = pList1[i];
                        var b = pList2[-i - 1];
                        BlitHorizontalLine(a.x, b.x, a.y, newUv0, newUv1, plotDelegate);
                    }
                }
                ArrayPool <RasterizedLine.Pixel> .Release(pList1);

                ArrayPool <RasterizedLine.Pixel> .Release(pList2);
            }
Ejemplo n.º 20
0
        // Bresenham's line algorithm
        IEnumerator <Pixel> Rasterize()
        {
            int x0 = Mathf.RoundToInt(start.x);
            int y0 = Mathf.RoundToInt(start.y);
            int x1 = Mathf.RoundToInt(end.x);
            int y1 = Mathf.RoundToInt(end.y);

            bool steep = Mathf.Abs(y1 - y0) > Mathf.Abs(x1 - x0);

            if (steep)
            {
                MUtils.Swap(ref x0, ref y0);
                MUtils.Swap(ref x1, ref y1);
            }
            if (x1 < x0)
            {
                MUtils.Swap(ref x0, ref x1);
                MUtils.Swap(ref y0, ref y1);
            }

            int dy = y1 - y0;
            int dx = x1 - x0;
            int yi = 1;

            if (dy < 0)
            {
                yi = -1;
                dy = -dy;
            }
            int D = 2 * dy - dx;
            int y = y0;

            if (steep)
            {
                for (int x = x0; x <= x1; ++x)
                {
                    yield return(new Pixel()
                    {
                        x = y, y = x, c = 1f,
                    });

                    if (D > 0)
                    {
                        y = y + yi;
                        D = D - 2 * dx;
                    }
                    D = D + 2 * dy;
                }
            }
            else
            {
                for (int x = x0; x <= x1; ++x)
                {
                    yield return(new Pixel()
                    {
                        x = x, y = y, c = 1f,
                    });

                    if (D > 0)
                    {
                        y = y + yi;
                        D = D - 2 * dx;
                    }
                    D = D + 2 * dy;
                }
            }
        }