Ejemplo n.º 1
0
        public Games MakeMove(int id, string move)
        {
            Games game = GetGame(id);

            if (game == null)
            {
                return(game);
            }

            if (game.Statuse != "play")
            {
                return(game);
            }

            Chess.Chess chess = new Chess.Chess(game.FEN);

            var chessNext = chess.Move(move);

            if (chessNext.fen == game.FEN)
            {
                return(game);
            }

            game.FEN = chessNext.fen;
            if (chessNext.IsCheckAndMate())
            {
                game.Statuse = "done";
            }

            db.Entry(game).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(game);
        }
Ejemplo n.º 2
0
        GameInfo JoinGame(Game game, RequestedGame r)
        {
            if (r.playerColor == "white")
            {
                game.White_ID = r.playerID;
            }

            if (r.playerColor == "black")
            {
                game.Black_ID = r.playerID;
            }
            game.Status = "play";

            db.Entry(game).State = System.Data.Entity.EntityState.Modified;// we commit updates to database
            db.SaveChanges();

            GameInfo gameInfo = new GameInfo();

            gameInfo.gameID = game.ID;
            gameInfo.FEN    = game.FEN;
            return(gameInfo);
        }
Ejemplo n.º 3
0
        public Games ConnectToGame(string name, string name2)
        {
            Users u1            = db.Users.Where(g => g.Name == name).FirstOrDefault();
            Users u2            = db.Users.Where(g => g.Name == name2).FirstOrDefault();
            Games userGameWhite = u2.Games.Where(g => g.Statuse == "wait").FirstOrDefault();
            var   ourGames      = u1.Games.Where(g => g.Statuse == "wait" || g.Statuse == "play" || g.Statuse == "offerDraw").ToList();
            var   ourGames1     = u1.Games1.Where(g => g.Statuse == "wait" || g.Statuse == "play" || g.Statuse == "offerDraw").ToList();

            if (ourGames.Count != 0 || ourGames1.Count != 0)
            {
                throw new WebException("Ты уже играешь");
            }
            if (userGameWhite != null)
            {
                userGameWhite.Black           = u1.id;
                userGameWhite.Statuse         = "play";
                db.Entry(userGameWhite).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(userGameWhite);
            }
            return(null);
        }