Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="location"></param>
        /// <param name="gridSize"></param>
        public BlockGrid(Point location, Size gridSize)
            : base()
        {
            //Mixer.SetAllChannelsVolume(50);

            int blockGridWidth  = gridSize.Width * Block.BlockWidth;
            int blockGridHeight = gridSize.Height * Block.BlockWidth;

            this.Size     = new Size(blockGridWidth, blockGridHeight);
            this.Location = location;
            sizeOfGrid    = gridSize;

            triad = new TriadGame(this);
            AddObject(triad);
            lastTriadMove      = Timer.TicksElapsed;
            lastTriadLeftRight = Timer.TicksElapsed;

            grid = new Block[gridSize.Width, gridSize.Height];


            currentState = BlockGridState.MoveTriad;

            try
            {
                loadSounds();
            }
            catch (SdlException)
            {
            }
        }
Esempio n. 2
0
        void markBlocks(TriadGame triad)
        {
            int row = triad.Y / Block.BlockWidth;
            int col = triad.X / Block.BlockWidth;

            markBlock(row, col, triad.TopBlock);
            markBlock(row + 1, col, triad.MiddleBlock);
            markBlock(row + 2, col, triad.BottomBlock);
        }
Esempio n. 3
0
        void moveTriad()
        {
            try
            {
                if (triad == null)
                {
                    return;
                }

                timeNow = Timer.TicksElapsed;
                triad.Update();

                int deltaTime          = timeNow - lastTriadMove;
                int deltaTimeLeftRight = timeNow - lastTriadLeftRight;

                if ((this.moveTriadLeft == true) && (deltaTimeLeftRight > 250))
                {
                    triad.MoveLeft();
                    this.lastTriadLeftRight = Timer.TicksElapsed;
                    moveSound.Play();
                }

                if ((this.moveTriadRight == true) && (deltaTimeLeftRight > 250))
                {
                    triad.MoveRight();
                    this.lastTriadLeftRight = Timer.TicksElapsed;
                    moveSound.Play();
                }

                if ((deltaTime > delayFactor) || ((rapidDropTriad) && (deltaTime > (delayFactor / 16))))
                {
                    if (triad.CanMoveDown())
                    {
                        triad.MoveDown();
                    }
                    else
                    {
                        this.hitBottomSound.Play();
                        markBlocks(triad);
                        RemoveObject(triad);
                        triad        = null;
                        currentState = BlockGridState.MarkBlocksToDestroy;
                    }

                    lastTriadMove = Timer.TicksElapsed;
                }
            }
            catch (SdlException)
            {
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        public override void Update()
        {
            if (gameIsPaused)
            {
                return;
            }

            try
            {
                switch (currentState)
                {
                case BlockGridState.CreateTriad:
                    triad = new TriadGame(this);
                    if (triadHitsAnyBlock())
                    {
                        gameOverSound.Play();;
                        currentState = BlockGridState.GameOver;
                    }
                    else
                    {
                        AddObject(triad);
                        currentState   = BlockGridState.MoveTriad;
                        reductionCount = 0;
                    }
                    break;

                case BlockGridState.MoveTriad:
                    moveTriad();
                    break;

                case BlockGridState.MarkBlocksToDestroy:
                    markBlocksToDestroy();
                    currentState = BlockGridState.ShowBlocksDestroyed;
                    break;

                case BlockGridState.ShowBlocksDestroyed:
                    showBlocksDestroyed();
                    currentState = BlockGridState.ReduceGrid;
                    break;

                case BlockGridState.ReduceGrid:
                    reduceGrid();
                    reductionCount++;
                    if (reductionOccured)
                    {
                        currentState = BlockGridState.MarkBlocksToDestroy;
                    }
                    else
                    {
                        currentState = BlockGridState.CreateTriad;
                    }

                    if (numberOfBlocksDestroyed > 0)
                    {
                        this.reductionSound.Play();
                        OnBlocksDestroyed(reductionCount, numberOfBlocksDestroyed);
                    }

                    break;

                case BlockGridState.GameOver:
                    break;

                default:
                    throw new SdlException(SdlDotNetExamplesBrowser.StringManager.GetString(
                                               "NotHandled", CultureInfo.CurrentUICulture) + " " + currentState);
                }
            }
            catch (SdlException)
            {
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
        public override void Update()
        {
            if (gameIsPaused) return;

            try
            {
                switch (currentState)
                {
                    case BlockGridState.CreateTriad:
                        triad = new TriadGame(this);
                        if (triadHitsAnyBlock())
                        {
                            gameOverSound.Play(); ;
                            currentState = BlockGridState.GameOver;
                        }
                        else
                        {
                            AddObject(triad);
                            currentState = BlockGridState.MoveTriad;
                            reductionCount = 0;
                        }
                        break;

                    case BlockGridState.MoveTriad:
                        moveTriad();
                        break;

                    case BlockGridState.MarkBlocksToDestroy:
                        markBlocksToDestroy();
                        currentState = BlockGridState.ShowBlocksDestroyed;
                        break;

                    case BlockGridState.ShowBlocksDestroyed:
                        showBlocksDestroyed();
                        currentState = BlockGridState.ReduceGrid;
                        break;

                    case BlockGridState.ReduceGrid:
                        reduceGrid();
                        reductionCount++;
                        if (reductionOccured)
                        {
                            currentState = BlockGridState.MarkBlocksToDestroy;
                        }
                        else
                        {
                            currentState = BlockGridState.CreateTriad;
                        }

                        if (numberOfBlocksDestroyed > 0)
                        {
                            this.reductionSound.Play();
                            OnBlocksDestroyed(reductionCount, numberOfBlocksDestroyed);
                        }

                        break;
                    case BlockGridState.GameOver:
                        break;
                    default:
                        throw new SdlException(SdlDotNetExamplesBrowser.StringManager.GetString(
                        "NotHandled", CultureInfo.CurrentUICulture) + " " + currentState);
                }
            }
            catch (SdlException)
            {
            }
        }
Esempio n. 6
0
        void moveTriad()
        {
            try
            {
                if (triad == null)
                {
                    return;
                }

                timeNow = Timer.TicksElapsed;
                triad.Update();

                int deltaTime = timeNow - lastTriadMove;
                int deltaTimeLeftRight = timeNow - lastTriadLeftRight;

                if ((this.moveTriadLeft == true) && (deltaTimeLeftRight > 250))
                {
                    triad.MoveLeft();
                    this.lastTriadLeftRight = Timer.TicksElapsed;
                    moveSound.Play();
                }

                if ((this.moveTriadRight == true) && (deltaTimeLeftRight > 250))
                {
                    triad.MoveRight();
                    this.lastTriadLeftRight = Timer.TicksElapsed;
                    moveSound.Play();
                }

                if ((deltaTime > delayFactor) || ((rapidDropTriad) && (deltaTime > (delayFactor / 16))))
                {
                    if (triad.CanMoveDown())
                    {
                        triad.MoveDown();
                    }
                    else
                    {
                        this.hitBottomSound.Play();
                        markBlocks(triad);
                        RemoveObject(triad);
                        triad = null;
                        currentState = BlockGridState.MarkBlocksToDestroy;
                    }

                    lastTriadMove = Timer.TicksElapsed;
                }
            }
            catch (SdlException)
            {
            }
        }
Esempio n. 7
0
        void markBlocks(TriadGame triad)
        {
            int row = triad.Y / Block.BlockWidth;
            int col = triad.X / Block.BlockWidth;
            markBlock(row, col, triad.TopBlock);
            markBlock(row + 1, col, triad.MiddleBlock);
            markBlock(row + 2, col, triad.BottomBlock);

        }
Esempio n. 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="location"></param>
        /// <param name="gridSize"></param>
        public BlockGrid(Point location, Size gridSize)
            : base()
        {
            //Mixer.SetAllChannelsVolume(50);

            int blockGridWidth = gridSize.Width * Block.BlockWidth;
            int blockGridHeight = gridSize.Height * Block.BlockWidth;
            this.Size = new Size(blockGridWidth, blockGridHeight);
            this.Location = location;
            sizeOfGrid = gridSize;

            triad = new TriadGame(this);
            AddObject(triad);
            lastTriadMove = Timer.TicksElapsed;
            lastTriadLeftRight = Timer.TicksElapsed;

            grid = new Block[gridSize.Width, gridSize.Height];

           
            currentState = BlockGridState.MoveTriad;

            try
            {
                loadSounds();
            }
            catch (SdlException)
            {
            }
        }