示例#1
0
        public bool Equals(SteamGame other)
        {
            if(other == null)
            {
                return false;
            }

            return this.AppID == other.AppID;
        }
        private bool NewGame(bool isInitialCall)
        {
            currGameIndex = Utilities.rng.Next(steam.User.Games.Count);
            currGame = steam.User.Games.ElementAt(currGameIndex);

            currGame.Name = SteamAPI.GetAppNameFromId(currGame.AppID);

            if (currGame.Name == "App no longer supported") //Some "games" are alphas or betas that no longer work 
            { 
                NewGame(false);
            }

            //string message = isInitialCall ? "How about this game?" : "No?  What about this?";
            //DisplayInfoOrError(message, 2250);

            tbGameName.Text = currGame.Name;
            labelGameTime.Content = String.Format("You have {0} hours in this game.", (currGame.HoursPlayed / 60.0f).ToString("0.0")); //Steam's API returns time played in mins.  This converts to hours

            gameSelector.Background = new ImageBrush(new BitmapImage(new Uri(String.Format("http://cdn.akamai.steamstatic.com/steam/apps/{0}/page_bg_generated_v6b.jpg", currGame.AppID))));
            gameImage.Source = new BitmapImage(new Uri(String.Format("http://cdn.akamai.steamstatic.com/steam/apps/{0}/header_292x136.jpg", currGame.AppID)));
            

            return true;

        }
        private void NewGame()
        {
            int randomIndex = Properties.Settings.Default.InstalledOnly ?
                    Utilities.rng.Next(Properties.Settings.Default.InstalledGames.Count) :
                    Utilities.rng.Next(steam.User.Games.Count);

            //TODO: clean this up. it's pretty messy

            //If we are only selecting from the pool of installed games, our current game is a random object from the list of installed games.
            //At this point, we do not have the playtime of that game within this object, but we do have it in the list of all owned games.
            //we find the same object from the list of all owned games using .Find and set that object as the current game.  This way we have the playtime
            //if we are selecting from the pool of all games, our current game is a random index from the list of all games.     
            //Reasoning: O(n) on a list with an expected size of around ~100 is better than an API call to get the time played.
            currentGame = Properties.Settings.Default.InstalledOnly ?
                    steam.User.Games.Find(Properties.Settings.Default.InstalledGames[randomIndex].Equals) :
                    steam.User.Games[randomIndex];

            //.Find returned null which means the user has an installed game which they do not own, do not show them this game
            if (currentGame == null)
            {
                NewGame();
            }

            currentGame.Name = SteamAPI.GetAppNameFromId(currentGame.AppID);

            if (currentGame.Equals(previousGame) || currentGame.Name == "App no longer supported") //Some "games" are alphas or betas that no longer work
            {
                NewGame();
            }


            tbGameName.Text = currentGame.Name;
            labelGameTime.Content = String.Format("You have {0} hours in this game.", (currentGame.MinutesPlayed / 60.0f).ToString("0.0")); //Steam's API returns time played in mins.  This converts to hours

            gameSelector.Background = new ImageBrush(new BitmapImage(new Uri(String.Format("http://cdn.akamai.steamstatic.com/steam/apps/{0}/page_bg_generated_v6b.jpg", currentGame.AppID))));
            gameImage.Source = new BitmapImage(new Uri(String.Format("http://cdn.akamai.steamstatic.com/steam/apps/{0}/header_292x136.jpg", currentGame.AppID)));

            if (Properties.Settings.Default.InstalledOnly) //we know they have this game installed
            {
                SetButtonLaunchOrDownloadImage("resources/images/launch_64x64.png");
                buttonLaunchOrDownload.ToolTip = "Launch the game";
            }
            else //We need to find out if they have this game installed to show them the correct image.
            {
                if (Properties.Settings.Default.InstalledGames.Contains(currentGame))
                {
                    SetButtonLaunchOrDownloadImage("resources/images/launch_64x64.png");
                    buttonLaunchOrDownload.ToolTip = "Launch the game";
                }
                else
                {
                    SetButtonLaunchOrDownloadImage("resources/images/download_64x64.png");
                    buttonLaunchOrDownload.ToolTip = "Download the game";
                }
            }

            previousGame = currentGame;
        }