Advertisement
Guest User

Untitled

a guest
Jul 17th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.97 KB | None | 0 0
  1. #include<time.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include<ctime>
  5. #include<cstdlib>
  6.  
  7. #pragma once
  8.  
  9. namespace RockPaperScisors {
  10.  
  11.     using namespace System;
  12.     using namespace System::ComponentModel;
  13.     using namespace System::Collections;
  14.     using namespace System::Windows::Forms;
  15.     using namespace System::Data;
  16.     using namespace System::Drawing;
  17.  
  18.     /// <summary>
  19.     /// Summary for Form1
  20.     /// </summary>
  21.     public ref class Form1 : public System::Windows::Forms::Form
  22.     {
  23.     public:
  24.         Form1(void)
  25.         {
  26.             InitializeComponent();
  27.             //
  28.             //TODO: Add the constructor code here
  29.             //
  30.         }
  31.  
  32.     protected:
  33.         /// <summary>
  34.         /// Clean up any resources being used.
  35.         /// </summary>
  36.         ~Form1()
  37.         {
  38.             if (components)
  39.             {
  40.                 delete components;
  41.             }
  42.         }
  43.     private: System::Windows::Forms::Button^  Rock;
  44.     protected:
  45.     private: System::Windows::Forms::Button^  Paper;
  46.     private: System::Windows::Forms::Button^  cis;
  47.     private: System::Windows::Forms::TextBox^  ComBox;
  48.  
  49.     private: System::Windows::Forms::TextBox^  WonBox;
  50.     private: System::Windows::Forms::Label^  CompLabel;
  51.  
  52.  
  53.     private: System::Windows::Forms::Label^  WonLabel;
  54.  
  55.  
  56.     private:
  57.         /// <summary>
  58.         /// Required designer variable.
  59.         /// </summary>
  60.         System::ComponentModel::Container ^components;
  61.  
  62. #pragma region Windows Form Designer generated code
  63.         /// <summary>
  64.         /// Required method for Designer support - do not modify
  65.         /// the contents of this method with the code editor.
  66.         /// </summary>
  67.         void InitializeComponent(void)
  68.         {
  69.             this->Rock = (gcnew System::Windows::Forms::Button());
  70.             this->Paper = (gcnew System::Windows::Forms::Button());
  71.             this->cis = (gcnew System::Windows::Forms::Button());
  72.             this->ComBox = (gcnew System::Windows::Forms::TextBox());
  73.             this->WonBox = (gcnew System::Windows::Forms::TextBox());
  74.             this->CompLabel = (gcnew System::Windows::Forms::Label());
  75.             this->WonLabel = (gcnew System::Windows::Forms::Label());
  76.             this->SuspendLayout();
  77.             //
  78.             // Rock
  79.             //
  80.             this->Rock->Location = System::Drawing::Point(13, 33);
  81.             this->Rock->Name = L"Rock";
  82.             this->Rock->Size = System::Drawing::Size(75, 23);
  83.             this->Rock->TabIndex = 0;
  84.             this->Rock->Text = L"Rock";
  85.             this->Rock->UseVisualStyleBackColor = true;
  86.             this->Rock->Click += gcnew System::EventHandler(this, &Form1::Rock_Click);
  87.             //
  88.             // Paper
  89.             //
  90.             this->Paper->Location = System::Drawing::Point(94, 33);
  91.             this->Paper->Name = L"Paper";
  92.             this->Paper->Size = System::Drawing::Size(75, 23);
  93.             this->Paper->TabIndex = 0;
  94.             this->Paper->Text = L"Paper";
  95.             this->Paper->UseVisualStyleBackColor = true;
  96.             this->Paper->Click += gcnew System::EventHandler(this, &Form1::Paper_Click);
  97.             //
  98.             // cis
  99.             //
  100.             this->cis->Location = System::Drawing::Point(175, 33);
  101.             this->cis->Name = L"cis";
  102.             this->cis->Size = System::Drawing::Size(75, 23);
  103.             this->cis->TabIndex = 0;
  104.             this->cis->Text = L"Scisors";
  105.             this->cis->UseVisualStyleBackColor = true;
  106.             this->cis->Click += gcnew System::EventHandler(this, &Form1::cis_Click);
  107.             //
  108.             // ComBox
  109.             //
  110.             this->ComBox->Location = System::Drawing::Point(83, 127);
  111.             this->ComBox->Name = L"ComBox";
  112.             this->ComBox->Size = System::Drawing::Size(100, 20);
  113.             this->ComBox->TabIndex = 1;
  114.             //
  115.             // WonBox
  116.             //
  117.             this->WonBox->Location = System::Drawing::Point(83, 190);
  118.             this->WonBox->Name = L"WonBox";
  119.             this->WonBox->Size = System::Drawing::Size(100, 20);
  120.             this->WonBox->TabIndex = 2;
  121.             //
  122.             // CompLabel
  123.             //
  124.             this->CompLabel->AutoSize = true;
  125.             this->CompLabel->Location = System::Drawing::Point(91, 95);
  126.             this->CompLabel->Name = L"CompLabel";
  127.             this->CompLabel->Size = System::Drawing::Size(88, 13);
  128.             this->CompLabel->TabIndex = 3;
  129.             this->CompLabel->Text = L"Computer Choice";
  130.             //
  131.             // WonLabel
  132.             //
  133.             this->WonLabel->AutoSize = true;
  134.             this->WonLabel->Location = System::Drawing::Point(91, 163);
  135.             this->WonLabel->Name = L"WonLabel";
  136.             this->WonLabel->Size = System::Drawing::Size(62, 13);
  137.             this->WonLabel->TabIndex = 3;
  138.             this->WonLabel->Text = L"Who Won\?";
  139.             //
  140.             // Form1
  141.             //
  142.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  143.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  144.             this->ClientSize = System::Drawing::Size(284, 262);
  145.             this->Controls->Add(this->WonLabel);
  146.             this->Controls->Add(this->CompLabel);
  147.             this->Controls->Add(this->WonBox);
  148.             this->Controls->Add(this->ComBox);
  149.             this->Controls->Add(this->cis);
  150.             this->Controls->Add(this->Paper);
  151.             this->Controls->Add(this->Rock);
  152.             this->Name = L"Form1";
  153.             this->Text = L"Form1";
  154.             this->ResumeLayout(false);
  155.             this->PerformLayout();
  156.  
  157.         }
  158. #pragma endregion
  159.     int userChoice, compChoice;
  160. private: System::Void Rock_Click(System::Object^  sender, System::EventArgs^  e) {
  161.              ComBox->Text="";
  162.              userChoice=1;
  163.  
  164.         compChoice=rand()%3+1;
  165.            
  166.             switch(compChoice){
  167.             case 1:
  168.                 ComBox->Text="Rock";
  169.                 WonBox->Text="You Tied";
  170.                 break;
  171.             case 2:
  172.                 ComBox->Text="Paper";
  173.                 WonBox->Text="You Lost";
  174.                 break;
  175.             case 3:
  176.                 ComBox->Text="Scisors";
  177.                 WonBox->Text="You Won";
  178.                 break;
  179.             }
  180.  
  181.          }
  182. private: System::Void Paper_Click(System::Object^  sender, System::EventArgs^  e) {
  183.              ComBox->Text="";
  184.              userChoice=2;
  185.         compChoice=rand()%3+1;
  186.            
  187.             switch(compChoice){
  188.             case 1:
  189.                 ComBox->Text="Rock";
  190.                 WonBox->Text="You Won";
  191.                 break;
  192.             case 2:
  193.                 ComBox->Text="Paper";
  194.                 WonBox->Text="You Tied";
  195.                 break;
  196.             case 3:
  197.                 ComBox->Text="Scisors";
  198.                 WonBox->Text="You Lost!";
  199.                 break;
  200.             }
  201.          }
  202. private: System::Void cis_Click(System::Object^  sender, System::EventArgs^  e) {
  203.              ComBox->Text="";
  204.              userChoice=3;
  205.             compChoice=rand()%3+1;
  206.            
  207.            
  208.             switch(compChoice){
  209.             case 1:
  210.                 ComBox->Text="Rock";
  211.                 WonBox->Text="You Lost";
  212.                 break;
  213.             case 2:
  214.                 ComBox->Text="Paper";
  215.                 WonBox->Text="You Won";
  216.                 break;
  217.             case 3:
  218.                 ComBox->Text="Scisors";
  219.                 WonBox->Text="You Tied!";
  220.                 break;
  221.             }
  222. };
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement