Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(tbfName.Text) &&
                !string.IsNullOrEmpty(tbpas.Text))
            {
                using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                {
                    var acto = from g in ctx.Players
                               where g.UserName.Equals(tbfName.Text.Trim()) && g.Password.Equals(tbpas.Text.Trim())
                               select g.UserName;

                    List <string> uo = acto.ToList();
                    if (!uo.Contains(tbfName.Text.Trim()))
                    {
                        MessageBox.Show("You are not registered yet!",
                                        "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    username = tbfName.Text.Trim();
                }
                ConnectToServer();
                //               (new chooseTypeOfGame(username)).Show();
            }
            else
            {
                MessageBox.Show("You must fill all the fields!", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            reg window = new reg();

            window.ShowDialog();
            if (window.A != null)
            {
                using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                {
                    ctx.Players.Add(window.A);
                    ctx.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(tbfName.Text) &&
                !string.IsNullOrEmpty(tbpas.Text))
            {
                try
                {
                    using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                    {
                        var acto = from g in ctx.Players
                                   select g.UserName;
                        List <string> uo = acto.ToList();
                        if (uo.Contains(tbfName.Text.Trim()))
                        {
                            throw new DoubleException();
                        }
                    }
                    A = new Player
                    {
                        UserName           = tbfName.Text.Trim(),
                        Password           = tbpas.Text.Trim(),
                        Wins               = 0,
                        Losses             = 0,
                        Ties               = 0,
                        Percentage         = 0,
                        Participated_Games = 0
                    };
                }
                catch (DoubleException)
                {
                    MessageBox.Show("item with this name already exists", " ",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                catch (FormatException)
                {
                    MessageBox.Show("מחרוזת קלט לא הייתה בתבנית הנכונה",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                this.Close();
            }

            else
            {
                MessageBox.Show("You must fill all the fields!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     using (sweepers_DBEntities ctx = new sweepers_DBEntities())
     {
         var glob = from m in ctx.rightNowGames
                    orderby m.Time
                    select new
         {
             UserName1 = m.UserName1,
             UserName2 = m.UserName2,
             Time      = m.Time
         };
         nowsgrid.ItemsSource = glob.ToList();
     }
 }
Ejemplo n.º 5
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (sweepers_DBEntities ctx = new sweepers_DBEntities())
     {
         var glob = from m in ctx.Players
                    orderby m.UserName
                    select new
         {
             UserName           = m.UserName,
             Wins               = m.Wins,
             Losses             = m.Losses,
             Ties               = m.Ties,
             Percentage         = m.Percentage.ToString(),
             Participated_Games = m.Participated_Games
         };
         playersgrid.ItemsSource = glob.ToList();
     }
 }
Ejemplo n.º 6
0
 private void Button_Click_3(object sender, RoutedEventArgs e)
 {
     using (sweepers_DBEntities ctx = new sweepers_DBEntities())
     {
         var glob = from m in ctx.Games
                    orderby m.Winner
                    select new
         {
             Date          = m.Date,
             Player_Name1  = m.Player_Name1,
             Player_Name2  = m.Player_Name2,
             Player1_score = m.Player1_score,
             Player2_score = m.Player2_score,
             Winner        = m.Winner
         };
         gamesgrid.ItemsSource = glob.ToList();
     }
 }
Ejemplo n.º 7
0
        private void Play_Click(object sender, EventArgs e)
        {
            if (player_num == 2)
            {
                MessageBox.Show(me + " you must wait for your turn");
                return;
            }

            SetDimensions();
            TableMargins(height, width);
            myTurn = true;

            if (firstPlay)
            {
                CreateButtons(width, height);
                difficulty.Visible = false;
                label5.Visible     = false;
                firstPlay          = false;
            }
            else if (!firstPlay)
            {
                ResetGame(width, height);
            }

            if (player_num == 1)
            {
                B = new rightNowGame
                {
                    UserName1 = me,
                    UserName2 = enemy[0],
                    Time      = DateTime.Now.ToString()
                };
                using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                {
                    ctx.rightNowGames.Add(B);
                    ctx.SaveChanges();
                }
            }
            StartGame();
        }
Ejemplo n.º 8
0
        private void info_click(object sender, RoutedEventArgs e)
        {
            if (lbUsers.SelectedItems.Count != 0)
            {
                string user = lbUsers.SelectedItem.ToString();
                using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                {
                    Player f = (from m in ctx.Players
                                where user.Equals(m.UserName)
                                select m).First();

                    MessageBox.Show(f.UserName + " have a "
                                    + f.Percentage + "% winning, and "
                                    + f.Ties + " ties, in " +
                                    f.Participated_Games + " games that he played");
                }
            }
            else
            {
                MessageBox.Show("You must select users");
            }
        }
Ejemplo n.º 9
0
        private void Update_database()
        {
            if (firstPlay)
            {
                return;
            }

            if (player_num == 1)
            {
                if (gameover)
                {
                    if (iwin)
                    {
                        w = me;
                    }
                    else
                    {
                        w = enemy[0];
                    }

                    if (atie)
                    {
                        w = "a tie";
                    }
                }
                else
                {
                    if (!byeCount) //ראשון שיוצא - מפסיד
                    {
                        w = enemy[0];
                    }
                    if (byeCount) // שני שיוצא - ניצח
                    {
                        w = me;
                    }
                }

                Game C = new Game
                {
                    Date          = DateTime.Now.ToString(),
                    Player_Name1  = me,
                    Player_Name2  = enemy[0],
                    Player1_score = myscore.ToString(),
                    Player2_score = escore.ToString(),
                    Winner        = w
                };

                int winn1 = 0, winn2 = 0, loss1 = 0, loss2 = 0, tiee = 0;
                if (w == me)
                {
                    winn1 = 1;
                    loss2 = 1;
                }
                if (w == enemy[0])
                {
                    winn2 = 1;
                    loss1 = 1;
                }
                if (w == "a tie")
                {
                    tiee = 1;
                }

                using (sweepers_DBEntities ctx = new sweepers_DBEntities())
                {
                    ctx.Games.Add(C);
                    ctx.SaveChanges();

                    rightNowGame ss = null;
                    ss = (from s in ctx.rightNowGames
                          where s.nowId == B.nowId
                          select s).First();
                    if (ss != null)
                    {
                        ctx.rightNowGames.Remove(ss);
                        ctx.Entry(ss).State = System.Data.Entity.EntityState.Deleted;
                        ctx.SaveChanges();
                    }

                    Player ses = (from s in ctx.Players
                                  where me.Equals(s.UserName)
                                  select s).First();

                    Player A = new Player
                    {
                        UserName           = ses.UserName,
                        Password           = ses.Password,
                        Wins               = ses.Wins + winn1,
                        Losses             = ses.Losses + loss1,
                        Ties               = ses.Ties + tiee,
                        Participated_Games = ses.Participated_Games + 1,
                        Percentage         = (((double)ses.Wins + (double)winn1) / (ses.Participated_Games + 1)) * 100
                    };
                    //A.Percentage *= 100;

                    ctx.Players.Add(A);
                    ctx.Players.Remove(ses);
                    ctx.Entry(ses).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();

                    String y    = enemy[0];
                    Player ses2 = (from s in ctx.Players
                                   where y.Equals(s.UserName)
                                   select s).First();

                    Player A2 = new Player
                    {
                        UserName           = ses2.UserName,
                        Password           = ses2.Password,
                        Wins               = ses2.Wins + winn2,
                        Losses             = ses2.Losses + loss2,
                        Ties               = ses2.Ties + tiee,
                        Participated_Games = ses2.Participated_Games + 1,
                        Percentage         = ((double)(ses2.Wins + winn2) / (ses2.Participated_Games + 1)) * 100
                    };
                    ctx.Players.Add(A2);
                    ctx.Players.Remove(ses2);
                    ctx.Entry(ses2).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }
            }
        }