ehm…ada yg pernah tau permainan memory ingatan? mgkn skli2 kita juga bisa ngukur seberapa kuat ingatan kita….
apa salahnya kita mncoba mengetest ingatan kita dengan program ini…
saya akan membeberkan source code nya….
Membuat Form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace CobaIngat
{
public partial class Form1 : Form
{
int time;
private System.Windows.Forms.Timer Clock;
private Label labelTime;
private int nyawa;
private double nilai;
private string jawaban;
private int CounterHint;
public Form1()
{
InitializeComponent();
textBoxInput.ReadOnly = true;
buttonBantu.Enabled = false;
button0.Enabled = false;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
}
private string AcakAngka(int mod)
{
int angka = 0;
Thread.Sleep(1);
Random acak = new Random();
angka = acak.Next() % mod;
return angka.ToString();
}
private void ScoreGame(bool menang)
{
if (menang == true)
{
nilai = nilai + 10;
textBoxScore.Text = nilai.ToString();
progressBar.Increment(1);
}
else
{
nyawa = nyawa - 1;
textBoxNyawa.Text = nyawa.ToString();
}
}
public bool Check()
{
if (textBoxInput.Text == jawaban)
{
MessageBox.Show(”Jawaban anda benar”);
textBoxInput.Text = “”;
return true;
}
else
{
MessageBox.Show(”Jawaban anda salah”);
textBoxInput.Text = “”;
return false;
}
}
private bool CheckNyawa()
{
if (nyawa > 0)
{
return true;
}
else
{
buttonOK.Enabled = true;
MessageBox.Show(”Nyawa anda udah abis”);
textBoxScore.Text = nilai.ToString();
return false;
}
}
private void KeyUpInput(object sender, KeyEventArgs e)
{
if (CheckNyawa())
{
if (e.KeyData == Keys.Enter)
{
if (Check())
{
ScoreGame(true);
time = DateTime.Now.Second;
textBoxDisplay.Visible = true;
//textBoxDisplay.Show();
textBoxDisplay.Text = AcakAngka(10);
jawaban = jawaban + textBoxDisplay.Text;
textBoxInput.Text = “”;
}
else if (nyawa == 1 && !Check())
{
ScoreGame(false);
textBoxInput.ReadOnly = true;
//textBoxDisplay.Show();
}
else
{
ScoreGame(false);
textBoxInput.Visible = true;
time = DateTime.Now.Second;
}
}
}
else
{
textBoxInput.ReadOnly = true;
//ScoreGame(true);
}
}
private void waktu_tick(object sender, EventArgs e)
{
if (sender == Clock)
{
labelTime.Text = GetTime();
}
}
private string GetTime()
{
string TimeString = “”;
int sec = DateTime.Now.Second;
int count = time + 3;
if (count.ToString().Equals(sec.ToString()))
{
textBoxDisplay.Visible = true;
}
return TimeString;
}
private void StartOK_Click(object sender, EventArgs e)
{
nyawa = 3;
nilai = 0;
//textBoxScore.Text = nilai.ToString();
buttonBantu.Enabled = true;
textBoxNyawa.Text = nyawa.ToString();
textBoxInput.ReadOnly = false;
textBoxInput.Text = “”;
jawaban = “”;
textBoxDisplay.Text = AcakAngka(10);
jawaban = jawaban + textBoxDisplay.Text;
time = DateTime.Now.Second;
Clock = new System.Windows.Forms.Timer();
Clock.Interval = 1000;
Clock.Start();
Clock.Tick += new EventHandler(waktu_tick);
labelTime = new Label();
this.Controls.Add(labelTime);
labelTime.Text = GetTime();
labelTime.Visible = false;
CounterHint = 3;
progressBar.Value = 0;
progressBar.Maximum = 25;
button0.Enabled = true;
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
}
private void StartRestart_Click(object sender, EventArgs e)
{
nyawa = 3;
nilai = 0;
buttonBantu.Enabled = true;
textBoxScore.Text = nilai.ToString();
textBoxScore.Visible = true;
textBoxNyawa.Text = nyawa.ToString();
textBoxDisplay.Visible = false;
textBoxInput.ReadOnly = false;
textBoxInput.Text = “”;
textBoxScore.Text = “”;
jawaban = “”;
textBoxDisplay.Text = AcakAngka(10);
jawaban = jawaban + AcakAngka(10);
time = DateTime.Now.Second;
Clock = new System.Windows.Forms.Timer();
Clock.Interval = 1000;
Clock.Start();
Clock.Tick += new EventHandler(waktu_tick);
labelTime = new Label();
this.Controls.Add(labelTime);
labelTime.Text = GetTime();
labelTime.Visible = false;
CounterHint = 3;
progressBar.Value = 0;
progressBar.Maximum = 25;
}
private void button0_Click(object sender, EventArgs e)
{
int input = 0;
textBoxInput.Text += input;
}
private void button1_Click(object sender, EventArgs e)
{
int input = 1;
textBoxInput.Text += input;
}
private void button2_Click(object sender, EventArgs e)
{
int input = 2;
textBoxInput.Text += input;
}
private void button3_Click(object sender, EventArgs e)
{
int input = 3;
textBoxInput.Text += input;
}
private void button4_Click(object sender, EventArgs e)
{
int input = 4;
textBoxInput.Text += input;
}
private void button5_Click(object sender, EventArgs e)
{
int input = 5;
textBoxInput.Text += input;
}
private void button6_Click(object sender, EventArgs e)
{
int input = 6;
textBoxInput.Text += input;
}
private void button7_Click(object sender, EventArgs e)
{
int input = 7;
textBoxInput.Text += input;
}
private void button8_Click(object sender, EventArgs e)
{
int input = 8;
textBoxInput.Text += input;
}
private void button9_Click(object sender, EventArgs e)
{
int input = 9;
textBoxInput.Text += input;
}
private void button10_Click(object sender, EventArgs e)
{
if (CheckNyawa())
{
if (Check())
{
ScoreGame(true);
time = DateTime.Now.Second;
textBoxDisplay.Visible = true;
//textBoxDisplay.Show();
textBoxDisplay.Text = AcakAngka(10);
jawaban = jawaban + textBoxDisplay.Text;
textBoxInput.Text = “”;
}
else if (nyawa == 1 && !Check())
{
ScoreGame(false);
textBoxInput.ReadOnly = true;
//textBoxDisplay.Show();
}
else
{
ScoreGame(false);
textBoxInput.Visible = true;
time = DateTime.Now.Second;
}
}
}
private void buttonBantu_Click(object sender, EventArgs e)
{
int panjangJawab = jawaban.Length;
for (int a = 0; a < panjangJawab; a++)
{
textBoxBantu.Text = jawaban.Substring(a, 1);
Thread.Sleep(800);
textBoxBantu.Update();
textBoxBantu.Text = “”;
Thread.Sleep(100);
textBoxBantu.Update();
}
textBoxBantu.Text = “”;
CounterHint–;
}
private void Hint()
{
if (CounterHint > 0)
{
textBoxBantu.Enabled = true;
}
else
{
textBoxBantu.Enabled = false;
}
}
}
}
berikut adalah bentuk program yang telah dijalankan :

