コード例 #1
0
        public GuestGame(String ipa)
        {
            InitializeComponent();
            ip = ipa;
            Joueur j1 = Gestion.getInstance().Joueur1;
            Joueur j2 = Gestion.getInstance().Joueur2;

            joueur1 = j1.Nom;
            Score1  = j1.Score;
            // joueur2 = j2.Nom;
            Score2   = 0;
            tour     = false;
            Plateau1 = new ObservableCollection <HoleControl>();
            Plateau2 = new ObservableCollection <HoleControl>();
            for (int i = 6; i > 0; i--)
            {
                Plateau1.Add(new HoleControl());
                Plateau2.Add(new HoleControl());
            }
            path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Score.txt");
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@path, true))
            {
                file.WriteLine(DateTime.Now.ToString("MM/dd/yyyy h:mm tt"));
            }
            UdpClient  listener = new UdpClient(1500);
            IPAddress  target   = IPAddress.Parse(ip);
            IPEndPoint ep       = new IPEndPoint(target, 1500);

            Task.Run(() => {
                try
                {
                    while (tour == false)
                    {
                        byte[] bytes = listener.Receive(ref ep);

                        Dispatcher.Invoke(() =>
                        {
                            tour = true;

                            String attack = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                            int a;
                            Int32.TryParse(attack, out a);
                            int total2 = Plateau1[a].NbrBilles;
                            Plateau1[a].Jouer();
                            Console.WriteLine(Plateau1[a].NbrBilles);
                            int b = 6;
                            for (int k = total2; k > 0; k--)
                            {
                                a = a + 1;
                                if (a < 6)
                                {
                                    Plateau1[a].Distribuer();
                                }
                                else
                                {
                                    b = b - 1;
                                    if (b < 6 && b > -1)
                                    {
                                        Plateau2[b].Distribuer();
                                        if (Plateau2[b].NbrBilles == 2)
                                        {
                                            Plateau2[b].NbrBilles = 0;
                                            this.Score1           = this.Score1 + 2;
                                        }
                                        else if (Plateau2[b].NbrBilles == 3)
                                        {
                                            Plateau2[b].NbrBilles = 0;
                                            this.Score1           = this.Score1 + 3;
                                        }
                                    }
                                    else
                                    {
                                        a = 0;
                                        b = 6;
                                    }
                                }
                            }
                        });
                    }
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1.ToString());
                }
                finally
                {
                    listener.Close();
                }
            });

            this.DataContext = this;
        }
コード例 #2
0
ファイル: Acceuil.xaml.cs プロジェクト: rihabbh/Projet-c-MBDS
 public Acceuil()
 {
     InitializeComponent();
     joueur           = Gestion.getInstance().Joueur1;
     this.DataContext = joueur;
 }