Beispiel #1
0
 public PlayerViewModel(GoPlayer p, GoColor color)
 {
     _color      = color;
     _name       = p.Name;
     _playerType = p.PlayerType;
     _level      = p.Level;
     _score      = p.Score;
 }
Beispiel #2
0
 public PlayerViewModel(GoPlayer p, GoColor color)
 {
     _color      = color;
     _name       = p.Name;
     _playerType = p.PlayerType;
     _level      = p.Level;
     _komi       = p.Komi;
 }
Beispiel #3
0
        public GoGameState GetGameState(Guid gameId)
        {
            using (var ctx = new GoGEntities())
            {
                var g = ctx.Games.FirstOrDefault(game => game.GameId == gameId);
                if (g == null)
                {
                    return(null);
                }

                var goMoveHistory = new List <GoMoveHistoryItem>();
                foreach (var h in g.Moves.OrderBy(h => h.Sequence))
                {
                    var newHistoryItem = new GoMoveHistoryItem();

                    newHistoryItem.Sequence = h.Sequence;

                    // Translate Move from db.
                    newHistoryItem.Move = new GoMove
                    {
                        Color    = h.IsBlack ? GoColor.Black : GoColor.White,
                        Position = h.Position,
                        MoveType = (MoveType)h.MoveType
                    };

                    // Translate Result from db.
                    newHistoryItem.Result = new GoMoveResult(h.Captured);

                    goMoveHistory.Add(newHistoryItem);
                }

                var p1 = new GoPlayer
                {
                    Level      = g.Player1Level,
                    Name       = g.Player1Name,
                    PlayerType = (PlayerType)g.Player1Type,
                    Score      = g.Player1Score,
                };
                var p2 = new GoPlayer
                {
                    Level      = g.Player2Level,
                    Name       = g.Player2Name,
                    PlayerType = (PlayerType)g.Player2Type,
                    Score      = g.Player2Score
                };
                var rval = new GoGameState(g.Size,
                                           p1, p2,
                                           (GoGameStatus)g.Status,
                                           g.BlacksTurn ? GoColor.Black : GoColor.White,
                                           g.BlackStones, g.WhiteStones,
                                           goMoveHistory,
                                           g.WinMargin);
                return(rval);
            }
        }
        private async void StartNewGame()
        {
            try
            {
                bool success             = false;
                GoGameStateResponse resp = null;

                for (int tries = 0; !AbortOperation && !success && tries < 5; tries++)
                {
                    BusyMessage = "Starting game...";
                    IsBusy      = true;

                    var tmpNewGame = Guid.NewGuid();

                    // Create game from user's selections.
                    var p1 = new GoPlayer();
                    var p2 = new GoPlayer();
                    if (Color == (int)GoColor.Black)
                    {
                        p1.Name       = Name;
                        p1.PlayerType = PlayerType.Human;

                        p2.Name       = "Fuego";
                        p2.PlayerType = PlayerType.AI;
                        p2.Level      = DifficultyLevel;
                    }
                    else
                    {
                        p2.Name       = Name;
                        p2.PlayerType = PlayerType.Human;

                        p1.Name       = "Fuego";
                        p1.PlayerType = PlayerType.AI;
                        p1.Level      = DifficultyLevel;
                    }
                    var tmpState = new GoGameState(
                        tmpNewGame,
                        (byte)BoardEdgeSize,
                        p1, p2,
                        GoGameStatus.Active,
                        GoColor.Black,
                        "",
                        "",
                        new List <GoMoveHistoryItem>(),
                        0);
                    resp = await DataRepository.StartAsync(tmpNewGame, tmpState);

                    BusyMessage = null;
                    IsBusy      = false;

                    ActiveGame = tmpNewGame;
                    success    = true;
                }

                if (AbortOperation)
                {
                    return;
                }

                if (success)
                {
                    NavService.Navigate("Game", ActiveGame);
                }
                else
                {
                    if (resp != null)
                    {
                        await DisplayErrorCode(resp.ResultCode);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                BusyMessage = null;
                IsBusy      = false;
            }
        }