Пример #1
0
        public MainForm()
        {
            Game       = new TetrisGame();
            Game.Score = 0; Game.GameOver = true;

            Saver.Load();

            GF = new GameField(18, 12);

            Preview             = new TetrisField(4, 4);
            Preview.BorderColor = Preview.BackColor;

            Random rnd = new Random();

            // Типа сплэш
            for (int row = 0; row < GF.TilesHeight; row++)
            {
                for (int col = 0; col < GF.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF.SetCell(row, col, t);
                }
            }

            Game.StateChanged += new EventHandler(Game_StateChanged);

            InitializeComponent();
        }
Пример #2
0
 public MovingObject(TetrisField _tField, TetrisObject _tObject, TetrisObject _nextObject, GameScore _game)
 {
     tField       = _tField;
     tObject      = _tObject;
     nextObject   = _nextObject;
     game         = _game;
     row          = 0;
     column       = 4;
     goldenPoints = 0;
     InitialDraw();
 }
Пример #3
0
        public ParallelGame(List <TetrisObject> listOfShapes)
        {
            SuspendLayout();

            labelArray1 = new Label[20, 10];
            labelArray2 = new Label[20, 10];

            labelScore = new Label();
            labelLevel = new Label();
            labelFocus = new Label();

            labelArrayNext1 = new Label[3, 3];
            labelArrayNext2 = new Label[3, 3];

            InitializeComponent();
            game            = new GameScore(ref timer1);
            labelScore.Text = "SCORE:\n" + game.Score.ToString();
            labelLevel.Text = "LEVEL: " + game.Level.ToString();
            labelFocus.Text = "<--";

            this.CreateGrid();

            this.CreateHelp();
            tField1 = new TetrisField(ref labelArray1);
            tField2 = new TetrisField(ref labelArray2);


            this.BackColor = Color.CornflowerBlue;
            //game = new GameScore(ref timer1);

            listOfObjects = new TetrisObject[listOfShapes.Count];
            listOfObjects = listOfShapes.ToArray();
            newGame       = new Game(listOfShapes, false, false, true);

            mObject1 = new MovingObject(tField1, new TetrisObject(listOfObjects[GetRandomNumber()]), new TetrisObject(listOfObjects[GetRandomNumber()]), game);
            mObject2 = new MovingObject(tField2, new TetrisObject(listOfObjects[GetRandomNumber()]), new TetrisObject(listOfObjects[GetRandomNumber()]), game);

            this.ClientSize = new Size(10 * 32 + 3 * 32 + 50 + 10 * 32, 32 * 20 + 1);

            mObjectFocus = mObject1;
            flag         = true;


            ShowNextObject();
            ResumeLayout();
            this.KeyDown += MoveObject;

            game.Start();
        }
Пример #4
0
        readonly Device secDev;            //设备对象
        #endregion

        public MainForm()
        {
            //新建背景音乐线程,循环播放
            musicThread = new Thread(new ThreadStart(delegate { backgroundPlayer.PlayLooping(); }));

            //初始化TetrisGame对象
            tetrisGame = new TetrisGame
            {
                Score    = 0,
                GameOver = true
            };

            //加载存档
            Saver.Load();

            //初始化游戏区域,20×15
            gameField = new GameField(20, 15);

            //初始化“下一个”区域
            nextTetromino = new TetrisField(4, 4);
            //边界(指示器)颜色默认
            nextTetromino.BorderColor = nextTetromino.BackColor;

            //产生随机块
            Random rnd = new Random();

            for (int row = 0; row < gameField.TilesHeight; row++)
            {
                for (int col = 0; col < gameField.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    gameField.SetCell(row, col, t);
                }
            }

            //注册游戏状态变化事件
            tetrisGame.StateChanged += new EventHandler(Game_StateChanged);

            InitializeComponent();

            //初始化声音设备,!当找不到声音设备时将报错!
            secDev = new Device();
            secDev.SetCooperativeLevel(this, CooperativeLevel.Normal);//设置设备协作级别

            //启动背景音乐播放线程
            musicThread.Start();
        }
Пример #5
0
        public MainForm()
        {
            Game        = new TetrisGame();
            Game.Score  = 0; Game.GameOver = true;
            Game.Score2 = 0;

            Saver.Load();

            GF  = new GameField(18, 12);
            GF2 = new GameField(18, 12);/////

            Preview             = new TetrisField(4, 4);
            Preview.BorderColor = Preview.BackColor;

            Preview2             = new TetrisField(4, 4);
            Preview2.BorderColor = Preview2.BackColor;

            Random rnd = new Random();

            // Type splash
            for (int row = 0; row < GF.TilesHeight; row++)
            {
                for (int col = 0; col < GF.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF.SetCell(row, col, t);
                }
            }

            //
            for (int row = 0; row < GF2.TilesHeight; row++)
            {
                for (int col = 0; col < GF2.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF2.SetCell(row, col, t);
                }
            }
            //

            Game.StateChanged += new EventHandler(Game_StateChanged);
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            InitializeComponent();
        }
