Exemplo n.º 1
0
        private bool BisaDiturunkan()
        {
            Point koordBaru = new Point(_terkiniBlok.koordKiriAtas.X, _terkiniBlok.koordKiriAtas.Y + OFFSETPIXEL);

            int offset_i = koordBaru.Y / OFFSETPIXEL;
            int offset_j = koordBaru.X / OFFSETPIXEL;

            int  barisTerbawah = Blok.LEBAR - 1;
            bool found         = false;

            for (int i = barisTerbawah; i >= 0 && !found; i--)
            {
                for (int j = 0; j < Blok.PANJANG && !found; j++)
                {
                    if (_terkiniBlok.GetElement(i, j) == true)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    --barisTerbawah;
                }
            }

            for (int j = 0; j < Blok.PANJANG; j++)
            {
                if (_terkiniBlok.GetElement(barisTerbawah, j) == true && offset_i + barisTerbawah >= PapanPermainan.TINGGI)
                {
                    return(false);
                }

                if (_terkiniBlok.GetElement(barisTerbawah, j) == true && _elemen[offset_i + barisTerbawah, offset_j + j] > HITAM)
                {
                    return(false);
                }
            }

            //tidak menyentuh apa2
            return(true);
        }
Exemplo n.º 2
0
        private bool BisaRotasi(char key)
        {
            Blok b = (Blok)_terkiniBlok.Clone();

            switch (key)
            {
            case 'w':
                b.RotateAtas();
                break;

            case 'a':
                b.RotateKiri();
                break;

            case 's':
                b.RotateBawah();
                break;

            case 'd':
                b.RotateKanan();
                break;
            }

            int offset_i = b.koordKiriAtas.Y / OFFSETPIXEL;
            int offset_j = b.koordKiriAtas.X / OFFSETPIXEL;

            for (int i = 0; i < Blok.LEBAR; i++)
            {
                for (int j = 0; j < Blok.PANJANG; j++)
                {
                    if (offset_j + j >= 0 && offset_j + j <= PapanPermainan.LEBAR - 1 && offset_i + i >= 0 && offset_i + i <= PapanPermainan.TINGGI - 1 && b.GetElement(i, j) == true && _terkiniBlok.GetElement(i, j) == false && _elemen[offset_i + i, offset_j + j] > HITAM)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }