コード例 #1
0
ファイル: TetrisForm.cs プロジェクト: janilakhan/GameSuite
        /// <summary>

        /*
         * TetrisForm::TetrisForm()
         *
         * NAME
         *
         *      TetrisForm::TetrisForm - intializes the form and its
         *                                 components
         *
         * SYNOPSIS
         *
         *      void TetrisForm::TetrisForm();
         *
         *
         * DESCRIPTION
         *
         *      This function create the tetris form and the elements
         *      within the form. This function also starts the timer.
         *
         * AUTHOR
         *
         *      Janila Khan
         *
         * DATE
         *
         *      12:00pm 3/23/2018
         *
         */
        /// </summary>
        public TetrisForm()
        {
            InitializeComponent();

            // Intialize the board
            t_board = new TetrisBoard();

            // Background music
            try
            {
                player = new SoundPlayer(GameConsole.Properties.Resources.tetrisTheme);
                player.PlayLooping();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            // Set the score, rows to zero
            t_playerScoreLabel.Text = t_board.m_score.ToString();
            t_playerRowsLabel.Text  = t_board.m_rowsCleared.ToString();

            // Set the level to one
            t_playerLevelLabel.Text = t_board.m_level.ToString();

            // Create a timer and set a interval.
            m_time          = new System.Timers.Timer();
            m_time.Interval = 400;

            // Hook up the Elapsed event for the timer.
            m_time.Elapsed += OnTimedEvent;

            // Have the timer fire repeated events (true is the default)
            m_time.AutoReset = true;

            // Start the timer
            m_time.Enabled = true;

            // Paint lines for the bucket
            tetrisBoard.Paint += new PaintEventHandler(tetrisBoard_Bucket);

            // The controls for the board and the game
            buttonsTextBox.Text += "\r\n";
            buttonsTextBox.Text += "<Down>: Move Block Striaght Down \r\n";
            buttonsTextBox.Text += "<Left>: Move Block To The Left \r\n";
            buttonsTextBox.Text += "<Right>: Move Block To The Right \r\n";
            buttonsTextBox.Text += "<A>: Rotate To the Left \r\n";
            buttonsTextBox.Text += "<D>: Rotate to the Right \r\n";
            buttonsTextBox.Text += "\r\n";
        }
コード例 #2
0
        /// <summary>

        /*
         * TetrisBlocks::TetrisBlocks()
         *
         * NAME
         *
         *      TetrisBlocks::TetrisBlocks- constructor
         *
         * SYNOPSIS
         *
         *      TetrisBlocks::TetrisBlocks(TetrisBoard t_board);
         *
         * DESCRIPTION
         *
         *      Constructor
         *
         * AUTHOR
         *
         *      Janila Khan
         *
         * DATE
         *
         *      5:50pm 3/10/2018
         *
         */
        /// </summary>
        /// <param name="t_board">A TetrisBoard object</param>
        public TetrisBlocks(TetrisBoard t_board)
        {
            //Intialize the board
            m_board = t_board;

            blockRow    = 0;
            blockColumn = 0;

            // Get a random number
            Random rand = new Random();

            num = rand.Next(0, 7);

            // Use the random to chose a block and the color that
            // corresponds with it
            block        = m_pieces[num];
            m_blockColor = m_piecesColor[num];

            // Create the block piece
            m_blockShape = new Rectangle[4];
            m_blockShape = createBlocks(block);
        }