// function to fill a user's team public List <GeneralPlayer> FillTeam(NFLv3StatsClient client) { List <GeneralPlayer> playersTeam = new List <GeneralPlayer>(); GeneralPlayer player = new GeneralPlayer(); // going to set a default team to size 7: 1 QB 2 RB 2 WR 1 TE 1 K not including ST/Def for (var i = 0; i < 7; i++) { do { player = new GeneralPlayer(); // Resets player fields so they do not repeat if null ie found some null bye weeks player.name = GetPlayersName(); GetPlayerInfo(player, client); if (player.playerID == 0) { Console.WriteLine("It appears that player does not exist or their name is spelled incorrectly."); Console.WriteLine("Please try again."); } } while (player.playerID == 0); // if a playerID is not 0 then a player with that name exists if (player.position == "QB") { playersTeam.Add(new Quarterback(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek)); } if (player.position == "RB" || player.position == "WR" || player.position == "TE") { playersTeam.Add(new WRRBTE(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek)); } if (player.position == "K") { playersTeam.Add(new Kicker(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek)); } } return(playersTeam); }
// function to get the playerID public void GetPlayerInfo(GeneralPlayer f, NFLv3StatsClient client) { // utilizes the SDK's class to pull data. could not come up with another way Predicate <Player> playerFinder = (Player p) => { return(p.Name == f.name); }; var tmpPlayer = client.GetPlayers().Find(playerFinder); if (tmpPlayer != null) { f.playerID = tmpPlayer.PlayerID; f.team = tmpPlayer.Team; f.position = tmpPlayer.Position; f.number = (int)tmpPlayer.Number; if (tmpPlayer.ByeWeek != null) { f.byeWeek = (int)tmpPlayer.ByeWeek; } } else { Console.WriteLine("Error!"); } }
static void Main(string[] args) { // Connect to client and get data // Please grab your own free apikey SportsData.io NFLv3StatsClient client = new NFLv3StatsClient("apikey"); //var projections = client.GetTeamGameStats("2018", 7).OrderByDescending(p => p.PasserRating).Take(20).ToList(); var week = 0; bool onBye = false; string teamName = ""; GeneralPlayer play = new GeneralPlayer(); List <GeneralPlayer> teamList = new List <GeneralPlayer>(); var userChoice = 1; while (userChoice != 6) { userChoice = Menu.DisplayMenu(); switch (userChoice) { case 1: Console.WriteLine("Create Team"); var team = new List <GeneralPlayer>(); team = play.FillTeam(client); teamList = team; break; case 2: if (teamList.Count() == 0) { Console.WriteLine("Please create or access a saved team first!\n"); break; } Database.SaveTeam(teamList); Console.WriteLine("Team Saved\n"); break; case 3: if (teamList.Count() == 0) { Console.WriteLine("Please create or access a saved team first!\n"); break; } week = play.GetStatWeek(); onBye = play.CheckByes(teamList, week); if (onBye) { break; } // exits this case because a new team needs to be selected play.GetStats(teamList, client, week); play.PrintStats(teamList); break; case 4: teamName = Database.ListTeams(); teamList = Database.GetSavedTeam(teamName); break; case 5: if (teamList.Count() == 0) { Console.WriteLine("Please create or access a saved team first!\n"); break; } var ppr = FantasyPoints.GetPPR(); FantasyPoints.CalcFantasyPoints(teamList, ppr); FantasyPoints.PrintFantasyPoints(teamList); break; } } }