Exemplo n.º 1
0
        static bool GenRainbow(MapGenArgs args)
        {
            int       maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            Random    rand      = args.UseSeed ? new Random(args.Seed) : new Random();
            NextBlock nextBlock = () => (byte)rand.Next(Block.Red, Block.White);

            // Cuboid the four walls
            Cuboid(args, 0, 1, 0, maxX, maxY, 0, nextBlock);
            Cuboid(args, 0, 1, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(args, 0, 1, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(args, maxX, 1, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base and top
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, nextBlock);
            Cuboid(args, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemplo n.º 2
0
        static bool GenRainbow(Player p, Level lvl, string seed)
        {
            int       maxX = lvl.Width - 1, maxY = lvl.Height - 1, maxZ = lvl.Length - 1;
            Random    rng       = MapGen.MakeRng(seed);
            NextBlock nextBlock = () => (byte)rng.Next(Block.Red, Block.White);

            // Cuboid the four walls
            Cuboid(lvl, 0, 1, 0, maxX, maxY, 0, nextBlock);
            Cuboid(lvl, 0, 1, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(lvl, 0, 1, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(lvl, maxX, 1, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base and top
            Cuboid(lvl, 0, 0, 0, maxX, 0, maxZ, nextBlock);
            Cuboid(lvl, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemplo n.º 3
0
        static bool GenSpace(Player p, Level lvl, string seed)
        {
            int       maxX = lvl.Width - 1, maxY = lvl.Height - 1, maxZ = lvl.Length - 1;
            Random    rng       = MapGen.MakeRng(seed);
            NextBlock nextBlock = () => rng.Next(100) == 0 ? Block.Iron : Block.Obsidian;

            // Cuboid the four walls
            Cuboid(lvl, 0, 2, 0, maxX, maxY, 0, nextBlock);
            Cuboid(lvl, 0, 2, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(lvl, 0, 2, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(lvl, maxX, 2, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base and top
            Cuboid(lvl, 0, 0, 0, maxX, 0, maxZ, () => Block.Bedrock);
            Cuboid(lvl, 0, 1, 0, maxX, 1, maxZ, nextBlock);
            Cuboid(lvl, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemplo n.º 4
0
        static bool GenSpace(MapGenArgs args)
        {
            int       maxX = args.Level.Width - 1, maxY = args.Level.Height - 1, maxZ = args.Level.Length - 1;
            Random    rand      = args.UseSeed ? new Random(args.Seed) : new Random();
            NextBlock nextBlock = () => rand.Next(100) == 0 ? Block.Iron : Block.Obsidian;

            // Cuboid the four walls
            Cuboid(args, 0, 2, 0, maxX, maxY, 0, nextBlock);
            Cuboid(args, 0, 2, maxZ, maxX, maxY, maxZ, nextBlock);
            Cuboid(args, 0, 2, 0, 0, maxY, maxZ, nextBlock);
            Cuboid(args, maxX, 2, 0, maxX, maxY, maxZ, nextBlock);

            // Cuboid base and top
            Cuboid(args, 0, 0, 0, maxX, 0, maxZ, () => Block.Bedrock);
            Cuboid(args, 0, 1, 0, maxX, 1, maxZ, nextBlock);
            Cuboid(args, 0, maxY, 0, maxX, maxY, maxZ, nextBlock);
            return(true);
        }
Exemplo n.º 5
0
        static void Cuboid(Level lvl, int minX, int minY, int minZ,
                           int maxX, int maxY, int maxZ, NextBlock nextBlock)
        {
            int width = lvl.Width, length = lvl.Length;

            byte[] blocks = lvl.blocks;

            for (int y = minY; y <= maxY; y++)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    for (int x = minX; x <= maxX; x++)
                    {
                        blocks[x + width * (z + y * length)] = nextBlock();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public bool IsValidChain(string prevBlockHash, bool verbose)
        {
            bool isValid        = true;
            bool validSignature = false;

            BuildMerkleTree();

            if (KeyStore != null)
            {
                validSignature = KeyStore.Verify(BlockHash, BlockSignature);
            }


            // Is this a valid block and transaction
            //string newBlockHash = CalculateBlockHash(prevBlockHash);
            string newBlockHash = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + CalculateBlockHash(prevBlockHash))));

            if (KeyStore != null)
            {
                validSignature = KeyStore.Verify(newBlockHash, BlockSignature);
            }

            if (newBlockHash != BlockHash)
            {
                isValid = false;
            }
            else
            {
                // Does the previous block hash match the latest previous block hash
                isValid |= PreviousBlockHash == prevBlockHash;
            }

            PrintVerificationMessage(verbose, isValid, validSignature, KeyStore != null);

            // Check the next block by passing in our newly calculated blockhash. This will be compared to the previous
            // hash in the next block. They should match for the chain to be valid.
            if (NextBlock != null)
            {
                return(NextBlock.IsValidChain(newBlockHash, verbose));
            }

            return(isValid);
        }
Exemplo n.º 7
0
    /// <summary>
    /// once a game has reached gameover the reset get's called to clear everything
    /// </summary>
    public void Reset()
    {
        nextBlock = new NextBlock();
        grid      = new TetrisGrid();
        block     = new Block();
        score     = new Score();
        hold      = new Hold();

        over.grid     = grid;
        over.score    = score;
        block.Grid    = grid;
        grid.Gblock   = block;
        score.grid    = grid;
        score.font    = font;
        hold.font     = font;
        title.fontBig = fontBig;
        over.fontBig  = fontBig;
        help.fontBig  = fontBig;
    }
        internal override void Pump()
        {
            base.Pump();

            using (fileStream = File.OpenRead())
            {
                byte[] b          = new byte[4096];
                int    dataReaded = 0;
                while ((dataReaded = fileStream.Read(b, 0, b.Length)) > 0)
                {
                    NextBlock.Collect(b, dataReaded);
                }
            }

            if (TransferCommand == TransferCommand.MOVE)
            {
                Destroy();
            }
        }
Exemplo n.º 9
0
        public void Loop(Frame frame)
        {
            FrameCount++;

            RemoveFirstCompleteRow();

            for (var y = 0; y < ColorGrid.Length; y++)
            {
                for (var x = 0; x < ColorGrid[y].Length; x++)
                {
                    frame.SetPixel(x, y, ColorGrid[y][x]);
                }
            }

            ActiveBlock.Draw(frame.Graphics);
            NextBlock.Draw(frame.Graphics);

            DrawBorders(frame.Graphics);

            HandleInput();

            if (FrameCount % 8 == 0)
            {
                MoveActiveBlock();
            }

            if (IsActiveBlockColliding())
            {
                SolidifyActiveBlock();
                AssignNextActiveBlock();
            }

            // Game over
            if (!CheckOverflow())
            {
                return;
            }

            GameOver = true;
            frame.Graphics.FillRectangle(Brushes.Red, 11, 10, 4, 5);
        }
Exemplo n.º 10
0
        static void Cuboid(Level lvl, int minX, int minY, int minZ,
                           int maxX, int maxY, int maxZ, NextBlock nextBlock)
        {
            int width = lvl.Width, length = lvl.Length;

            byte[] blocks = lvl.blocks;

            // space theme uses maxY = 2, but map might only be 1 block high
            maxY = Math.Min(maxY, lvl.MaxY);

            for (int y = minY; y <= maxY; y++)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    for (int x = minX; x <= maxX; x++)
                    {
                        blocks[x + width * (z + y * length)] = nextBlock();
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Method <c>HoldBlock()</c>
        /// sets the heldBlock to the current block, and then sets the current block to
        /// the next block.
        /// </summary>
        public void HoldBlock()
        {
            if (HeldBlock.Count == 0)
            {
                _heldShape = _shapeFactory.BuildShape(_shape);

                for (int i = 0; i < 4; i++)
                {
                    Blocks.Remove(x => x.GridX == _shape.ShapeBlocks[i].GridX &&
                                  x.GridY == _shape.ShapeBlocks[i].GridY);
                }

                _shape = _nextShape;
                _shape.CenterShape();

                Blocks.AddRange(_shape.ShapeBlocks);
                _nextShape = _shapeFactory.BuildRandomShape();
                NextBlock.Clear();
                NextBlock.AddRange(_nextShape.ShapeBlocks);
                HeldBlock.AddRange(_heldShape.ShapeBlocks);
            }
            else
            {
                HeldBlock.Clear();
                var tempShape = _heldShape;
                _heldShape = _shapeFactory.BuildShape(_shape);

                for (int i = 0; i < 4; i++)
                {
                    Blocks.Remove(x => x.GridX == _shape.ShapeBlocks[i].GridX &&
                                  x.GridY == _shape.ShapeBlocks[i].GridY);
                }

                _shape = tempShape;
                _shape.CenterShape();
                Blocks.AddRange(_shape.ShapeBlocks);
                HeldBlock.AddRange(_heldShape.ShapeBlocks);
            }
        }
Exemplo n.º 12
0
        public void Execute()
        {
            var condition = (bool)Condition.Value;

            if (condition)
            {
                InnerBlock?.Execute();

                var next = NextBlock ?? null;

                while (next is ElseBlock || next is ElseIfBlock)
                {
                    next = next?.NextBlock;
                }

                next?.Execute();
            }
            else
            {
                NextBlock?.Execute();
            }
        }
Exemplo n.º 13
0
        } // Funkcja sprawdzajaca kolizje

        private void Initializer()
        {
            timer1.Start();

            gameover            = false;
            Display.Width       = SBW * BW;
            Display.Height      = SBW * (BH - 1);
            Display.BackColor   = Color.Black;
            NextBlock.Width     = SBW * 3;
            NextBlock.Height    = SBW * 3;
            NextBlock.BackColor = Color.Black;
            Board = new short[BW, BH];
            for (int i = 0; i < BW; ++i)
            {
                for (int j = 0; j < BH; ++j)
                {
                    Board[i, j] = 0;
                }
            }
            Generate();
            GenerateNext();
            NextBlock.Refresh();
        }
Exemplo n.º 14
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (CollisionCheck(QoB.First(), 'N') == false)
     {
         YL++;
     }
     else
     {
         for (int i = 0; i < 3; ++i)
         {
             for (int j = 0; j < 3; ++j)
             {
                 if (QoB.First().Arr[i, j] == true)
                 {
                     Board[XL + i, YL + j] = ColorId;
                 }
             }
         }
         if (YL + 3 == 3)
         {
             gameover = true;
         }
         XL = BW / 2 - 1;
         YL = 0;
         StateChech();
         QoB.Dequeue();
         ColorId = ColorTemp;
         GenerateNext();
         NextBlock.Refresh();
         if (gameover)
         {
             label1.Text = "GameOver";
             timer1.Stop();
         }
     }
     Display.Refresh();
 }
Exemplo n.º 15
0
        public bool IsValidChain(string prevBlockHash, bool verbose)
        {
            bool isValid = true;

            BuildMerkleTree();
            //is this a valid block and transaction
            string newBlockHash = CalculateBlockHash(prevBlockHash);

            if (newBlockHash != BlockHash)
            {
                isValid = false;
            }
            else
            {
                isValid |= PreviousBlockHash == prevBlockHash;
            }

            if (NextBlock != null)
            {
                return(NextBlock.IsValidChain(newBlockHash, verbose));
            }

            return(isValid);
        }
Exemplo n.º 16
0
 private void AddToString(StringBuilder sb, Side side)
 {
     sb.Append(this[side]);
     NextBlock?.AddToString(sb, side);
 }
Exemplo n.º 17
0
 public static void OnNextBlock(ITZXBlock block, int blockIndex)
 {
     NextBlock?.Invoke(block, blockIndex);
 }
Exemplo n.º 18
0
 void Start()
 {
     Next = NextBlock?.GetComponent <IBlock>();
 }
Exemplo n.º 19
0
 /// <summary>
 /// Remove the back block (or this block if the list contains only one element)
 /// </summary>
 /// <returns>Removed block</returns>
 public Block RemoveBack(bool fullIsolation = false) => NextBlock.Isolate(fullIsolation);
Exemplo n.º 20
0
 void Awake()
 {
     gameController = GameObject.Find("GameController").GetComponent <GameController>();
     stopBlock      = GameObject.Find("StopBrock");
     nextBlock      = GameObject.Find("NextBlock").GetComponent <NextBlock>();
 }
Exemplo n.º 21
0
        // Различные режимы игрового такта

        /// <summary>
        /// Добавление нового игрового блока на сетку
        /// </summary>
        private void AddNextBlockToGrid()
        {
            FallingBlock = new GameBlock(NextBlock);
            NextBlock.SetRandomColor();
        }
Exemplo n.º 22
0
 public void Execute()
 {
     InnerBlock?.Execute();
     NextBlock?.Execute();
 }