示例#1
0
    protected virtual void TakeBlocks(int nLetters, char[] letters, Thaum.Type[] types)
    {
        if (letters.Length < nLetters)
        {
            Debug.LogError("Not enough letters!");
        }

        if (types.Length < nLetters)
        {
            Debug.LogError("Not enough thaums!!");
        }

        _blockPool = FindObjectOfType <BlockPool>();
        if (_blockPool == null)
        {
            Debug.LogError("Scene didn't have a BlockPool object.");
        }

        _blocks = new LetterBlock[nLetters];

        for (int i = 0; i < nLetters; i++)
        {
            _blocks[i] = _blockPool.Get();
            _blocks[i].transform.SetParent(_transform);
            _blocks[i].Construct(letters[i], types[i]);
        }
    }
示例#2
0
        public void ProcessNewBlock()
        {
            var TxsSize = 0;
            var block   = new Block();

            block.Index = BlockPool.Get().GetBlocks().Keys.Max() + 1;

            while (pool.Count > 0 && TxsSize < BlockTxLimit)
            {
                var next = GetNext();
                block.AddTx(next);
            }

            if (!BlockValidator.IsValid(block))
            {
                Console.WriteLine("Block is not valid");
                return;
            }

            BlockPool.Get().AddBlock(block);
        }
示例#3
0
    public void Construct(int nLetters, bool[][] blueprint, float size, char[] letters, Thaum.Type[] types)
    {
        int n = blueprint.Length;       float revN = 1 / (float)n;
        int m = blueprint[0].Length;    float revM = 1 / (float)m;

        RectTransform rect = GetComponent <RectTransform>();

        float cellSz       = _table.GetCellSize();

        Debug.Log("Table cell size: " + cellSz + "x" + cellSz);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (m) * cellSz);
        rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (n) * cellSz);

        Debug.Log("Tetrino created: table " + m + "x" + n + ", size: " + rect.rect.size.x + "x" + rect.rect.size.y);

        _blocks = new LetterBlock[nLetters];

        int k = 0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (blueprint[i][j])
                {
                    _blocks[k] = _blockPool.Get();
                    _blocks[k].Construct(letters[k], types[k]);

                    _blocks[k].transform.SetParent(transform);
                    rect           = _blocks[k].GetComponent <RectTransform>();
                    rect.anchorMin = new Vector2(revM * j, 1 - revN * (i + 1));
                    rect.anchorMax = new Vector2(revM * (j + 1), 1 - revN * i);

                    rect.offsetMax = Vector2.zero;
                    rect.offsetMin = Vector2.zero;
                    k++;
                }
            }
        }
    }
示例#4
0
        public static double GetBalance(string wallet)
        {
            var    pool          = BlockPool.Get();
            double senderBalance = 0;

            foreach (var block in pool.GetBlocks())
            {
                foreach (var curTx in block.Value.Txs)
                {
                    if (curTx.To == wallet)
                    {
                        senderBalance += curTx.Amount;
                    }

                    if (curTx.From == wallet)
                    {
                        senderBalance -= curTx.Amount;
                    }
                }
            }

            return(senderBalance);
        }