Game ARKANOID Sederhana dengan C# Visual Studio 2012


Untitled

Game ini ditulis dengan bahasa C# di visual Studi 2012, yuk jangan berlama2 lagi berikut syntax kodenya

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

namespace dynamic
{
public partial class Form1 : Form
{
Button[] newbtn = new Button[9];
int dx, dy;
public Form1()
{
InitializeComponent();
this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
dx = 5;
dy = 5;
}

private void Form1_Load(object sender, EventArgs e)
{
//untuk create on the fly button, tetapi kalo lbh dr 1 button
//hanya untuk deklarasi…saat for harus di new lagi
for (int i = 0; i < 9; i++)
{
newbtn[i] = new Button();
newbtn[i].Left = (i %3) * 100;
newbtn[i].Top = (i / 3) * 50;
newbtn[i].Text = Convert.ToString(i);
newbtn[i].Enabled = false;
this.Controls.Add(newbtn[i]);//untuk menambahkan btn yg d create ke form
newbtn[0].Click += new EventHandler(oke);

}
//untuk set procedure tick pada timer
//dilakukan tiap 10ms
timer1.Interval = 100;
timer1.Start();
//this.Focus();
}
void oke(object sender, EventArgs e)
{
Button xx = (Button)sender;
MessageBox.Show(xx.Text);
}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{//untuk mendapatkan tombol dari keyboard yang saya tekan
//jangan lupa properties keypreview pada form = true
// MessageBox.Show(e.KeyChar.ToString());
}

private void Form1_KeyUp(object sender, KeyEventArgs e)
{
// MessageBox.Show(e.KeyCode.ToString() + “up”);
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
button1.Left += 5;
if (e.KeyCode == Keys.Left)
button1.Left -= 5;
if (button1.Left <= 0)
button1.Left = 0;
//if (button1.Left + button1.Width + 25 >= this.Width)
//    button1.Left = this.Width – button1.Width -25;
}

private void timer1_Tick(object sender, EventArgs e)
{
radioButton1.Left -= dx;
radioButton1.Top -= dy;
if (radioButton1.Left == 0)
dx = dx * -1;
else if (radioButton1.Top <= 0)
dy = dy * -1;
else if (radioButton1.Left + radioButton1.Width >= this.Width – 30)
dx = dx * -1;
else if (radioButton1.Left >= button1.Left && radioButton1.Left <= button1.Left + button1.Width && button1.Top <= radioButton1.Top + radioButton1.Height)
dy = dy * -1;
for (int i=0;i<9;i++)
{
if (newbtn[i].Visible == true && radioButton1.Left >= newbtn[i].Left && radioButton1.Left <= newbtn[i].Left + newbtn[i].Width && radioButton1.Top <= newbtn[i].Top + newbtn[i].Height && radioButton1.Top >= newbtn[i].Top)
newbtn[i].Visible = false;
}
}

private void button1_Click(object sender, EventArgs e)
{

}
}
}

 

 

MASUKAN KOMENTAR ANDA !