Ejemplo n.º 1
0
        public IMoveResult Convert(SerializedBoard serializedBoard)
        {
            if (!(serializedBoard is TBoard))
            {
                throw new NotSupportedException("This converter can not convert this board.");
            }

            return(Convert((TBoard)serializedBoard));
        }
Ejemplo n.º 2
0
    private void Serialize()
    {
        var board = new SerializedBoard();

        board.Fields = Fields.ToList();
        var field      = new Field(1, 1, true);
        var fieldsJson = JsonUtility.ToJson(board);
        //var utcNowTicks = DateTime.UtcNow.Ticks;
        var fileName = InputField.text;

        File.WriteAllText("Assets/Resources/" + fileName + ".json", fieldsJson);
    }
Ejemplo n.º 3
0
        private async Task <Dictionary <string, MatchStatus> > CreateMatchWithBoardAsync(IEnumerable <string> players, SerializedBoard board, bool isQuickMatch)
        {
            var users = await context.Users.Where(u => players.Any(p => p == u.UserName))
                        .ToListAsync();

            var match = new Match
            {
                Board = board,
                CurrentPlayerIndex = 0,
                IsQuickMatch       = isQuickMatch,
                CreateTime         = DateTime.UtcNow,
                LastMove           = DateTime.UtcNow
            };

            match.Users = Enumerable.Range(0, users.Count)
                          .Select(x => new UserMatch {
                User = users[x], Match = match, PlayerIndex = x
            })
                          .ToList();

            context.Matches.Add(match);
            context.Boards.Add(board);
            await context.SaveChangesAsync();

            return(match.Users.Select(um => new { Player = um.User.UserName, Status = matchConverter.ConvertFor(match, um.User.UserName) })
                   .ToDictionary(x => x.Player, x => x.Status));
        }
Ejemplo n.º 4
0
 public IBoardConverter FindBoardConverter(SerializedBoard serializedBoard)
 {
     return(boardConverters.FirstOrDefault(x => x.GetType().BaseType?.GetGenericArguments().First() == serializedBoard.GetType())
            ?? throw new GameNotSupportedException("Could not find board converter for this game type."));
 }