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