Esempio n. 1
0
    public GameWorld()
    {
        random    = new Random();
        gameState = GameState.Playing;

        font  = TetrisGame.ContentManager.Load <SpriteFont>("SpelFont");
        speed = 15;
        grid  = new TetrisGrid();
        block = block.GetRandomBlock(random.Next(0, 7));
        //block = new BlockI(new Vector2(4, -4));
        blockWidth  = block.curBool.GetLength(1);
        blockHeight = block.curBool.GetLength(0);
        blockList   = new List <TetrisBlocks>();
    }
Esempio n. 2
0
 void BlockUpdate()
 {
     AddBlock(block.blockSize, block.blockSize);
     LineFull();
     block = nextBlock;
     nextBlock = block.GetRandomBlock(random.Next(0, 7));
     hold = true;
 }
Esempio n. 3
0
    public void Reset()
    {
        for (int x = 0; x < grid.Width; x++)
        {
            for (int y = 0; y < grid.Height; y++)
            {
                grid.grid[y, x] = null;

            }
        }
        score = 0;
        speed = 15;
        level = 1;
        block = block.GetRandomBlock(random.Next(0, 7));
        nextBlock = block.GetRandomBlock(random.Next(0, 7));
    }
Esempio n. 4
0
    public void HandleInput(GameTime gameTime, InputHelper inputHelper)
    {
        if (gameState == GameState.Title)
        {
            if (inputHelper.MouseLeftButtonPressed())
            {
                gameState = GameState.Playing;
            }
        }
        if (gameState == GameState.GameOver)
        {
            if (inputHelper.MouseLeftButtonPressed())
            {
                gameState = GameState.Title;
            }
        }
        if (gameState == GameState.Playing)
        {
            if (inputHelper.KeyPressed(Keys.Left))
            {
                if (block.Location.X > 0 - LeftClear() && CanGoLeft())
                    block.Location.X--;
                if (!NoCollision())
                    grid.tijd = 0;
            }

            if (inputHelper.KeyPressed(Keys.Right))
            {
                if (block.Location.X + block.blockSize < grid.Width + RightClear() && CanGoRight())
                    block.Location.X++;
                if (!NoCollision())
                    grid.tijd = 0;
            }

            if (inputHelper.KeyPressed(Keys.Space))
            {
                while (NoCollision())
                {
                    block.Location.Y += 1;
                }
                space = true;
            }

            if (inputHelper.KeyPressed(Keys.A))
            {

                MoveIfBlocked();
                if (CanGoLeft() && CanGoRight())
                    block.curBool = Rotate(block.curBool, false, block.blockSize);
                if (!NoCollision())
                    grid.tijd = 0;

            }

            if (inputHelper.KeyPressed(Keys.D))
            {
                MoveIfBlocked();
                if (CanGoLeft() && CanGoRight())
                    block.curBool = Rotate(block.curBool, true, block.blockSize);
                if (!NoCollision())
                    grid.tijd = 0;
            }


            if (inputHelper.KeyPressed(Keys.C))
            {
                if (holdBlock == null)
                {
                    holdBlock = block;
                    block = nextBlock;
                    nextBlock = block.GetRandomBlock(random.Next(0, 7));
                    block.Location = block.SpawnLocation;
                }
                if (hold)
                {
                    saveBlock = block;
                    block = holdBlock;
                    holdBlock = saveBlock;
                    block.Location = block.SpawnLocation;
                    hold = false;
                }

            }

        }
    }