Langkah-langkahnya :
1. Buat Form yang menarik untuk dilihat .
2. Setelah form jadi tulis beberapa function yang diperlukan seperti di bawah ini.
private void NewGame() // mendefinisikan Game Baru
{
L1.Text = ""; L1.BackColor = Color.DarkCyan;
L2.Text = "" ; L2.BackColor = Color.Blue;
L3.Text = ""; L3.BackColor = Color.Coral;
L4.Text = ""; L4.BackColor = Color.Chocolate;
L5.Text = ""; L5.BackColor = Color.ForestGreen;
L6.Text = "" ; L6.BackColor = Color.Gold;
L7.Text = "" ; L7.BackColor = Color.Green;
L8.Text = "" ; L8.BackColor = Color.HotPink;
L9.Text = "" ; L9.BackColor = Color.Purple;
L10.Text = ""; L10.BackColor = Color.DarkSlateBlue;
L11.Text = "" ; L11.BackColor = Color.LightSalmon;
L12.Text = "" ; L12.BackColor = Color.Magenta;
L13.Text = "" ; L13.BackColor = Color.Red;
L14.Text = "" ; L14.BackColor = Color.Olive;
L15.Text = ""; L15.BackColor = Color.DeepPink;
L16.Text = ""; L16.BackColor = Color.Black;
Timer1.Enabled = false;
Label1.Text = "00:00:00";
l = new Label();
Random r = new Random(); // Untuk membuat nilai Random/acak bila New Game ditekan
int j = 1;
for (i=1; i<=150; i++)
{
int v = r.Next(1, 16);
Selection(v);
if (l.Text == "")
{
l.Text = j.ToString();
j = j + 1;
}
}
}
private void Change() // Memberi warna bila ada perubahan kotak
{
l.Text = n.Text;
l.BackColor = n.BackColor;
n.Text = "";
n.BackColor = Color.Black;
}
private void Clicks() // Function yang harus dilakukan bila Mouse ditekan
{
if (Timer1.Enabled == false)
{
t = 0;
Timer1.Enabled = true;
}
if (x==4|x==8|x==12)
{
y = x;
}
else
{
y = x + 1;
}
Selection(y);
if (l.Text == "")
{
Change();
}
else
{
if (x==5|x==5|x==13)
{
y = x;
}
else
{
y = x - 1;
}
Selection(y);
if (l.Text == "")
{
Change();
}
else
{
y = x + 4;
Selection(y);
if (l.Text == "")
{
Change();
}
else
{
y = x - 4;
Selection(y);
if (l.Text == "")
{
Change();
}
}
}
}
if (L1.Text == "1" & L2.Text == "2" & L3.Text == "3" & L4.Text == "4" & L5.Text == "5" & L6.Text == "6" & L7.Text == "7" & L8.Text == "8" & L9.Text == "9" & L10.Text == "10" & L11.Text == "11" & L12.Text == "12" & L13.Text == "13" & L14.Text == "14" & L15.Text == "15" & L16.Text == "16")
{
Timer1.Enabled = false;
if (h > 0 & m > 0 & s > 0)
{
str = h + " Hours " + m + " Minutes " + s + " Seconds.";
}
else
{
if (m > 0 & s > 0)
{
str = m + " Minutes " + s + " Seconds.";
}
else
{
if (s > 0)
{
str = s + " Seconds.";
}
}
}
if (MessageBox.Show("YOU WON\n\nTime Taken Is" + str + "\n\nDo You Want Another Game?", "Rubik Puzzle", MessageBoxButtons.YesNo) == DialogResult.Yes )
{
NewGame();
}
else
{
this.Dispose ();
}
}
}
Begitulah code program yang bisa anda buat untuk game sederhana untuk anak-anak.Contoh hasilnya bisa di download disini.
Tidak ada komentar:
Posting Komentar