Advertisement
DrAungWinHtut

Three Card Game with Random CSharp

Feb 16th, 2022
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace _2022021601_CS_3CardGame_Random
  12. {
  13.     public partial class frmThreeCard : Form
  14.     {
  15.         public frmThreeCard()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void frmThreeCard_Load(object sender, EventArgs e)
  21.         {
  22.             this.Text = "Three Card Game";
  23.             pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  24.             pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  25.             pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  26.  
  27.             pic1.SizeMode = PictureBoxSizeMode.StretchImage;
  28.             pic2.SizeMode = PictureBoxSizeMode.StretchImage;
  29.             pic3.SizeMode = PictureBoxSizeMode.StretchImage;
  30.  
  31.             txtBaydin.Enabled = false;
  32.             txtBaydin.SelectionAlignment = HorizontalAlignment.Center;
  33.         }
  34.  
  35.         private void pic1_Click(object sender, EventArgs e)
  36.         {
  37.             //  1. Random number 1 - 3 generate
  38.             Random rnd = new Random();
  39.             int iCard = rnd.Next(1, 4);
  40.  
  41.             //  2. ကျလာတဲ့ တန်ဖိုးပေါ် မူတည်ပြီး သက်ဆိုင်ရာ ပုံပြမယ်
  42.             //      ဥပမာ 1-King   2-Queen  3-Fool
  43.             if(iCard == 1)
  44.             {
  45.                 pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\king.png");
  46.                 txtBaydin.Text = "ဘုရင်ဖြစ်ကိန်းရှိသည်";
  47.             }
  48.             if (iCard == 2)
  49.             {
  50.                 pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\queen.jpg");
  51.                 txtBaydin.Text = "မဆိုးပါဘူး";
  52.             }
  53.             if (iCard == 3)
  54.             {
  55.                 pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\fool.jpg");
  56.                 txtBaydin.Text = "သင် ကံဆိုးနေသည်";
  57.             }
  58.  
  59.             // 3. အခြားဖဲချပ်တွေကို (pic2 and 3) မှောက်ခိုင်းထားမယ်
  60.             pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  61.             pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  62.  
  63.  
  64.             // 4. Disable လုပ်မယ်
  65.             pic1.Enabled = false;
  66.             pic2.Enabled = false;
  67.             pic3.Enabled = false;
  68.  
  69.  
  70.         }
  71.  
  72.         private void pic2_Click(object sender, EventArgs e)
  73.         {
  74.             //  1. Random number 1 - 3 generate
  75.             Random rnd = new Random();
  76.             int iCard = rnd.Next(1, 4);
  77.  
  78.             //  2. ကျလာတဲ့ တန်ဖိုးပေါ် မူတည်ပြီး သက်ဆိုင်ရာ ပုံပြမယ်
  79.             //      ဥပမာ 1-King   2-Queen  3-Fool
  80.             if (iCard == 1)
  81.             {
  82.                 pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\king.png");
  83.                 txtBaydin.Text = "ဘုရင်ဖြစ်ကိန်းရှိသည်";
  84.             }
  85.             if (iCard == 2)
  86.             {
  87.                 pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\queen.jpg");
  88.                 txtBaydin.Text = "မဆိုးပါဘူး";
  89.             }
  90.             if (iCard == 3)
  91.             {
  92.                 pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\fool.jpg");
  93.                 txtBaydin.Text = "သင် ကံဆိုးနေသည်";
  94.             }
  95.  
  96.             // 3. အခြားဖဲချပ်တွေကို (pic2 and 3) မှောက်ခိုင်းထားမယ်
  97.             pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  98.             pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  99.  
  100.  
  101.             // 4. Disable လုပ်မယ်
  102.             pic1.Enabled = false;
  103.             pic2.Enabled = false;
  104.             pic3.Enabled = false;
  105.  
  106.  
  107.         }
  108.  
  109.         private void pic3_Click(object sender, EventArgs e)
  110.         {
  111.             //  1. Random number 1 - 3 generate
  112.             Random rnd = new Random();
  113.             int iCard = rnd.Next(1, 4);
  114.  
  115.             //  2. ကျလာတဲ့ တန်ဖိုးပေါ် မူတည်ပြီး သက်ဆိုင်ရာ ပုံပြမယ်
  116.             //      ဥပမာ 1-King   2-Queen  3-Fool
  117.             if (iCard == 1)
  118.             {
  119.                 pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\king.png");
  120.                 txtBaydin.Text = "ဘုရင်ဖြစ်ကိန်းရှိသည်";
  121.             }
  122.             if (iCard == 2)
  123.             {
  124.                 pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\queen.jpg");
  125.                 txtBaydin.Text = "မဆိုးပါဘူး";
  126.             }
  127.             if (iCard == 3)
  128.             {
  129.                 pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\fool.jpg");
  130.                 txtBaydin.Text = "သင် ကံဆိုးနေသည်";
  131.             }
  132.  
  133.             // 3. အခြားဖဲချပ်တွေကို (pic2 and 3) မှောက်ခိုင်းထားမယ်
  134.             pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  135.             pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  136.  
  137.  
  138.             // 4. Disable လုပ်မယ်
  139.             pic1.Enabled = false;
  140.             pic2.Enabled = false;
  141.             pic3.Enabled = false;
  142.  
  143.  
  144.         }
  145.  
  146.         private void btnReset_Click(object sender, EventArgs e)
  147.         {
  148.             pic1.Enabled = true;
  149.             pic2.Enabled = true;
  150.             pic3.Enabled = true;
  151.             pic1.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  152.             pic2.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  153.             pic3.Image = Image.FromFile("D:\\CStutorial\\baydin\\back.png");
  154.             txtBaydin.Clear();
  155.         }
  156.     }
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement