示例#1
0
        protected override void Initialize()
        {
            LoadContent();
            //tetrimino factory
            factory = new TetriminoFactory(tileTexture);

            holdTextPos  = new Vector2((gameWidth / 2) - Tetrimino.tileSize * 8 - font.MeasureString("HOLD").X, gameHeight / 4);
            nextTextPos  = new Vector2((gameWidth / 2) + Tetrimino.tileSize * 8, gameHeight / 4);
            linesTextPos = new Vector2((gameWidth / 2) + Tetrimino.tileSize * 7, 6 * gameHeight / 8);
            levelTextPos = new Vector2((gameWidth / 2) + Tetrimino.tileSize * 7, 5 * gameHeight / 8);

            nextPos = nextTextPos + new Vector2(20, 50);
            holdPos = holdTextPos + new Vector2(20, 50);

            inputs = new Inputs(this);

            boundaries = new List <Boundary>();
            boundaries.Add(new Boundary(BoundarySide.Left, graphics.GraphicsDevice));
            boundaries.Add(new Boundary(BoundarySide.Right, graphics.GraphicsDevice));
            boundaries.Add(new Boundary(BoundarySide.Bottom, graphics.GraphicsDevice));
            boundaries.Add(new Boundary(BoundarySide.Top, graphics.GraphicsDevice));

            Reset();             //everything else set/initialised here
            base.Initialize();
        }
        public void newGame()
        {
            //Resets all necessary variables, then starts a new game.

            gameCanvas.Children.Clear();
            nextBlockCanvas.Children.Clear();

            this.logic = new GameLogic(scoreBox, levelBox, rowsBox);
            this.logic.initializeBoxes();
            gameArray        = new GameArray(gameCanvas, this.logic);
            tetriminoFactory = new TetriminoFactory(gameCanvas, gameArray);

            gameStarted = true;

            CurrentBlock = tetriminoFactory.getNewBlock();
            NextBlock    = tetriminoFactory.getNewBlock();
            drawNext();

            CurrentBlock.Move(CurrentBlock.XCoord, CurrentBlock.YCoord, CurrentBlock.Orientation);
            StartTimer();
        }