Пример #6
0
        public Form1(List <TetrisObject> listOfShapes, bool _addObstacles = false, bool _addGoldenPoints = false)
        {
            SuspendLayout();
            addObstacles    = _addObstacles;
            addGoldenPoints = _addGoldenPoints;
            blackFieldAdded = false;
            Random rnd = new Random();

            goldenPointsInterval = rnd.Next(15, 50);
            labelArray           = new Label[20, 10];
            labelScore           = new Label();
            labelLevel           = new Label();
            labelArrayNext       = new Label[3, 3];
            this.CreateGrid();
            this.CreateHelp();

            InitializeComponent();
            game            = new GameScore(ref timer1);
            labelScore.Text = "Score: " + game.Score.ToString();
            labelLevel.Text = "Level: " + game.Level.ToString();

            tField = new TetrisField(ref labelArray);

            this.BackColor = Color.CornflowerBlue;

            //game = new GameScore(ref timer1);

            listOfObjects = new TetrisObject[listOfShapes.Count];
            listOfObjects = listOfShapes.ToArray();
            newGame       = new Game(listOfShapes, _addObstacles, _addGoldenPoints);

            mObject         = new MovingObject(tField, new TetrisObject(listOfObjects[GetRandomNumber()]), new TetrisObject(listOfObjects[GetRandomNumber()]), game);
            this.ClientSize = new Size(10 * 32 + 3 * 32 + 50, 32 * 20 + 1);

            goldenPosition = new Tuple <int, int>(0, 0);

            ShowNextObject();
            ResumeLayout();
            this.KeyDown += MoveObject;

            game.Start();
        }
Пример #7
0
        public Form1(bool _addObstacles = false, bool _addGoldenPoints = false)
        {
            SuspendLayout();
            addObstacles         = _addObstacles;
            addGoldenPoints      = _addGoldenPoints;
            blackFieldAdded      = false;
            goldenPointsInterval = rnd.Next(15, 50);
            labelArray           = new Label[20, 10];
            labelScore           = new Label();
            labelLevel           = new Label();
            labelArrayNext       = new Label[3, 3];
            this.CreateGrid();
            this.CreateHelp();
            tField = new TetrisField(ref labelArray);

            this.BackColor = Color.CornflowerBlue;
            InitializeComponent();
            game = new GameScore(ref timer1);

            labelScore.Text = "SCORE:\n" + game.Score.ToString();
            labelLevel.Text = "LEVEL: " + game.Level.ToString();

            int[,] objekt1 = new int[, ] {
                { 1, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 }
            };
            TetrisObject tObject1 = new TetrisObject(objekt1);

            int[,] objekt2 = new int[, ] {
                { 0, 1, 0 }, { 0, 1, 0 }, { 1, 1, 0 }
            };
            TetrisObject tObject2 = new TetrisObject(objekt2);

            int[,] objekt3 = new int[, ] {
                { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 }
            };
            TetrisObject tObject3 = new TetrisObject(objekt3);

            int[,] objekt4 = new int[, ] {
                { 1, 1, 0 }, { 1, 1, 0 }, { 0, 0, 0 }
            };
            TetrisObject tObject4 = new TetrisObject(objekt4);

            int[,] objekt5 = new int[, ] {
                { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 0 }
            };
            TetrisObject tObject5 = new TetrisObject(objekt5);

            int[,] objekt6 = new int[, ] {
                { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 }
            };
            TetrisObject tObject6 = new TetrisObject(objekt6);

            int[,] objekt7 = new int[, ] {
                { 0, 0, 0 }, { 0, 1, 1 }, { 1, 1, 0 }
            };
            TetrisObject tObject7 = new TetrisObject(objekt7);

            listOfObjects = new TetrisObject[7] {
                tObject1, tObject2, tObject3, tObject4, tObject5, tObject6, tObject7
            };
            List <TetrisObject> list = new List <TetrisObject>()
            {
                tObject1, tObject2, tObject3, tObject4, tObject5, tObject6, tObject7
            };

            newGame = new Game(list);

            mObject         = new MovingObject(tField, new TetrisObject(listOfObjects[GetRandomNumber()]), new TetrisObject(listOfObjects[GetRandomNumber()]), game);
            this.ClientSize = new Size(10 * 32 + 3 * 32 + 50, 32 * 20 + 1);

            goldenPosition = new Tuple <int, int>(0, 0);

            ShowNextObject();
            ResumeLayout();
            this.KeyDown += MoveObject;

            game.Start();
        }