Example #1
0
        public object Clone()
        {
            //throw new NotImplementedException();
            Blok b = null;

            if (this is BlokGaris)
            {
                b = new BlokGaris();
            }
            else if (this is BlokKotak)
            {
                b = new BlokKotak();
            }
            else if (this is BlokKros)
            {
                b = new BlokKros();
            }
            else if (this is BlokZNormal)
            {
                b = new BlokZNormal();
            }
            else if (this is BlokZTerbalik)
            {
                b = new BlokZTerbalik();
            }
            else if (this is BlokLNormal)
            {
                b = new BlokLNormal();
            }
            else if (this is BlokLTerbalik)
            {
                b = new BlokLTerbalik();
            }

            b.koordKiriAtas = this.koordKiriAtas;
            b._warnaBlok    = this._warnaBlok;

            for (int i = 0; i < LEBAR; i++)
            {
                for (int j = 0; j < PANJANG; j++)
                {
                    b._elemen[i, j] = this._elemen[i, j];
                }
            }

            return(b);
        }
        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);
        }
        //private void PapanPermainan_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    //BlokGaris b1 = new BlokGaris();
        //    //b1.koordKiriAtas = new Point(0, 0);
        //    //b1.Draw();

        //    //BlokKros b2 = new BlokKros();
        //    //b1.koordKiriAtas = new Point(80, 0);
        //    //b2.Draw();

        //    //BlokZNormal b3 = new BlokZNormal();
        //    //b3.koordKiriAtas = new Point(160, 0);
        //    //b3.Draw();

        //    switch (e.KeyChar)
        //    {
        //        case 'M':
        //            goto case 'm';

        //        case 'm' :
        //            BuatBlokBaru();
        //            break;
        //    }
        //    e.Handled = true;
        //}

        private void BuatBlokBaru()
        {
            // antara 0-6(termasuk 0 dan 6)
            int spesifikasi = _random.Next(0, 7);

            _terkiniBlok = BlokFactory.BuatkanBlok(spesifikasi);
            _terkiniBlok.koordKiriAtas = new Point(100, -60);

            //hitamkan area sebelum buat blok baru
            //Graphics g = this.CreateGraphics();
            //SolidBrush hitam = new SolidBrush(Color.Black);
            int i_max = _terkiniBlok.koordKiriAtas.X + (Blok.PANJANG * OFFSETPIXEL);
            int j_max = _terkiniBlok.koordKiriAtas.Y + (Blok.LEBAR * OFFSETPIXEL);

            for (int i = _terkiniBlok.koordKiriAtas.X; i < i_max; i += OFFSETPIXEL)
            {
                for (int j = _terkiniBlok.koordKiriAtas.Y; j < j_max; j += OFFSETPIXEL)
                {
                    if (i >= 0 && j >= 0)
                    {
                        _elemen[j / OFFSETPIXEL, i / OFFSETPIXEL] = HITAM;
                    }
                    //g.FillRectangle(hitam, i, j, OFFSETPIXEL, OFFSETPIXEL);
                }
            }

            //tampilkan blok baru
            _terkiniBlok.Draw(this);

            //panggil invalidate
            Size s = new Size(Blok.PANJANG * OFFSETPIXEL, Blok.LEBAR * OFFSETPIXEL);

            this.Invalidate(new Rectangle(_terkiniBlok.koordKiriAtas, s));

            //hitam.Dispose();
            //g.Dispose();
        }
Example #4
0
        public static Blok BuatkanBlok(int spesifikasi)
        {
            Blok b = null;

            switch (spesifikasi)
            {
            case Blok.BARIS:
                b = new BlokGaris();
                break;

            case Blok.KOTAK:
                b = new BlokKotak();
                break;

            case Blok.KROS:
                b = new BlokKros();
                break;

            case Blok.ZNORMAL:
                b = new BlokZNormal();
                break;

            case Blok.ZTERBALIK:
                b = new BlokZTerbalik();
                break;

            case Blok.LNORMAL:
                b = new BlokLNormal();
                break;

            case Blok.LTERBALIK:
                b = new BlokLTerbalik();
                break;
            }

            return(b);
        }