コード例 #1
0
        /********************************************************************************************
         * 機能
         * 乱数で7種類のテトリスミノのうち何を発生させるか決めて、タイマが発生するたびに
         * ミノを一つ下げる
         *******************************************************************************************/
        public void MyClock(object sender, EventArgs e)
        {
            CchangeScreen screen = new CchangeScreen();
            CDrawFigure   figure = new CDrawFigure();
            CdeleteBlock  delete = new CdeleteBlock();

            /*if (MinoPos == 0 && flag ==false)
             * {
             *  screen.setScreen(CONST.START_MINO_POS, tempMinoPos, var_sell_status, temp_mino, temp_minoNumber);
             *  return;
             * }*/
            if (MinoPos_y != 0)
            {
                screen.deleteScreen(MinoPos_x, MinoPos_y - 1, var_sell_status, temp_mino, direction);
            }
            //1~7の乱数発生
            Random random = new System.Random();

            if (MinoPos_y == 0)
            {
                MinoPos_x = CONST.START_MINO_POS;
                minoNo    = random.Next(1, 8); //1から7の乱数を発生して、表示させるミノを決める
                //temp_minoNumber = minoNo;
                CLoad_block block = new CLoad_block();
                if (minoNo == 1)
                {
                    tetoris_mino = block.getTetorisMino1();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 2)
                {
                    tetoris_mino = block.getTetorisMino2();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 3)
                {
                    tetoris_mino = block.getTetorisMino3();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 4)
                {
                    tetoris_mino = block.getTetorisMino4();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 5)
                {
                    tetoris_mino = block.getTetorisMino5();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 6)
                {
                    tetoris_mino = block.getTetorisMino6();
                    temp_mino    = new int[4, 4, 4];
                }
                else if (minoNo == 7)
                {
                    tetoris_mino = block.getTetorisMino7();
                    temp_mino    = new int[4, 4, 4];
                }
                else
                {
                    MessageBox.Show("何か想定外の数値が入力されました MyClock");
                    return;
                }
            }
            //MessageBox.Show(minoNo.ToString());

            //ミノが動けるとき画面を表示
            if (screen.checkBlockIsMove(MinoPos_x, MinoPos_y, var_sell_status, tetoris_mino, direction))
            {
                //ミノの画面への状態をセット
                screen.setScreen(MinoPos_x, MinoPos_y, var_sell_status, tetoris_mino, direction);

                //ミノが移動できるのでミノを描写する
                figure.DrawBlock(timer_graphics, var_sell_status);
                //前の画面の状態を保持
                this.setPreviousScreen(tetoris_mino, temp_mino, direction);
                tempMinoPos = MinoPos_y;
                MinoPos_y++;
            }
            else
            {
                //ミノが動けない、以前のミノを表示する
                screen.setScreen(MinoPos_x, MinoPos_y - 1, var_sell_status, tetoris_mino, direction);
                figure.DrawBlock(timer_graphics, var_sell_status);
                //ここに一行そろっていたら消す処理を入れる
                delete.deleteBlock(timer_graphics, var_sell_status);
                MinoPos_y = 0;
            }
        }
コード例 #2
0
        /******************************************************************************************
         * 機能
         * キーが押された時の処理、ミノを回転させる処理と、ミノを移動させる処理
         * ***************************************************************************************/
        private void TetorisForm_KeyDown(object sender, KeyEventArgs e)
        {
            //現在のミノの位置を取得
            int pos_x     = Maintimer.getMinoPos_x();
            int pos_y     = Maintimer.getMinoPos_y();
            int minoNo    = Maintimer.getMinoNo();
            int direction = Maintimer.getDirection();

            int[,,] minoblock    = Maintimer.getTetorisMino();
            int[,] screen_status = Maintimer.getScreenStatus();
            CdeleteBlock delete = new CdeleteBlock();


            CchangeScreen screen = new CchangeScreen();
            CDrawFigure   figure = new CDrawFigure();

            //右ノーが押されたとき
            if (e.KeyCode == Keys.Right)
            {
                //前の状態を消去
                screen.deleteScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                Maintimer.setScreenStatus(screen_status);
                //ミノを右に移動させる
                pos_x++;
                if (screen.checkBlockIsMove(pos_x, pos_y - 1, screen_status, minoblock, direction))
                {
                    //ミノが動かせるときにミノを移動させる
                    //新しい状態のミノを表示
                    screen.setScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                    //物理的に描く
                    figure.DrawBlock(this.CreateGraphics(), screen_status);
                    Maintimer.setMinoPos_x(pos_x);
                    Maintimer.setMinoPos_y(pos_y);
                    Maintimer.setScreenStatus(screen_status);
                }
                else
                {
                    //行がそろっていたら消す
                    //delete.deleteBlock(this.CreateGraphics(), screen_status);
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                //ミノを下に移動させる
                //前の状態を消去
                screen.deleteScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                Maintimer.setScreenStatus(screen_status);
                //ミノを右に移動させる
                pos_y++;
                if (screen.checkBlockIsMove(pos_x, pos_y - 1, screen_status, minoblock, direction))
                {
                    //ミノが動かせるときにミノを移動させる
                    //新しい状態のミノを表示
                    screen.setScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                    //物理的に描く
                    figure.DrawBlock(this.CreateGraphics(), screen_status);
                    Maintimer.setMinoPos_x(pos_x);
                    Maintimer.setMinoPos_y(pos_y);
                    Maintimer.setScreenStatus(screen_status);
                }
                else
                {
                    //行がそろっていたら消す
                    //delete.deleteBlock(this.CreateGraphics(), screen_status);
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                //ミノを左に移動させる
                //前の状態を消去
                screen.deleteScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                Maintimer.setScreenStatus(screen_status);
                //ミノを右に移動させる
                pos_x--;
                if (screen.checkBlockIsMove(pos_x, pos_y - 1, screen_status, minoblock, direction))
                {
                    //ミノが動かせるときにミノを移動させる
                    //新しい状態のミノを表示
                    screen.setScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                    //物理的に描く
                    figure.DrawBlock(this.CreateGraphics(), screen_status);
                    Maintimer.setMinoPos_x(pos_x);
                    Maintimer.setMinoPos_y(pos_y);
                    Maintimer.setScreenStatus(screen_status);
                }
                else
                {
                    //行がそろっていたら消す
                    //delete.deleteBlock(this.CreateGraphics(), screen_status);
                }
            }
            if (e.KeyCode == Keys.L)
            {
                //前のミノの上位を消去
                screen.deleteScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                Maintimer.setScreenStatus(screen_status);
                //ミノを右回転させる
                direction++;
                if (direction == 4)
                {
                    direction = 0;
                }
                if (screen.checkBlockIsMove(pos_x, pos_y, screen_status, minoblock, direction))
                {
                    //ミノが動かせるときにミノを移動させる
                    //新しい状態のミノを表示
                    screen.setScreen(pos_x, pos_y, screen_status, minoblock, direction);
                    //物理的に描く
                    figure.DrawBlock(this.CreateGraphics(), screen_status);
                    Maintimer.setDirection(direction);
                    Maintimer.setTempMino(minoblock);
                    Maintimer.setMinoPos_y(pos_y + 1);
                    Maintimer.setScreenStatus(screen_status);
                }
            }
            if (e.KeyCode == Keys.J)
            {
                //ミノを左回転させる
                //前のミノの上位を消去
                screen.deleteScreen(pos_x, pos_y - 1, screen_status, minoblock, direction);
                Maintimer.setScreenStatus(screen_status);
                //ミノを右回転させる
                direction--;
                if (direction == -1)
                {
                    direction = 3;
                }
                direction = direction % 4;
                if (screen.checkBlockIsMove(pos_x, pos_y, screen_status, minoblock, direction))
                {
                    //ミノが動かせるときにミノを移動させる
                    //新しい状態のミノを表示
                    screen.setScreen(pos_x, pos_y, screen_status, minoblock, direction);
                    //物理的に描く
                    figure.DrawBlock(this.CreateGraphics(), screen_status);
                    Maintimer.setDirection(direction);
                    Maintimer.setTempMino(minoblock);
                    Maintimer.setMinoPos_y(pos_y + 1);
                    Maintimer.setScreenStatus(screen_status);
                }
            }
        }