#pragma once


namespace ex3
{
 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 ///


 /// Summary for Form1
 ///
 /// WARNING: If you change the name of this class, you will need to change the
 ///          'Resource File Name' property for the managed resource compiler tool
 ///          associated with all .resx files this class depends on.  Otherwise,
 ///          the designers will not be able to interact properly with localized
 ///          resources associated with this form.
 ///

 public __gc class Form1 : public System::Windows::Forms::Form
 {
 public:
  Form1(void)
  {
   InitializeComponent();
  }
 
 protected:
  void Dispose(Boolean disposing)
  {
   if (disposing && components)
   {
    components->Dispose();
   }
   __super::Dispose(disposing);
  }
 private: System::Windows::Forms::TextBox *  textBox1;
 private: System::Windows::Forms::TextBox *  textBox2;
 private: System::Windows::Forms::Button *  button1;
 private: System::Windows::Forms::Timer *  timer1;
 private: System::Windows::Forms::Timer *  timer2;
 private: System::Windows::Forms::PictureBox *  pictureBox1;
 private: System::Windows::Forms::PictureBox *  pictureBox2;
 private: System::Windows::Forms::PictureBox *  pictureBox3;
 private: System::Windows::Forms::PictureBox *  pictureBox4;
 private: System::Windows::Forms::PictureBox *  pictureBox5;
 private: System::Windows::Forms::PictureBox *  pictureBox6;
 private: System::Windows::Forms::PictureBox *  pictureBox7;
 private: System::Windows::Forms::PictureBox *  pictureBox8;
 private: System::Windows::Forms::PictureBox *  pictureBox9;
 private: System::Windows::Forms::Label *  label1;
 private: System::Windows::Forms::Label *  label2;
 private: System::ComponentModel::IContainer *  components;

 private:
  ///


  /// Required designer variable.
  ///


  ///


  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  ///

  void InitializeComponent(void)
  {
   this->components = new System::ComponentModel::Container();
   System::Resources::ResourceManager *  resources = new System::Resources::ResourceManager(__typeof(ex3::Form1));
   this->textBox1 = new System::Windows::Forms::TextBox();
   this->textBox2 = new System::Windows::Forms::TextBox();
   this->button1 = new System::Windows::Forms::Button();
   this->timer1 = new System::Windows::Forms::Timer(this->components);
   this->timer2 = new System::Windows::Forms::Timer(this->components);
   this->pictureBox1 = new System::Windows::Forms::PictureBox();
   this->pictureBox2 = new System::Windows::Forms::PictureBox();
   this->pictureBox3 = new System::Windows::Forms::PictureBox();
   this->pictureBox4 = new System::Windows::Forms::PictureBox();
   this->pictureBox5 = new System::Windows::Forms::PictureBox();
   this->pictureBox6 = new System::Windows::Forms::PictureBox();
   this->pictureBox7 = new System::Windows::Forms::PictureBox();
   this->pictureBox8 = new System::Windows::Forms::PictureBox();
   this->pictureBox9 = new System::Windows::Forms::PictureBox();
   this->label1 = new System::Windows::Forms::Label();
   this->label2 = new System::Windows::Forms::Label();
   this->SuspendLayout();
   //
   // textBox1
   //
   this->textBox1->AutoSize = false;
   this->textBox1->Location = System::Drawing::Point(64, 24);
   this->textBox1->Name = S"textBox1";
   this->textBox1->ReadOnly = true;
   this->textBox1->Size = System::Drawing::Size(136, 40);
   this->textBox1->TabIndex = 0;
   this->textBox1->Text = S"";
   this->textBox1->TextChanged += new System::EventHandler(this, textBox1_TextChanged);
   //
   // textBox2
   //
   this->textBox2->AutoSize = false;
   this->textBox2->Location = System::Drawing::Point(64, 80);
   this->textBox2->Name = S"textBox2";
   this->textBox2->ReadOnly = true;
   this->textBox2->Size = System::Drawing::Size(136, 40);
   this->textBox2->TabIndex = 1;
   this->textBox2->Text = S"";
   //
   // button1
   //
   this->button1->Font = new System::Drawing::Font(S"Wide Latin", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
   this->button1->Location = System::Drawing::Point(264, 40);
   this->button1->Name = S"button1";
   this->button1->Size = System::Drawing::Size(152, 64);
   this->button1->TabIndex = 2;
   this->button1->Text = S"Start";
   this->button1->Click += new System::EventHandler(this, button1_Click);
   this->button1->KeyDown += new System::Windows::Forms::KeyEventHandler(this, button1_KeyDown);
   //
   // timer1
   //
   this->timer1->Tick += new System::EventHandler(this, timer1_Tick);
   //
   // timer2
   //
   this->timer2->Tick += new System::EventHandler(this, timer2_Tick);
   //
   // pictureBox1
   //
   this->pictureBox1->Image = (__try_cast(resources->GetObject(S"pictureBox1.Image")));
   this->pictureBox1->Location = System::Drawing::Point(72, 136);
   this->pictureBox1->Name = S"pictureBox1";
   this->pictureBox1->Size = System::Drawing::Size(72, 72);
   this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox1->TabIndex = 3;
   this->pictureBox1->TabStop = false;
   this->pictureBox1->MouseDown += new System::Windows::Forms::MouseEventHandler(this, pictureBox1_MouseDown);
   //
   // pictureBox2
   //
   this->pictureBox2->Image = (__try_cast(resources->GetObject(S"pictureBox2.Image")));
   this->pictureBox2->Location = System::Drawing::Point(184, 136);
   this->pictureBox2->Name = S"pictureBox2";
   this->pictureBox2->Size = System::Drawing::Size(72, 72);
   this->pictureBox2->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox2->TabIndex = 4;
   this->pictureBox2->TabStop = false;
   this->pictureBox2->Click += new System::EventHandler(this, pictureBox2_Click);
   //
   // pictureBox3
   //
   this->pictureBox3->Image = (__try_cast(resources->GetObject(S"pictureBox3.Image")));
   this->pictureBox3->Location = System::Drawing::Point(288, 136);
   this->pictureBox3->Name = S"pictureBox3";
   this->pictureBox3->Size = System::Drawing::Size(72, 72);
   this->pictureBox3->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox3->TabIndex = 5;
   this->pictureBox3->TabStop = false;
   this->pictureBox3->Click += new System::EventHandler(this, pictureBox3_Click);
   //
   // pictureBox4
   //
   this->pictureBox4->Image = (__try_cast(resources->GetObject(S"pictureBox4.Image")));
   this->pictureBox4->Location = System::Drawing::Point(72, 232);
   this->pictureBox4->Name = S"pictureBox4";
   this->pictureBox4->Size = System::Drawing::Size(72, 72);
   this->pictureBox4->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox4->TabIndex = 6;
   this->pictureBox4->TabStop = false;
   this->pictureBox4->Click += new System::EventHandler(this, pictureBox4_Click);
   //
   // pictureBox5
   //
   this->pictureBox5->Image = (__try_cast(resources->GetObject(S"pictureBox5.Image")));
   this->pictureBox5->Location = System::Drawing::Point(184, 232);
   this->pictureBox5->Name = S"pictureBox5";
   this->pictureBox5->Size = System::Drawing::Size(72, 72);
   this->pictureBox5->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox5->TabIndex = 7;
   this->pictureBox5->TabStop = false;
   this->pictureBox5->Click += new System::EventHandler(this, pictureBox5_Click);
   //
   // pictureBox6
   //
   this->pictureBox6->Image = (__try_cast(resources->GetObject(S"pictureBox6.Image")));
   this->pictureBox6->Location = System::Drawing::Point(288, 232);
   this->pictureBox6->Name = S"pictureBox6";
   this->pictureBox6->Size = System::Drawing::Size(72, 72);
   this->pictureBox6->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox6->TabIndex = 8;
   this->pictureBox6->TabStop = false;
   this->pictureBox6->Click += new System::EventHandler(this, pictureBox6_Click);
   //
   // pictureBox7
   //
   this->pictureBox7->Image = (__try_cast(resources->GetObject(S"pictureBox7.Image")));
   this->pictureBox7->Location = System::Drawing::Point(72, 328);
   this->pictureBox7->Name = S"pictureBox7";
   this->pictureBox7->Size = System::Drawing::Size(72, 72);
   this->pictureBox7->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox7->TabIndex = 9;
   this->pictureBox7->TabStop = false;
   this->pictureBox7->Click += new System::EventHandler(this, pictureBox7_Click);
   //
   // pictureBox8
   //
   this->pictureBox8->Image = (__try_cast(resources->GetObject(S"pictureBox8.Image")));
   this->pictureBox8->Location = System::Drawing::Point(184, 328);
   this->pictureBox8->Name = S"pictureBox8";
   this->pictureBox8->Size = System::Drawing::Size(72, 72);
   this->pictureBox8->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox8->TabIndex = 10;
   this->pictureBox8->TabStop = false;
   this->pictureBox8->Click += new System::EventHandler(this, pictureBox8_Click);
   //
   // pictureBox9
   //
   this->pictureBox9->Image = (__try_cast(resources->GetObject(S"pictureBox9.Image")));
   this->pictureBox9->Location = System::Drawing::Point(288, 328);
   this->pictureBox9->Name = S"pictureBox9";
   this->pictureBox9->Size = System::Drawing::Size(72, 72);
   this->pictureBox9->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox9->TabIndex = 11;
   this->pictureBox9->TabStop = false;
   this->pictureBox9->Click += new System::EventHandler(this, pictureBox9_Click);
   //
   // label1
   //
   this->label1->Font = new System::Drawing::Font(S"新細明體", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)136);
   this->label1->Location = System::Drawing::Point(16, 32);
   this->label1->Name = S"label1";
   this->label1->Size = System::Drawing::Size(48, 24);
   this->label1->TabIndex = 12;
   this->label1->Text = S"時間";
   //
   // label2
   //
   this->label2->Font = new System::Drawing::Font(S"新細明體", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, (System::Byte)136);
   this->label2->Location = System::Drawing::Point(16, 88);
   this->label2->Name = S"label2";
   this->label2->Size = System::Drawing::Size(40, 24);
   this->label2->TabIndex = 13;
   this->label2->Text = S"分數";
   //
   // Form1
   //
   this->AutoScaleBaseSize = System::Drawing::Size(5, 15);
   this->ClientSize = System::Drawing::Size(448, 454);
   this->Controls->Add(this->label2);
   this->Controls->Add(this->label1);
   this->Controls->Add(this->pictureBox9);
   this->Controls->Add(this->pictureBox8);
   this->Controls->Add(this->pictureBox7);
   this->Controls->Add(this->pictureBox6);
   this->Controls->Add(this->pictureBox5);
   this->Controls->Add(this->pictureBox4);
   this->Controls->Add(this->pictureBox3);
   this->Controls->Add(this->pictureBox2);
   this->Controls->Add(this->pictureBox1);
   this->Controls->Add(this->button1);
   this->Controls->Add(this->textBox2);
   this->Controls->Add(this->textBox1);
   this->Name = S"Form1";
   this->Text = S"Form1";
   this->KeyDown += new System::Windows::Forms::KeyEventHandler(this, Form1_KeyDown);
   this->Load += new System::EventHandler(this, Form1_Load);
   this->ResumeLayout(false);

  }

  int total_time,score,n;
 private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
    {
     pictureBox1->Visible=false;
     pictureBox2->Visible=false;
     pictureBox3->Visible=false;
     pictureBox4->Visible=false;
     pictureBox5->Visible=false;
     pictureBox6->Visible=false;
     pictureBox7->Visible=false;
     pictureBox8->Visible=false;
     pictureBox9->Visible=false;
     timer1->Enabled=false;
     timer2->Enabled=false;
     button1->Enabled=true; 
    }

private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
   {
   score=0;
   total_time=30;
   timer1->Interval=1000;
   timer1->Enabled=true;
   timer2->Interval=400;
   timer2->Enabled=true;
   button1->Enabled=false;
   }

private: System::Void timer1_Tick(System::Object *  sender, System::EventArgs *  e)
   {
    total_time=total_time-1;
    textBox1->Text=total_time.ToString();
   }

private: System::Void textBox1_TextChanged(System::Object *  sender, System::EventArgs *  e)
   {
    if (total_time==0)
         {
                timer1->Enabled=false;
                timer2->Enabled=false;
                button1->Enabled=true;
         }
   }

private: System::Void timer2_Tick(System::Object *  sender, System::EventArgs *  e)
   {
     pictureBox1->Visible=false;
     pictureBox2->Visible=false;
     pictureBox3->Visible=false;
     pictureBox4->Visible=false;
     pictureBox5->Visible=false;
     pictureBox6->Visible=false;
     pictureBox7->Visible=false;
     pictureBox8->Visible=false;
     pictureBox9->Visible=false;
     n=rand()%9+1;
     if(n==1)
     {
     pictureBox1->Visible=true;
     }
     if(n==2)
     {
     pictureBox2->Visible=true;
     }
     if(n==3)
     {
     pictureBox3->Visible=true;
     }
     if(n==4)
     {
     pictureBox4->Visible=true;
     }
     if(n==5)
     {
     pictureBox5->Visible=true;
     }
     if(n==6)
     {
     pictureBox6->Visible=true;
     }
     if(n==7)
     {
     pictureBox7->Visible=true;
     }
     if(n==8)
     {
     pictureBox8->Visible=true;
     }
     if(n==9)
     {
     pictureBox9->Visible=true;
     }

   }

private: System::Void Form1_KeyDown(System::Object *  sender, System::Windows::Forms::KeyEventArgs *  e)
   {
    if(e->KeyCode==System::Windows::Forms::Keys::Right)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
   if(pictureBox2->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad8)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox3->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad9)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox4->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad4)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox5->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad5)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox6->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad6)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox7->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad1)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox8->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad2)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox9->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad3)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox1_MouseDown(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
   {
   if(pictureBox1->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }

   }

private: System::Void pictureBox2_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox2->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }

   }

private: System::Void pictureBox3_Click(System::Object *  sender, System::EventArgs *  e)
   {
   if(pictureBox3->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox4_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox4->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox5_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox5->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox6_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox6->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox7_Click(System::Object *  sender, System::EventArgs *  e)
   {
     if(pictureBox7->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox8_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox8->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void pictureBox9_Click(System::Object *  sender, System::EventArgs *  e)
   {
    if(pictureBox9->Visible==true)
    {
     if(total_time!=0)
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

private: System::Void button1_KeyDown(System::Object *  sender, System::Windows::Forms::KeyEventArgs *  e)
   {
   if(pictureBox1->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad7)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
   if(pictureBox2->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad8)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox3->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad9)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox4->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad4)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox5->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad5)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox6->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad6)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox7->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad1)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox8->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad2)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
    if(pictureBox9->Visible==true&&e->KeyCode==System::Windows::Forms::Keys::NumPad3)
    {
     score=score+1;
     textBox2->Text=score.ToString();
    }
   }

};
}

 


創作者介紹
創作者 Miti's Blog 的頭像
mitia

Miti's Blog

mitia 發表在 痞客邦 留言(0) 人氣( 130 )