コード例 #1
0
    public void HandleInput(GameTime gameTime, InputHelper inputHelper)
    {
        switch (chooseBlock.Current)
        {
        case 0:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Iblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Iblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Iblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Iblok.Right();
            }
            for (int x = 0; x < Iblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Iblok.Width; y++)
                {
                    if ((grid.Check(Iblok.Position.X, Iblok.Position.Y, x + 1, y)) && (Iblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Iblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Iblok.Width; y++)
                    {
                        if (Iblok.Check(x, y) != false)
                        {
                            grid.Place(Iblok.Position.X, Iblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Iblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 1:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Oblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Oblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Oblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Oblok.Right();
            }
            for (int x = 0; x < Oblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Oblok.Width; y++)
                {
                    if ((int)Oblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Oblok.Position.X, Oblok.Position.Y, x + 1, y)) && (Oblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Oblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Oblok.Width; y++)
                    {
                        if (Oblok.Check(x, y) != false)
                        {
                            grid.Place(Oblok.Position.X, Oblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Oblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 2:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Tblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Tblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Tblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Tblok.Right();
            }
            for (int x = 0; x < Tblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Tblok.Width; y++)
                {
                    if ((int)Tblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Tblok.Position.X, Tblok.Position.Y, x + 1, y)) && (Tblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Tblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Tblok.Width; y++)
                    {
                        if (Tblok.Check(x, y) != false)
                        {
                            grid.Place(Tblok.Position.X, Tblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Tblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 3:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Sblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Sblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Sblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Sblok.Right();
            }
            for (int x = 0; x < Sblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Sblok.Width; y++)
                {
                    if ((int)Sblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Sblok.Position.X, Sblok.Position.Y, x + 1, y)) && (Sblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Sblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Sblok.Width; y++)
                    {
                        if (Sblok.Check(x, y) != false)
                        {
                            grid.Place(Sblok.Position.X, Sblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Sblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 4:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Zblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Zblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Zblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Zblok.Right();
            }
            for (int x = 0; x < Zblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Zblok.Width; y++)
                {
                    if ((int)Zblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Zblok.Position.X, Zblok.Position.Y, x + 1, y)) && (Zblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Zblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Zblok.Width; y++)
                    {
                        if (Zblok.Check(x, y) != false)
                        {
                            grid.Place(Zblok.Position.X, Zblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Zblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 5:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Jblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Jblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Jblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Jblok.Right();
            }
            for (int x = 0; x < Jblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Jblok.Width; y++)
                {
                    if ((int)Jblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Jblok.Position.X, Jblok.Position.Y, x + 1, y)) && (Jblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Jblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Jblok.Width; y++)
                    {
                        if (Jblok.Check(x, y) != false)
                        {
                            grid.Place(Jblok.Position.X, Jblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Jblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;

        case 6:
            if (inputHelper.KeyPressed(Keys.W))
            {
                Lblok.Up();
            }
            if (inputHelper.KeyPressed(Keys.A))
            {
                //tetromino.X--; // This one probably has to be changed with set

                Lblok.Left();
            }
            timer -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer < 0)
            {
                Console.WriteLine("S");
                Lblok.Down();
                timer = (float)gameTime.ElapsedGameTime.TotalMilliseconds + speed;
            }
            if (inputHelper.KeyPressed(Keys.D))
            {
                //tetromino.X++; // This one probably has to be changed with set
                Console.WriteLine("D");
                Lblok.Right();
            }
            for (int x = 0; x < Lblok.Width; x++)
            {
                Console.WriteLine();
                for (int y = 0; y < Lblok.Width; y++)
                {
                    if ((int)Lblok.Position.Y - 1 == 0)
                    {
                        Down = true;
                    }
                    else if ((grid.Check(Lblok.Position.X, Lblok.Position.Y, x + 1, y)) && (Lblok.Check(x, y) != false))
                    {
                        Down = true;
                    }
                }
            }
            if (Down)
            {
                for (int x = 0; x < Lblok.Width; x++)
                {
                    Console.WriteLine();
                    for (int y = 0; y < Lblok.Width; y++)
                    {
                        if (Lblok.Check(x, y) != false)
                        {
                            grid.Place(Lblok.Position.X, Lblok.Position.Y, x, y);
                        }
                    }
                }
                score += grid.CheckLine();
                Lblok.Clear();
                Down = false;
                chooseBlock.genNext();
            }
            break;
        }
    }