Friday, October 11, 2013

cara buat game TETRIS in C#

  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tetris
{
    public partial class Form1 : Form
    {
        public lurus2 tetris;
        public Form1()
        {
            InitializeComponent();
        }


        private void btnRandom_Click(object sender, EventArgs e)
        {
            lurus2 tetris = new lurus2();
            tetris.buat(gbLayar);
        }

        class lurus2
        {
            int xawal = 100;
            int yawal = 50;

            Button kotak = new Button();
            Button kotak2 = new Button();
            Button kotak3 = new Button();

            public void buat(GroupBox layar)
            {
                kotak.Size = new Size(20, 20);
                kotak.Left = kotak.Left + xawal;
                kotak.Top = kotak.Top + yawal;
                layar.Controls.Add(kotak);

                kotak2.Size = new Size(20, 20);
                kotak2.Left = kotak.Left + 20;
                kotak2.Top = kotak.Top;
                layar.Controls.Add(kotak2);

                kotak3.Size = new Size(20, 20);
                kotak3.Left = kotak2.Left + 20;
                kotak3.Top = kotak2.Top;
                layar.Controls.Add(kotak3);
            }



            public void geser_kiri()
            {
                kotak.Left = kotak.Left + 20;
                kotak2.Left = kotak2.Left + 20;

            }




            /*void lurus()
            {
                Button kotak = new Button();
                Button kotak2 = new Button();
                Button kotak3 = new Button();
                kotak.Size = new Size(20, 20);

                gbLayar.Controls.Add(kotak);
                kotak.Left = 100;
                kotak.Top = 150;
                kotak2.Left = kotak.Left + 20;
                kotak2.Size = new Size(20, 20);
                kotak2.Top = kotak.Top;
                gbLayar.Controls.Add(kotak2);
                kotak3.Left = kotak2.Left + 20;
                kotak3.Top = kotak.Top;
                kotak3.Size = new Size(20, 20);
                gbLayar.Controls.Add(kotak3);
            }*/

            private void btnKiri_Click(object sender, EventArgs e)
            {

            }

        }

        private void btnKiri_Click(object sender, EventArgs e)
        {
            tetris.geser_kiri();
        }
    }
}

No comments:

Post a Comment