Exemplo n.º 1
0
        public ActionResult Status()
        {
            var board = new Board();
            board.InitialPosition();
            string res;
            var request = new MoveListRequest {Game = int.Parse(Request.Params["gameID"])};
            var response = ServerProvider.MakeRequest<MoveListResponse>(request);
            var request2 = new GameStatRequest {gameID = int.Parse(Request.Params["gameID"])};
            var response2 = ServerProvider.MakeRequest<GameStatResponse>(request2);

            board.ApplyMoves(response.Moves);

            switch (response2.Act)
            {
                case Act.AbandonedByWhite:
                    res = ("Was abandoned by White");
                    break;

                case Act.AbandonedByBlack:
                    res = ("Was abandoned by Black");
                    break;

                case Act.Canceld:
                    res = ("Was canceld");
                    break;

                case Act.WaitingOpponent:
                    res = ("Waiting for 2nd player");
                    break;

                case Act.Pat:
                    res = ("Finished with pat");
                    break;

                case Act.WhiteWon:
                    res = ("Won by White");
                    break;

                case Act.BlackWon:
                    res = ("Won by Black");
                    break;

                case Act.BlackCheck:
                    res = ("Check Black");
                    break;

                case Act.WhiteCheck:
                    res = ("Check White");
                    break;

                case Act.InProgress:
                    res = ("Now in progress");
                    break;

                default:
                    res = ("Unexpected act");
                    break;
            }

            /*   return Json(new {DataBoard = board.ShowBoardToWeb(), DataMove = response.Moves.Select(move =>
            {
                dynamic m = new {From = move.From, To = move.To};
                if (move.Result != MoveResult.SilentMove)
                {
                    m.Result = move.Result;
                }
                return m;
            }),  DataStatus = response2.Act, DataTextStatus = res,
                DataWhitePlayer = response2.PlayerWhite, DataBlackPlayer = response2.PlayerBlack, DataTurn = response2.Turn,
                EatedWhites = response2.EatedWhites, EatedBlacks = response2.EatedBlacks}, JsonRequestBehavior.AllowGet);
            }*/
            return Json(new
            {
                DataBoard = board.ShowBoardToWeb(),
                DataMove = response.Moves.Select(move =>
                {
                    dynamic m = new {
                        From = move.From,
                        To = move.To,
                        DataMovedFigure = move.MovedFigure,
                        InWhom = move.InWhom,
                        Result1 = (move.Result & MoveResult.Taking) == MoveResult.Taking ? "×" : "—",
                        Result2 = (move.Result & MoveResult.Check) == MoveResult.Check ? "+" : ((move.Result & MoveResult.Mate) == MoveResult.Mate ? "#" : ((move.Result & MoveResult.Pat) == MoveResult.Pat) ? "=" : "" ),
                        Result3 = (move.Result & MoveResult.LongCastling) == MoveResult.LongCastling ? "0—0—0" : ((move.Result & MoveResult.ShortCastling) == MoveResult.ShortCastling ? "0—0" : "y")
                    };

                    return m;
                }),
                DataStatus = response2.Act,
                DataTextStatus = res,
                DataWhitePlayer = response2.PlayerWhite,
                DataBlackPlayer = response2.PlayerBlack,
                DataTurn = response2.Turn,
                EatedWhites = response2.EatedWhites,
                EatedBlacks = response2.EatedBlacks
            }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
 public List<Move> GetList()
 {
     var request = new MoveListRequest {Game = CurrentUser.CurrentGame.Value};
     var response = ServerProvider.MakeRequest<MoveListResponse>(request);
     return response.Status == Statuses.Ok ? response.Moves : null;
 }