Facebook
From Harmless Water Vole, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 136
  1. #pragma once
  2. #include <cstdlib>
  3. namespace ProgramZaliczeniowy {
  4.  
  5.         using namespace System;
  6.         using namespace System::ComponentModel;
  7.         using namespace System::Collections;
  8.         using namespace System::Windows::Forms;
  9.         using namespace System::Data;
  10.         using namespace System::Drawing;
  11.  
  12.         /// <summary>
  13.         /// Summary for zgadnijNumer
  14.         /// </summary>
  15.         public ref class zgadnijNumer : public System::Windows::Forms::Form
  16.         {
  17.         public:
  18.                 zgadnijNumer(void)
  19.                 {
  20.                         InitializeComponent();
  21.                         //
  22.                         //TODO: Add the constructor code here
  23.                         //
  24.                 }
  25.  
  26.         protected:
  27.                 /// <summary>
  28.                 /// Clean up any resources being used.
  29.                 /// </summary>
  30.                 ~zgadnijNumer()
  31.                 {
  32.                         if (components)
  33.                         {
  34.                                 delete components;
  35.                         }
  36.                 }
  37.         private: System::Windows::Forms::Button^  button1;
  38.         protected:
  39.         private: System::Windows::Forms::TextBox^  textBox1;
  40.         private: System::Windows::Forms::Button^  button2;
  41.         private: System::Windows::Forms::Label^  czyZgadleslbl;
  42.  
  43.  
  44.  
  45.         private:
  46.                 /// <summary>
  47.                 /// Required designer variable.
  48.                 /// </summary>
  49.                 System::ComponentModel::Container ^components;
  50.  
  51. #pragma region Windows Form Designer generated code
  52.                 /// <summary>
  53.                 /// Required method for Designer support - do not modify
  54.                 /// the contents of this method with the code editor.
  55.                 /// </summary>
  56.                 void InitializeComponent(void)
  57.                 {
  58.                         System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(zgadnijNumer::typeid));
  59.                         this->button1 = (gcnew System::Windows::Forms::Button());
  60.                         this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  61.                         this->button2 = (gcnew System::Windows::Forms::Button());
  62.                         this->czyZgadleslbl = (gcnew System::Windows::Forms::Label());
  63.                         this->SuspendLayout();
  64.                         //
  65.                         // button1
  66.                         //
  67.                         this->button1->BackColor = System::Drawing::Color::Transparent;
  68.                         this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.BackgroundImage")));
  69.                         this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
  70.                         this->button1->FlatAppearance->BorderSize = 0;
  71.                         this->button1->FlatAppearance->MouseDownBackColor = System::Drawing::Color::Transparent;
  72.                         this->button1->FlatAppearance->MouseOverBackColor = System::Drawing::Color::Transparent;
  73.                         this->button1->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
  74.                         this->button1->Font = (gcnew System::Drawing::Font(L"Buxton Sketch", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  75.                                 static_cast<System::Byte>(238)));
  76.                         this->button1->ForeColor = System::Drawing::SystemColors::Info;
  77.                         this->button1->Location = System::Drawing::Point(47, 305);
  78.                         this->button1->Name = L"button1";
  79.                         this->button1->Size = System::Drawing::Size(101, 52);
  80.                         this->button1->TabIndex = 0;
  81.                         this->button1->Text = L"NEW NUMBER";
  82.                         this->button1->UseVisualStyleBackColor = false;
  83.                         this->button1->Click += gcnew System::EventHandler(this, &zgadnijNumer::button1_Click);
  84.                         //
  85.                         // textBox1
  86.                         //
  87.                         this->textBox1->Enabled = false;
  88.                         this->textBox1->Location = System::Drawing::Point(47, 114);
  89.                         this->textBox1->Name = L"textBox1";
  90.                         this->textBox1->Size = System::Drawing::Size(101, 20);
  91.                         this->textBox1->TabIndex = 3;
  92.                         this->textBox1->TextChanged += gcnew System::EventHandler(this, &zgadnijNumer::textBox1_TextChanged);
  93.                         //
  94.                         // button2
  95.                         //
  96.                         this->button2->BackColor = System::Drawing::Color::Transparent;
  97.                         this->button2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button2.BackgroundImage")));
  98.                         this->button2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
  99.                         this->button2->FlatAppearance->BorderSize = 0;
  100.                         this->button2->FlatAppearance->MouseDownBackColor = System::Drawing::Color::Transparent;
  101.                         this->button2->FlatAppearance->MouseOverBackColor = System::Drawing::Color::Transparent;
  102.                         this->button2->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
  103.                         this->button2->Font = (gcnew System::Drawing::Font(L"Buxton Sketch", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  104.                                 static_cast<System::Byte>(238)));
  105.                         this->button2->ForeColor = System::Drawing::SystemColors::Info;
  106.                         this->button2->Location = System::Drawing::Point(47, 155);
  107.                         this->button2->Name = L"button2";
  108.                         this->button2->Size = System::Drawing::Size(101, 49);
  109.                         this->button2->TabIndex = 4;
  110.                         this->button2->Text = L"GUESS";
  111.                         this->button2->UseVisualStyleBackColor = false;
  112.                         this->button2->Click += gcnew System::EventHandler(this, &zgadnijNumer::button2_Click);
  113.                         //
  114.                         // czyZgadleslbl
  115.                         //
  116.                         this->czyZgadleslbl->BackColor = System::Drawing::Color::Transparent;
  117.                         this->czyZgadleslbl->Font = (gcnew System::Drawing::Font(L"Buxton Sketch", 11.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
  118.                                 static_cast<System::Byte>(238)));
  119.                         this->czyZgadleslbl->Location = System::Drawing::Point(360, 132);
  120.                         this->czyZgadleslbl->Name = L"czyZgadleslbl";
  121.                         this->czyZgadleslbl->Size = System::Drawing::Size(100, 23);
  122.                         this->czyZgadleslbl->TabIndex = 5;
  123.                         this->czyZgadleslbl->Text = L"...";
  124.                         this->czyZgadleslbl->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
  125.                         //
  126.                         // zgadnijNumer
  127.                         //
  128.                         this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  129.                         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  130.                         this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
  131.                         this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
  132.                         this->ClientSize = System::Drawing::Size(549, 459);
  133.                         this->Controls->Add(this->czyZgadleslbl);
  134.                         this->Controls->Add(this->button2);
  135.                         this->Controls->Add(this->textBox1);
  136.                         this->Controls->Add(this->button1);
  137.                         this->DoubleBuffered = true;
  138.                         this->MaximizeBox = false;
  139.                         this->Name = L"zgadnijNumer";
  140.                         this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
  141.                         this->Text = L"Guess The Number";
  142.                         this->ResumeLayout(false);
  143.                         this->PerformLayout();
  144.  
  145.                 }
  146. #pragma endregion
  147.                 int numer;
  148.                 int guess;
  149.                 int strzal = 0;
  150.                
  151.         public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  152.                 numer = rand() % 100 + 1;
  153.                 textBox1->Enabled = true;
  154.                
  155.                
  156.                
  157.         }
  158.         private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
  159.                
  160.                
  161.                
  162.                 guess = Int32::Parse(textBox1->Text);
  163.                
  164.                         if (guess<numer)
  165.                         {
  166.                                 czyZgadleslbl->Text = "To za mało";
  167.                                 strzal++;
  168.                         }
  169.                         else if (guess>numer)
  170.                         {
  171.                                 czyZgadleslbl->Text = "To za dużo";
  172.                                 strzal++;
  173.                         }
  174.  
  175.                         else if  (guess == numer)
  176.                         {
  177.                                 czyZgadleslbl->Text = "To git";
  178.                                 strzal++;
  179.                                 MessageBox::Show("Udało Ci się odgadnąć liczbę! Zajęło Ci to " + strzal.ToString() + " prób.", "Gratulacje", MessageBoxButtons::YesNo,MessageBoxIcon::Information );
  180.  
  181.                         }
  182.        
  183.  
  184.        
  185.                
  186.         }
  187. private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
  188.         guess = Int32::Parse(textBox1->Text);
  189. }
  190. };
  191. }
  192.