2013-12-3
Xiaomi flash sale program
The activation code is 100 Xiaomi mobile phones. Three people buy the first mobile phone respectively. The network speed is 1 second. You can grab a mobile phone. The second is 5 seconds. The third is 10 seconds. Three people cannot grab the same mobile phone.
My thinking: ①: set three timer1 timer2 timer3 and set the attribute Interval to the corresponding network speed.
②: Three richTextBox1 are used to facilitate scroll bars when numbers are large.
③ Use a button to snap up and click three times, which means three people use the cycle.
④ The three labels show the number of mobile phones sold by three people.
Code thinking: define two global variables n1 sum (n1 = 1 indicates the number of 100 mobile phones starting from 1 sum = 100)
N1 must be in the if Loop
Define the global variable m to show the quantity of snapped up increase when sum
And so on... Remember: m is the timer1 variable timer2 and timer3 need to define two more
The complete code is as follows: a small program reads and plays in class
All code: 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 WindowsFormsApplication3
{
Public partial class Form3: Form
{
PublicForm3 ()
{
InitializeComponent ();
}
Intn1 = 1;
Int sum = 100;
Int m = 0;
Int m1 = 0;
Int m2 = 0;
Private voidtimereffectick (object sender, EventArgs e)
{
If (n1 <= sum)
{
RichTextBox1.AppendText (n1.ToString () + "\ n \ r ");
RichTextBox1.ScrollToCaret ();
N1 ++; m ++;
}
If (sum
{
Timer1.Stop ();
}
Label5.Text = "Total" + m;
}
Privatevoid timer2_Tick (objectsender, EventArgs e)
{
If (n1 <sum)
{
RichTextBox2.AppendText (n1.ToString () + "\ n \ r ");
RichTextBox2.ScrollToCaret ();
N1 ++; m1 ++;
}
If (sum <n1)
{
Timer2.Stop ();
}
Label6.Text = "Total:" + m1;
}
Privatevoid timer3_Tick (objectsender, EventArgs e)
{
If (n1 <sum)
{
RichTextBox3.AppendText (n1.ToString () + "\ n \ r ");
RichTextBox3.ScrollToCaret ();
N1 ++; m2 ++;
}
If (sum
{
Timer3.Stop ();
}
Label7.Text = "Total" + m2;
}
Int Num = 0;
Privatevoid button#click (objectsender, EventArgs e)
{
Num ++;
If (Num = 1)
{
Timer1.Start ();
}
Elseif (Num = 2)
{
Timer2.Start ();
}
Elseif (Num = 3)
{
Timer3.Start ();
}
Else
{
MessageBox. Show ("already °? You have bought o from the hacker and bought o from the hacker! ");
}
}
}