public IMoveResult Convert(SerializedBoard serializedBoard) { if (!(serializedBoard is TBoard)) { throw new NotSupportedException("This converter can not convert this board."); } return(Convert((TBoard)serializedBoard)); }
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); }
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)); }
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.")); }