示例#1
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();
        }
示例#2
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();
                }
            }
        }