Esempio n. 1
0
        private void pushBlocks()
        {
            int rows = 1;

            //if there's anything in the top row, game over
            if (tiles[1].Exists(x => (x != null)))
            {
                GameOver();
            }

            foreach (List<Block> l in tiles)
            {
                foreach (Block b in l)
                {
                    if (b != null)
                        b.Row = b.Row - rows; //move all blocks up by the number of rows to push
                }
            }

            //make room at the top
            for (int i = 0; i < rows; ++i)
            {
                tiles.RemoveAt(0);
            }

            //push blocks onto the bottom
            for (int i = 0; i < rows; ++i)
            {
                List<Block> nrow = new List<Block>(NUM_COLUMNS);
                for (int j = 0; j < NUM_COLUMNS; ++j)
                {
                    //create a new block at column j and row i (from the bottom), numbered 1-9
                    Block nblock = new Block(this, j, NUM_ROWS - 1 - i, 0);
                    nrow.Add(nblock);
                }
                tiles.Add(nrow);

                //add new randomized blocks, making sure they don't immediately create any groups
                for (int j = 0; j < NUM_COLUMNS; ++j)
                {
                    do
                    {
                        tiles[tiles.Count - 1][j].Number = rand.Next(1, Block.NUM_BLOCK_TYPES);
                    } while (new Group(this, tiles.Count - 1, j).Size >= Facet.GroupSize);
                }

            }

            foreach (Block b in fallingblocks)
            {
                //b.Row -= rows;
                b.FallingDestination -= rows;
            }

            //sadly, these aren't linked lists, so have to manually order them (ouch)
            tiles.Sort((row1, row2) => {
                int r1 = 0, r2 = 0;
                foreach (Block b in row1)
                {
                    if (b != null)
                    {
                        r1 = b.Row;
                        break;
                    }
                }
                foreach (Block b in row2)
                {
                    if (b != null)
                    {
                        r2 = b.Row;
                        break;
                    }
                }
                return r1 - r2;
            });
            cursor.Y -= 1;
        }
Esempio n. 2
0
        public void HeyIGotSelected(Block block)
        {
            if (selected.Count < SelectLimit && block.Number != 0)
            {
                selected.Add(block);
                block.Selected = true;

                if (selected.Count == SelectLimit && GetTotal() != Target)
                    Facet.CueTutorialMessage(GameplayFacet.TutorialManager.TutorialEvent.SelectLimitReached);
            }
            else
            {
                SoundManager.PlaySound(SFX.CannotSelect, true);
            }
        }
Esempio n. 3
0
        public void DropCrap(int numberOfBlocks, int[] columns)
        {
            int[] stack = new int[NUM_COLUMNS];
            int count = columns.Length;

            for (int i = 0; i < stack.Length; ++i)
                stack[i] = 0;

            if (count <= 0) return;

            for (int i = 0; i < numberOfBlocks; ++i)
            {
                int column = columns[i % count];
                Debug.Assert(column >= 0 && column < NUM_COLUMNS);

                Block block = new Block(this, column, 0, 0);

                int row;
                for (row = tiles.Count - 1; tiles[row][column] != null; --row)
                {
                    if (row <= 0) return;
                }

                block.FallingDestination = row - stack[column];
                ++stack[column];

                if (block.FallingDestination == block.Row)
                    tiles[0][column] = block;
                else
                    fallingblocks.Add(block);
            }
        }
Esempio n. 4
0
 public void HeyIGotDeselected(Block block)
 {
     if (selected.Remove(block))
         block.Selected = false;
     if (block.Dead)
     {
         dead.Add(block);
         Facet.CueTutorialMessage(GameplayFacet.TutorialManager.TutorialEvent.DeadBlockCreated);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Is this block adjacent to (share a side with) another?
 /// </summary>
 /// <param name="b">The other block</param>
 /// <returns></returns>
 public bool AdjacentTo(Block b)
 {
     return (Math.Abs(b.row - row) == 1 && b.column == column) ||
         (Math.Abs(b.column - column) == 1 && b.row == row);
 }