Simple games by using Buttons and Labels

Chandrakanth
Posted by Chandrakanth under C# category on | Points: 40 | Views : 1213
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 Button_Game
{
public partial class Form1 : Form
{
int flag, i = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Visible = false;
button2.Visible = false;
button3.Visible = false;
button4.Visible = false;
button5.Visible = false;
button6.Visible = false;
button7.Visible = false;
button8.Visible = false;
button9.Visible = false;
label2.Text = i.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{ Random random = new Random();
int randomno = random.Next(1, 10);
if (randomno == 1)
{
flag = 1;
button1.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 2)
{
flag = 2;
button2.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 3)
{
flag = 3;
button3.Visible = true;
timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 4)
{
flag = 4;
button4.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 5)
{
flag = 5;
button5.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 6)
{
flag = 6;
button6.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 7)
{
flag = 7;
button7.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 8)
{
flag = 8;
button8.Visible = true;
timer1.Enabled = false;
timer2.Enabled = true;
}
else if (randomno == 9)
{
flag = 9;
button9.Visible = true;

timer1.Enabled = false;
timer2.Enabled = true;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (flag == 1)
{
button1.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 2)
{
button2.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 3)
{
button3.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 4)
{
button4.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 5)
{
button5.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 6)
{
button6.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 7)
{
button7.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 8)
{
button8.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
else if (flag == 9)
{
button9.Visible = false;
timer2.Enabled = false;
timer1.Enabled = true;
}
}

private void button1_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}

private void button2_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button3_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button4_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button5_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button6_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button7_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button8_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button9_Click(object sender, EventArgs e)
{
label2.Text = (i++).ToString();
}
private void button10_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void button11_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
timer2.Enabled = false;
button1.Visible = false;
button2.Visible = false;
button3.Visible = false;
button4.Visible = false;
button5.Visible = false;
button6.Visible = false;
button7.Visible = false;
button8.Visible = false;
button9.Visible = false;
i = 0;
label2.Text = i.ToString();
}
private void button12_Click(object sender, EventArgs e)
{
MessageBox.Show(" JUST CLICK ON BOXES BEFORE THEY DISAPPEAR AND IF CLICKED YOU GET A +1 SCORE");
}

private void button13_Click(object sender, EventArgs e)
{
MessageBox.Show("Quick Reaction 1.0, This is my First Window app created in visual c#");
}
}
}

Comments or Responses

Posted by: Siri on: 4/26/2012 Level:Starter | Status: [Member] | Points: 10
It's working perfect good program
Posted by: Chandrakanth on: 10/2/2012 Level:Starter | Status: [Member] | Points: 10
Thank u siri

Login to post response