public void WriteInDB(int numberButton)
        {
            using (GamingPlatformDB_v4Entities writeMove = new GamingPlatformDB_v4Entities())
            {
                List <TicTacMatch> list   = writeMove.TicTacMatches.ToList();
                TicTacMatch        result = new TicTacMatch();
                result = list.Find(item => item.IDTable == position.IDTable);
                try
                {
                    writeMove.SaveChanges();
                }
                catch (DbEntityValidationException d)
                {
                    MessageBox.Show(d.Message);
                }

                char[]        str           = result.FEN.ToCharArray();
                StringBuilder stringBuilder = new StringBuilder(result.FEN);

                if (stringBuilder[0] == 'K')
                {
                    stringBuilder[0]            = 'N';
                    stringBuilder[numberButton] = '1';
                }
                else if (stringBuilder[0] == 'N')
                {
                    stringBuilder[0]            = 'K';
                    stringBuilder[numberButton] = '2';
                }

                result.FEN = stringBuilder.ToString();
                writeMove.SaveChanges();
            }
        }
        public void Play()
        {
            int IDEmptyUser = 6;

            while (true)
            {
                using (GamingPlatformDB_v4Entities d = new GamingPlatformDB_v4Entities())
                {
                    List <TicTacMatch> list   = d.TicTacMatches.ToList();
                    List <Player>      listP  = d.Players.ToList();
                    TicTacMatch        result = new TicTacMatch();
                    Player             player = new Player();
                    player = listP.Find(item => item.IDPlayer == ActiveUser.UserId);
                    if (position.IDTable == 0)
                    {
                        result           = list.Find(item => item.StatusMatch == 0); //0-wait, 1-play 2-
                        position.IDTable = result.IDTable;
                        if (result.Player.IDPlayer == IDEmptyUser)                   //left user
                        {
                            position.yourMove = true;
                            result.Player     = player;
                            position.User1    = result.Player.LoginUser;
                        }
                        else if (result.Player1.IDPlayer == IDEmptyUser)
                        {
                            position.yourMove  = false;
                            position.User2     = result.Player1.LoginUser;
                            result.Player1     = player;
                            result.StatusMatch = 1;
                        }
                    }
                    else
                    {
                        result         = list.Find(item => item.IDTable == position.IDTable);
                        position.FEN   = result.FEN;
                        position.User1 = result.Player.LoginUser;
                        position.User2 = result.Player1.LoginUser;
                        if (position.CheckWinLose() == 1)
                        {
                            MessageBox.Show(position.User1 + " победил");
                            break;
                        }
                        else if (position.CheckWinLose() == 2)
                        {
                            MessageBox.Show(position.User2 + " победил");
                            break;
                        }
                        else if (position.CheckWinLose() == 3)
                        {
                            MessageBox.Show("ничья");
                            break;
                        }
                    }

                    d.SaveChanges();
                }
            }
        }
Esempio n. 3
0
 public void Save()
 {
     db.SaveChanges();
 }