//GET: Games/Index public async Task <IActionResult> Index() { // Get Current Time in Eastern Time var timeUtc = DateTime.UtcNow; TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone); // Get Current User var user = await GetCurrentUserAsync(); // Get today's games that have not started var TodaysUpcomingGames = _context.Games .Include(g => g.AwayTeam) .Include(g => g.HomeTeam) .Include(g => g.UserGames) .ThenInclude(ug => ug.User) .Where(g => g.FirstPitchDateTime > easternTime) .OrderBy(g => g.FirstPitchDateTime) .ThenBy(g => g.HomeTeam.TeamId) .ToList() ; // Make list to hold Available Game models List <AvailableGame> AvailableGameModels = new List <AvailableGame>(); // Convet list of games into list of AvailableGames to send to model TodaysUpcomingGames.ForEach(game => { //Check to see if there is a usergame associated with this user and game var userGame = game.UserGames.Where(ug => ug.User.Id == user.Id).FirstOrDefault(); // set defaults to 0 assuming there is no UserGame for this user/game var isChecked = 0; int userGameId = 0; int teamId = 0; if (userGame != null) { // change to true if a UserGame exists for this game and user isChecked = 1; userGameId = userGame.UserGameId; teamId = userGame.ChosenTeamId; } // Crate AvailableGame for each game AvailableGame newAvailableGameModel = new AvailableGame() { Game = game, GameId = game.GameId, UserGame = userGame, UserGameId = userGameId, TeamId = teamId, IsChecked = isChecked }; AvailableGameModels.Add(newAvailableGameModel); }); return(View(AvailableGameModels)); }
public GameChangedEventArgs(AvailableGame game, GameModification gameModification) { Game = game ?? throw new ArgumentNullException(nameof(game)); if (gameModification == GameModification.Undefined) { throw new ArgumentOutOfRangeException(nameof(gameModification)); } GameModification = gameModification; }
void JoinGame(AvailableGame joinedGame) { foreach (AvailableGame game in games) { if (game.id == joinedGame.id) { Debug.Log("Joining " + game.name + " :: " + game.id); PlayerSingleton.Instance.gameToJoin = game; //hack!! WEEE!!! clients need the name too you know? PlayerSingleton.Instance.nameOfGame = game.name; break; } } SceneManager.LoadScene("Lobby"); }
/** * Method: createGameObjects * Purpose: Create Individual Game objects for the user to see in the lobby * Parameters: updList -> List of games in lobby * Return Val: N/A * */ private void createGameObjects(List <ServerUpdate> updList) { //print(updList.Capacity); for (int i = 0; i < updList.Count; i++) { if (updList[i].status == "LOBBY") //Loops through list, creating a GameObject for each game in lobby { GameObject game = (GameObject)Instantiate(Resources.Load("AvailableGame")); gamesDict.Add(updList[i].users[0], game); game.transform.SetParent(gamesPanel.transform, false); AvailableGame aGame = game.GetComponent <AvailableGame>(); aGame.setGameIDText(updList[i].id); aGame.setHostNameText(updList[i].host_name); } } }
void Start() { if (PlayerSingleton.Instance.isHost) { NetworkManager.singleton.networkPort = 27017; NetworkManager.singleton.StartHost(); } else { AvailableGame game = PlayerSingleton.Instance.gameToJoin; NetworkManager.singleton.networkAddress = game.ip; NetworkManager.singleton.networkPort = 27017; // NetworkManager.singleton.ud // NetworkManager.singleton.networkAddress = "192.168.1.47"; NetworkManager.singleton.StartClient(); } }
//GET: Games/MyPicks public async Task <IActionResult> MyPicks() { // Get Yesterday var yesterday = DateTime.Today.AddDays(-1); // Get Current User var user = await GetCurrentUserAsync(); // Get games user picked yesterday and today var UsersPickedGames = _context.UserGames .Where(ug => ug.UserId == user.Id) .Include(ug => ug.User) .Include(ug => ug.Game).ThenInclude(g => g.AwayTeam) .Include(ug => ug.Game).ThenInclude(g => g.HomeTeam) .Where(ug => ug.Game.FirstPitchDateTime > yesterday) .OrderByDescending(ug => ug.Game.FirstPitchDateTime.DayOfYear) .ThenBy(ug => ug.Game.FirstPitchDateTime.TimeOfDay) .ThenBy(ug => ug.Game.HomeTeam.TeamId) .ToList(); // Make list to hold Available Game models List <AvailableGame> AvailableGameModels = new List <AvailableGame>(); // Convet list of usergames into list of AvailableGames to send to model UsersPickedGames.ForEach(usergame => { // Crate AvailableGame for each game AvailableGame newAvailableGameModel = new AvailableGame() { Game = usergame.Game, GameId = usergame.Game.GameId, UserGame = usergame, UserGameId = usergame.UserGameId, TeamId = usergame.ChosenTeamId, IsChecked = 1 }; AvailableGameModels.Add(newAvailableGameModel); }); return(View(AvailableGameModels)); }
IEnumerator WaitForRequest(WWW www) { yield return(www); AvailableGame result = JsonUtility.FromJson <AvailableGame>(www.text); PlayerSingleton.Instance.isHost = true; StopAllCoroutines(); if (www.error == null && !www.text.Equals("")) { Debug.Log("SUCCESS!!!"); PlayerSingleton.Instance.idOfGame = result.id; SceneManager.LoadScene("Lobby"); } else { Debug.Log("FAILED!!!"); Debug.Log(www.error); } }
void AddListener(Button b, AvailableGame game) { b.onClick.AddListener(() => JoinGame(game)); }