コード例 #1
0
    private void PlayBtn_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            if (GameInfo.IsSteam && !Global.CanLaunchSteamGame())
            {
                return;                 // If the user can't launch the game, stop
            }

            if (!GameInfo.IsUWP && !GameInfo.IsSteam)             // If EXE/Win32 game
            {
                Process p = new();
                p.StartInfo.WorkingDirectory = Path.GetDirectoryName(GameInfo.FileLocation);
                p.StartInfo.FileName         = GameInfo.FileLocation;
                p.Start();
            }
            else
            {
                Process.Start("explorer.exe", GameInfo.FileLocation);                 // Start the game
            }

            GameInfo.LastTimePlayed = Env.GetUnixTime();                                                     // Set the last time played
            Definitions.Games[Definitions.Games.IndexOf(GameInfo)].LastTimePlayed = GameInfo.LastTimePlayed; // Update the games
            GameSaver.Save(Definitions.Games);                                                               // Save the changes

            Timer.Start();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
コード例 #2
0
    private void Button_Click(object sender, RoutedEventArgs e)     // Play button
    {
        if (!GameInfo.IsUWP && !GameInfo.IsSteam)
        {
            if (File.Exists(location))             // If the file exist
            {
                Process p = new();
                p.StartInfo.WorkingDirectory = Path.GetDirectoryName(location);
                p.StartInfo.FileName         = location;
                p.Start();
                GameInfo.LastTimePlayed = Env.GetUnixTime(); // Set the last time played

                Timer.Start();                               // Start the timer

                Definitions.RecentGamesPage.LoadGames();     // Reload the games
                GameSaver.Save(Definitions.Games);           // Save the changes
            }
        }
        else
        {
            if (GameInfo.IsSteam && !Global.CanLaunchSteamGame())
            {
                return;                 // If the user can't launch the game, stop
            }

            Process.Start("explorer.exe", location);     // Start the game
            GameInfo.LastTimePlayed = Env.GetUnixTime(); // Set the last time played

            Timer.Start();                               // Start the timer

            Definitions.RecentGamesPage.LoadGames();     // Reload the games
            GameSaver.Save(Definitions.Games);           // Save the changes
        }
    }
コード例 #3
0
    // Save the game
    public void SaveButtonOnClick()
    {
        _currentCoolDown = _saveCoolDown;
        GameSaver gs = GameObjectFinder.FindGameSaver();

        gs.Save();
    }
コード例 #4
0
    private async void GamePresenter_Drop(object sender, DragEventArgs e)
    {
        try
        {
            if (Definitions.Games.Count <= 0)
            {
                Global.RemoveWelcomeScreen();                 // Remove the "Welcome" screen
            }

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[]      files       = (string[])e.Data.GetData(DataFormats.FileDrop); // Get all the files droped
                List <string> executables = new();                                          // The execuables files

                for (int i = 0; i < files.Length; i++)                                      // For each file
                {
                    if (System.IO.Path.GetExtension(files[i]) == ".exe")                    // If the file is a .exe
                    {
                        executables.Add(files[i]);                                          // Add the file to the executables
                    }
                }

                for (int i = 0; i < executables.Count; i++)                 // For each executables (or games)
                {
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(executables[i]);
                    int             id = await Global.GetGameId(string.IsNullOrEmpty(fileVersionInfo.ProductName)?System.IO.Path.GetFileNameWithoutExtension(executables[i]) : fileVersionInfo.ProductName);

                    GameInfo gameInfo = new()
                    {
                        FileLocation     = executables[i],
                        IsFavorite       = false,
                        Name             = string.IsNullOrEmpty(fileVersionInfo.ProductName) ? System.IO.Path.GetFileNameWithoutExtension(executables[i]) : fileVersionInfo.ProductName,
                        LastTimePlayed   = 0,
                        TotalTimePlayed  = 0,
                        IconFileLocation = await Global.GetCoverImageAsync(string.IsNullOrEmpty(fileVersionInfo.ProductName)?System.IO.Path.GetFileNameWithoutExtension(executables[i]) : fileVersionInfo.ProductName),
                        RAWGID           = id,                                                         // Set the id
                        ProcessName      = "",                                                         // Set the ProcessName: "" => Default
                        Description      = (id != -1) ? await Global.GetGameDescriptionAsync(id) : "", // Get the description
                        Platforms        = (id != -1) ? await Global.GetGamePlatformsAsync(id) : new List <SDK.RAWG.Platform>
                        {
                            Definitions.DefaultPlatform
                        },                                                                                              // Get platforms
                        Stores  = (id != -1) ? await Global.GetStoresAsync(id) : new(),                                 // Get
                        Version = fileVersionInfo.FileVersion                                                           // Get the version
                    };
                    Definitions.Games.Add(gameInfo);                                                                    // Add the games to the List<GameInfo>
                    Definitions.GamesCardsPages.GamePresenter.Children.Add(new GameCard(gameInfo, GavilyaPages.Cards)); // Add the games to the GamePresenter
                    GameSaver.Save(Definitions.Games);                                                                  // Save the added games
                    Global.SortGames();                                                                                 // Sort
                    Definitions.GamesCardsPages.LoadGames();                                                            // Reload the page
                    Definitions.RecentGamesPage.LoadGames();                                                            // Reload the page
                    Definitions.GamesListPage.LoadGames();                                                              // Reload the page
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, Properties.Resources.MainWindowTitle, MessageBoxButton.OK, MessageBoxImage.Error);             // Error
        }
    }
