SHARE
TWEET

Untitled

a guest Jun 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Android.App;
  2. using Android.OS;
  3. using Android.Support.V7.App;
  4. using Android.Widget;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8.  
  9. namespace App2
  10. {
  11.     [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
  12.     public class MainActivity : AppCompatActivity
  13.     {
  14.         private ImageView Image1 { get; set; }
  15.         private ImageView Image2 { get; set; }
  16.         private ImageView Image3 { get; set; }
  17.  
  18.         private ImageView ImageMain { get; set; }
  19.  
  20.         private TextView Player { get; set; }
  21.         private TextView Phone { get; set; }
  22.  
  23.         private Button Start { get; set; }
  24.  
  25.         private int PlayerOrder { get; set; }
  26.         private int PhoneOrder { get; set; }
  27.  
  28.  
  29.         private Dictionary<int, int> ImagesAndOrders { get; set; }
  30.  
  31.         private Dictionary<int, int> Images { get; set; }
  32.  
  33.         public MainActivity()
  34.         {
  35.             Image1 = null;
  36.             Image2 = null;
  37.             Image3 = null;
  38.             ImageMain = null;
  39.  
  40.             Player = null;
  41.             Phone = null;
  42.  
  43.             Start = null;
  44.  
  45.             PlayerOrder = 0;
  46.             PhoneOrder = 0;
  47.         }
  48.  
  49.         protected override void OnCreate(Bundle savedInstanceState)
  50.         {
  51.             base.OnCreate(savedInstanceState);
  52.             SetContentView(Resource.Layout.activity_main);
  53.  
  54.             ImageMain = FindViewById<ImageView>(Resource.Id.MainImg);
  55.             Image1 = FindViewById<ImageView>(Resource.Id.Img1);
  56.             Image2 = FindViewById<ImageView>(Resource.Id.Img2);
  57.             Image3 = FindViewById<ImageView>(Resource.Id.Img3);
  58.  
  59.             Player = FindViewById<TextView>(Resource.Id.PlayerNum);
  60.             Phone = FindViewById<TextView>(Resource.Id.PhoneNum);
  61.  
  62.             Start = FindViewById<Button>(Resource.Id.Start);
  63.             Start.Enabled = false;
  64.  
  65.             ImagesAndOrders = new Dictionary<int, int>
  66.             {
  67.                 { Resource.Drawable.img2, Resource.Drawable.img3 },
  68.                 { Resource.Drawable.img1, Resource.Drawable.img2 },
  69.                 { Resource.Drawable.img3, Resource.Drawable.img1 }
  70.             };
  71.  
  72.             Images = new Dictionary<int, int>
  73.             {
  74.                 {Image1.Id, Resource.Drawable.img1},
  75.                 {Image2.Id, Resource.Drawable.img2},
  76.                 {Image3.Id, Resource.Drawable.img3},
  77.             };
  78.  
  79.             Image1.Click += ColorAndORder;
  80.             Image2.Click += ColorAndORder;
  81.             Image3.Click += ColorAndORder;
  82.  
  83.             Image1.SetImageResource(Resource.Drawable.img1);
  84.             Image2.SetImageResource(Resource.Drawable.img2);
  85.             Image3.SetImageResource(Resource.Drawable.img3);
  86.  
  87.             Start.Click += GoPlay;
  88.         }
  89.  
  90.         public void ColorAndORder(object s, EventArgs e)
  91.         {
  92.             var img = (s as ImageView);
  93.  
  94.             ChoiceImagePlayer(!Image1.Enabled);
  95.  
  96.             PlayerOrder = Images.FirstOrDefault(o => o.Key == img.Id).Value;
  97.  
  98.             img.Background = Resources.GetDrawable(Resource.Drawable.BorderColor);
  99.         }
  100.  
  101.         public void ChoiceImagePlayer(bool tof)
  102.         {
  103.             Image1.Enabled = tof;
  104.             Image2.Enabled = tof;
  105.             Image3.Enabled = tof;
  106.  
  107.             Start.Enabled = !tof;
  108.         }
  109.  
  110.         public int PhoneOrderRand() =>
  111.             new Random().Next(0, 3);
  112.  
  113.         public void Clear()
  114.         {
  115.             ChoiceImagePlayer(!Image1.Enabled);
  116.  
  117.             Image1.Background = null;
  118.             Image2.Background = null;
  119.             Image3.Background = null;
  120.             Start.Enabled = false;
  121.             ImageMain.SetImageResource(Resource.Drawable.abc_list_pressed_holo_dark);
  122.             Start.Text = "NEXT";
  123.  
  124.             PlayerOrder = 0;
  125.             PhoneOrder = 0;
  126.         }
  127.  
  128.         public void GoPlay(object s, EventArgs e)
  129.         {
  130.             if(Start.Text == "->")
  131.             {
  132.                 Start.Enabled = false;
  133.                 Clear();
  134.                 return;
  135.             }
  136.  
  137.             do//ro ar daemtxves
  138.             {
  139.                 PhoneOrder = ImagesAndOrders.ElementAt(PhoneOrderRand()).Value;
  140.  
  141.                 if (PhoneOrder != PlayerOrder)
  142.                     break;
  143.  
  144.             } while (true);
  145.  
  146.             ImageMain.SetImageResource(PhoneOrder);
  147.  
  148.             //maigo an ara
  149.             if (ImagesAndOrders.Any(o => o.Key == PlayerOrder && o.Value == PhoneOrder))
  150.             {
  151.                 int.TryParse(Player.Text, out int player);
  152.                 Player.Text = $"{++player}";
  153.             }
  154.             else
  155.             {
  156.                 int.TryParse(Phone.Text, out int phone);
  157.                 Phone.Text = $"{++phone}";
  158.             }
  159.  
  160.             Start.Text = "->";
  161.         }
  162.     }
  163. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top