コード例 #5
0
    private void Timer_Tick(object sender, EventArgs e)
    {
        string processName;

        if (!GameInfo.IsUWP)
        {
            processName = (!string.IsNullOrEmpty(GameInfo.ProcessName)) ? GameInfo.ProcessName : System.IO.Path.GetFileNameWithoutExtension(GameInfo.FileLocation);             // Get the process name
        }
        else
        {
            processName = (!string.IsNullOrEmpty(GameInfo.ProcessName)) ? GameInfo.ProcessName : location;
        }

        Definitions.GameInfoPage.DisplayTotalTimePlayed((Definitions.GameInfoPage.GameInfo == null) ? GameInfo.TotalTimePlayed : Definitions.GameInfoPage.GameInfo.TotalTimePlayed);    // Refresh
        Definitions.GameInfoPage2.DisplayTotalTimePlayed((Definitions.GameInfoPage2.GameInfo == null) ? GameInfo.TotalTimePlayed : Definitions.GameInfoPage2.GameInfo.TotalTimePlayed); // Refresh

        if (Global.IsProcessRunning(processName))                                                                                                                                       // If the game is running
        {
            gameStarted = true;                                                                                                                                                         // The game has started
            GameInfo.TotalTimePlayed += 1;                                                                                                                                              // Increment the time played
        }
        else
        {
            if (gameStarted)                       // If the game has been started
            {
                GameSaver.Save(Definitions.Games); // Save
                if (!GameInfo.AlwaysCheckIfRunning)
                {
                    Timer.Stop();                     // Stop
                }
            }
        }
    }
コード例 #6
0
    void CheckHowManyGuesses()
    {
        int howManyGuesses = 0;

        switch (level)
        {
        case 0:
            howManyGuesses = 5;
            break;

        case 1:
            howManyGuesses = 10;
            break;

        case 2:
            howManyGuesses = 15;
            break;

        case 3:
            howManyGuesses = 20;
            break;

        case 4:
            howManyGuesses = 25;
            break;
        }

        if (countTryGuess < howManyGuesses)
        {
            gameFinished.ShowGameFinishedPanel(3);

            puzzleGameSaver.Save(level, selectedPuzzle, 3);
        }
        else if (countTryGuess < (howManyGuesses + 5))
        {
            gameFinished.ShowGameFinishedPanel(2);

            puzzleGameSaver.Save(level, selectedPuzzle, 2);
        }
        else
        {
            gameFinished.ShowGameFinishedPanel(1);
            puzzleGameSaver.Save(level, selectedPuzzle, 1);
        }
    }
コード例 #7
0
        public void TestSave()
        {
            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();


            saver.Save(myGame);

            Assert.IsTrue(saver.IsSavingPresent());
            Assert.AreNotEqual(saver.Load(), new GameImpl());
            Assert.AreEqual(myGame, saver.Load());
        }
コード例 #8
0
    private void NextBtn_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            if (isFromAdd)
            {
                Definitions.Games.Add(new()
                {
                    Name             = AddGame.GameName,         // Set value
                    Version          = AddGame.GameVersion,      // Set value
                    Description      = DescriptionTextBox.Text,  // Set value
                    FileLocation     = AddGame.GameLocation,     // Set value
                    IconFileLocation = AddGame.GameIconLocation, // Set value
                    IsFavorite       = false,                    // Set value
                    RAWGID           = RAWGID,                   // Set value
                    LastTimePlayed   = 0,                        // Set value
                    TotalTimePlayed  = 0,                        // Set value
                    ProcessName      = "",                       // Set value
                    Platforms        = (Platforms.Count == 0) ? new List <SDK.RAWG.Platform> {
                        Definitions.DefaultPlatform
                    } : Platforms,                                                                                                                    // Get platforms
                    Stores = Stores,
                    AlwaysCheckIfRunning = false,
                    IsUWP   = AddGame.IsUWP,
                    IsSteam = AddGame.IsSteam
                });

                GameSaver.Save(Definitions.Games);       // Save
                Global.ReloadAllPages();                 // Refresh UI

                AddGame.Close();
            }
            else
            {
                GameCard.GameInfo.RAWGID      = RAWGID;                                // Set
                GameCard.GameInfo.Description = DescriptionTextBox.Text;               // Set
                GameCard.GameInfo.Platforms   = Platforms;                             // Set
                GameCard.GameInfo.Stores      = Stores;                                // Set

                Definitions.Games[Definitions.Games.IndexOf(old)] = GameCard.GameInfo; // Update
                GameSaver.Save(Definitions.Games);                                     // Save

                Global.ReloadAllPages();                                               // Refresh UI

                EditGame.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, Properties.Resources.MainWindowTitle, MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
コード例 #9
0
        public void TestEngineOldGame()
        {
            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();

            saver.Save(myGame);


            Engine engine = new Engine();

            engine.Update(true);

            Assert.AreEqual(engine.Game, myGame);
        }
コード例 #10
0
        public void TestEngineNewGame()
        {
            Engine engine = new Engine();

            engine.Update(false);

            GameSaver saver  = new GameSaver();
            GameImpl  myGame = new GameImpl();

            saver.Save(myGame);

            Assert.NotNull(engine.Game);
            Assert.AreNotEqual(myGame, engine.Game);
        }
コード例 #11
0
    private void PlayBtn_Click(object sender, RoutedEventArgs e)
    {
        if (GameInfo.IsSteam && !Global.CanLaunchSteamGame())
        {
            return;             // If the user can't launch the game, stop
        }

        if (!GameInfo.IsUWP && !GameInfo.IsSteam)
        {
            if (File.Exists(GamePath))             // If the game location file exist
            {
                Process p = new();
                p.StartInfo.WorkingDirectory = Path.GetDirectoryName(GamePath);
                p.StartInfo.FileName         = GamePath;
                p.Start();

                if (parentElement is GameCard gameCard)
                {
                    gameCard.GameInfo.LastTimePlayed = Env.GetUnixTime();                    // Get the current unix time
                    GameSaver.Save(Definitions.Games);                                       // Save the changes

                    Definitions.GameInfoPage.UpdateLastTimePlayed(GameInfo.LastTimePlayed);  // Update informations
                    Definitions.GameInfoPage2.UpdateLastTimePlayed(GameInfo.LastTimePlayed); // Update informations

                    gameCard.Timer.Start();                                                  // Start the timer
                }

                Definitions.RecentGamesPage.LoadGames();                 // Reload the games
            }
        }
        else
        {
            Process.Start("explorer.exe", GamePath);             // Start the game
            // Create a game card

            if (parentElement is GameCard gameCard)
            {
                gameCard.GameInfo.LastTimePlayed = Env.GetUnixTime();                    // Get the current unix time
                GameSaver.Save(Definitions.Games);                                       // Save the changes

                Definitions.GameInfoPage.UpdateLastTimePlayed(GameInfo.LastTimePlayed);  // Update informations
                Definitions.GameInfoPage2.UpdateLastTimePlayed(GameInfo.LastTimePlayed); // Update informations

                gameCard.Timer.Start();                                                  // Start the timer
            }

            Definitions.RecentGamesPage.LoadGames();             // Reload the games
        }
    }
コード例 #12
0
        public void OnGet()
        {
            // Players have not been defined yet
            if (ActiveGame.Players == null || ActiveGame.Players.Count == 0)
            {
                IsInvalidAccess = true;
                return;
            }

            // There's no current player so set it
            if (ActiveGame.CurrentPlayer == null || ActiveGame.NextPlayer == null)
            {
                ActiveGame.InitPlayerPointers();

                // Just to get rid of IDE warnings
                if (ActiveGame.CurrentPlayer == null || ActiveGame.NextPlayer == null)
                {
                    throw new NullReferenceException();
                }
            }

            // Players haven't placed ships yet
            if (ActiveGame.CurrentPlayer.Ships.FirstOrDefault(ship => ship.IsPlaced) == null)
            {
                IsInvalidAccess = true;
                return;
            }

            if (Request.Query.ContainsKey("save"))
            {
                GameSaver.Save();
                IsStatus  = true;
                StatusMsg = "Game saved!";
                return;
            }

            // There's a winner
            if (ActiveGame.TrySetWinner())
            {
                IsWinner  = true;
                StatusMsg = $"The winner of the game is {ActiveGame.Winner.Name}!";
                return;
            }

            MainTitle       = $"{ActiveGame.CurrentPlayer.Name} is attacking {ActiveGame.NextPlayer.Name}";
            IsDisplayBoards = true;
        }
コード例 #13
0
ファイル: LabCamera.cs プロジェクト: CyberChroma/Cyberspace
 // Update is called once per frame
 void Update()
 {
     if (activePos == 0)
     {
         if (Input.GetKeyDown(KeyCode.D))
         {
             camPositions[0].rotation = Quaternion.Euler(new Vector3(5, camPositions[0].rotation.eulerAngles.y + 60, 0));
             turnDir += 1;
             if (turnDir > 6)
             {
                 turnDir = 1;
             }
         }
         else if (Input.GetKeyDown(KeyCode.A))
         {
             camPositions[0].rotation = Quaternion.Euler(new Vector3(5, camPositions[0].rotation.eulerAngles.y - 60, 0));
             turnDir -= 1;
             if (turnDir < 1)
             {
                 turnDir = 6;
             }
         }
         if (Input.GetKeyDown(KeyCode.Space))
         {
             activePos = turnDir;
             if (activePos == 5)
             {
                 levelManager.Activate();
             }
             if (activePos == 1)
             {
                 StartCoroutine(MainMenu());
             }
         }
     }
     else if (Input.GetKeyDown(KeyCode.LeftShift) && activePos != 1)
     {
         if (activePos == 5)
         {
             levelManager.Deactivate();
         }
         activePos = 0;
         gameSaver.Save();
     }
     transform.position = Vector3.Lerp(transform.position, camPositions[activePos].position, smoothing * Time.deltaTime);
     transform.rotation = Quaternion.Slerp(transform.rotation, camPositions[activePos].rotation, smoothing * Time.deltaTime);
 }
コード例 #14
0
 private void FavBtn_Click(object sender, RoutedEventArgs e)
 {
     if (GameInfo.IsFavorite)                                                          // If the game is a favorite
     {
         GameInfo.IsFavorite = false;                                                  // The game is no longer a favorite
         Definitions.HomePage.FavoriteBar.Children.Remove(FavoriteGameCard);           // Remove from favorite bar
         FavBtn.Content             = "\uF710";                                        // Change icon
         GameCardBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(102, 0, 255)); // Set the border color
     }
     else
     {
         GameInfo.IsFavorite = true;                                                    // Set the game to be a favorite
         FavoriteGameCard    = new FavoriteGameCard(GameInfo, this);
         Definitions.HomePage.FavoriteBar.Children.Add(FavoriteGameCard);               // Add to favorite bar
         FavBtn.Content             = "\uF71B";                                         // Change icon
         GameCardBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(55, 121, 238)); // Set the border color
     }
     GameSaver.Save(Definitions.Games);                                                 // Save the changes
 }
コード例 #15
0
    private void NextBtn_Click(object sender, RoutedEventArgs e)
    {
        if (GamePresenter.Children.Count > 0)
        {
            List <GameInfo> gameInfos = new();

            for (int i = 0; i < GamePresenter.Children.Count; i++)
            {
                var game = (ImportGameItem)GamePresenter.Children[i];
                if (game.SelectCheckBox.IsChecked.Value)
                {
                    gameInfos.Add(game.GameInfo);                     // Add
                }
            }

            Definitions.Games = gameInfos;             // Set
            GameSaver.Save(Definitions.Games);         // Save changes
        }

        FirstRun.ChangePage(Enums.FirstRunPages.Finish);         // Change page
    }
コード例 #16
0
    private void FinishBtn_Click(object sender, RoutedEventArgs e)
    {
        if (GamePresenter.Children.Count > 0)
        {
            List <GameInfo> gameInfos = new();

            for (int i = 0; i < GamePresenter.Children.Count; i++)
            {
                var game = (ImportGameItem)GamePresenter.Children[i];
                if (game.SelectCheckBox.IsChecked.Value)
                {
                    gameInfos.Add(game.GameInfo);                     // Add
                }
            }

            Definitions.Games = gameInfos;             // Set
            GameSaver.Save(Definitions.Games);         // Save changes
        }

        Global.ReloadAllPages(); // Refresh
        Close();                 // Close the window
    }
コード例 #17
0
    private void ConvertSteamBtn_Click(object sender, RoutedEventArgs e)
    {
        if (ConvertSteamPanel.Visibility == Visibility.Collapsed)
        {
            ConvertSteamBtn.Content      = Properties.Resources.ConvertToSteam; // Set new text of the button
            ConvertSteamPanel.Visibility = Visibility.Visible;                  // Show the panel
        }
        else
        {
            if (string.IsNullOrEmpty(SteamAppIdTextBox.Text))
            {
                MessageBox.Show(Properties.Resources.GameNeedsName, Properties.Resources.MainWindowTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);                 // Show message
                return;
            }

            // Ask a confirmation to the user
            if (MessageBox.Show(Properties.Resources.ConvertToSteamMsg, Properties.Resources.MainWindowTitle, MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                GameCard.GameInfo.IsSteam      = true;            // Convert to steam game
                GameCard.GameInfo.FileLocation = $"steam://rungameid/{SteamAppIdTextBox.Text}";
                GameCard.GameInfo.ProcessName  = !string.IsNullOrEmpty(GameProcessTextBox.Text) ? GameProcessTextBox.Text : GameCard.GameInfo.ProcessName;

                // Save other changes
                GameCard.GameInfo.RAWGID      = RAWGID;                                // Set
                GameCard.GameInfo.Description = DescriptionTextBox.Text;               // Set
                GameCard.GameInfo.Platforms   = Platforms;                             // Set
                GameCard.GameInfo.Stores      = Stores;                                // Set

                Definitions.Games[Definitions.Games.IndexOf(old)] = GameCard.GameInfo; // Update
                GameSaver.Save(Definitions.Games);                                     // Save

                Global.ReloadAllPages();                                               // Refresh UI

                EditGame.Close();
            }
        }
    }
コード例 #18
0
        public override void PreInit()
        {
            GameObjects.Add(Background);
            GameObjects.Add(
                new ButtonObject(new Text("Сохранить", Cache.GetFont("fonts/arial"), 21),
                                 new Style(new Dictionary <StyleType, object>
            {
                { StyleType.TextColor, Color.Black }
            }))
            {
                Position         = new Vector2f(10, 920),
                LeftClickHandler = () =>
                {
                    GameSaver.Save("test.save");

                    var box = new MessageBoxObject(new Style(), new Text("Вы сохранили игру!", Cache.GetFont("fonts/arial")));
                    GameObjects.Add(box);
                }
            });

            _isFirst = true;
            Index    = 0;
            NovelInfo.Clear();
        }
コード例 #19
0
    private void AdminBtn_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            if (!GameInfo.IsUWP && !GameInfo.IsSteam)
            {
                if (File.Exists(location))                       // If the file exist
                {
                    Env.ExecuteAsAdmin(location);                // Start the game
                    GameInfo.LastTimePlayed = Env.GetUnixTime(); // Set the last time played

                    Timer.Start();                               // Start the timer

                    Definitions.RecentGamesPage.LoadGames();     // Reload the games
                    GameSaver.Save(Definitions.Games);           // Save the changes
                }
            }
            else
            {
                MessageBox.Show(Properties.Resources.CannotLaunchAsAdminUWP, Properties.Resources.MainWindowTitle, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        catch { }         // If the user says "No" the Admin prompt
    }
コード例 #20
0
 void Quit()
 {
     gameSaver.Save();
     Application.Quit();
 }