Exemplo n.º 1
0
        private void NextVideoStart(object sender, EventArgs e)
        {
            // by default we advance the position by 1
            int nextStoryPosition = MainResources.GetPathPosition() + 1;

            switch (_prevButtonSchema.ButtonType)
            {
            case ButtonType.Default:
                MainResources.AdjustHP(_prevButtonSchema.ScoreAdjustment.HP);
                MainResources.AdjustPoints(_prevButtonSchema.ScoreAdjustment.Points);
                break;

            case ButtonType.End:
                // an "End" button type will end the game immidiately
                nextStoryPosition = -1;
                break;

            default:
                break;
            }
            // update the game resources
            MainResources.SetPathPosition(nextStoryPosition);
            // create new GameMenu instance
            GameMenu nextGameMenu = new GameMenu(_prevButtonSchema);

            DebugFunctions.DEBUG_output_list_of_videos("NextVideoStart function, line 398", _prevButtonSchema);
            MainResources.MainWindow.MainPanel.Children.Add(nextGameMenu);
            MainResources.MainWindow.MainPanel.Children.Remove(this);
            MainResources.SetPathPosition(nextStoryPosition);
        }
Exemplo n.º 2
0
        private void RetryButtonClicked(object sender, RoutedEventArgs e)
        {
            // create new GameMenu instance with previous game state
            RestorePoint load = MainResources.RestorePreviousState();

            DebugFunctions.DEBUG_output_list_of_videos("LOADED RESTORE POINT", load.LastChoice);
            // we only want to show the last video played, not the whole list
            ButtonSchema  loadedState = load.LastChoice;
            List <string> setupVideo  = new List <string>();

            // if there was more than 1 video played, just play the last video
            if (loadedState.VideoFilename.Count > 1)
            {
                // only add the last video to the list
                setupVideo.Add(loadedState.VideoFilename[loadedState.VideoFilename.Count - 1]);
            }
            else
            {
                // there's only one anyways, so just pass it along
                setupVideo = loadedState.VideoFilename;
            }
            // add the setup video to our loaded state
            loadedState.VideoFilename = setupVideo;

            GameMenu replayChoices = new GameMenu(loadedState);

            MainResources.MainWindow.MainPanel.Children.Add(replayChoices);
            MainResources.MainWindow.MainPanel.Children.Remove(this);
        }
Exemplo n.º 3
0
        private void PlayButtonClicked(object sender, RoutedEventArgs e)
        {
            // sets base path file location (root directory)
            MainResources.SetRootDirectory(_path);

            // confirm the scenario, loads the settings into mainresources
            MainResources.SetHP(_settings.StartingHP);
            MainResources.SetBranch(_settings.StartingBranch);
            MainResources.SetPathPosition(_settings.StartingPathPosition);
            MainResources.SetPoints(_settings.StartingPoints);

            // sets the folder path where we store all the ending videos
            MainResources.SetEndingPathRoot(Path.Combine(_path, "endings"));

            ButtonSchema buttonData = new ButtonSchema()
            {
                VideoFilename = new List <string>()
                {
                    Path.Combine(_path, _introVideo)
                },
                Endings = new List <Ending>()
            };

            GameMenu gameMenu = new GameMenu(buttonData);

            MainResources.MainWindow.MainPanel.Children.Add(gameMenu);
            MainResources.MainWindow.MainPanel.Children.Remove(this);
            MainResources.MainWindow.RemoveBackground();
        }
Exemplo n.º 4
0
        private void ButtonClicked(ButtonSchema buttonSchema)
        {
            DebugFunctions.DEBUG_output_list_of_videos("ButtonClicked", buttonSchema);

            // disable UI
            IsEnabled = false;

            if (buttonSchema.Path.Branch != MainResources.GetBranch())
            {
                MainResources.SetBranch(buttonSchema.Path.Branch);
                MainResources.SetPathPosition(buttonSchema.Path.StartPosition - 1);
            }

            _prevButtonSchema = buttonSchema;
            _fadeInStoryboards.Stop();
            _fadeOutStoryboards.Begin();
        }
Exemplo n.º 5
0
        public GameMenu(ButtonSchema buttonData)
        {
            DebugFunctions.DEBUG_output_list_of_videos("GameMenu Constructor", buttonData);

            InitializeComponent();
            // load root directory
            _scenarioPath = MainResources.GetRootDirectory();

            // holds our buttons so we can iterate and enable/disable
            gameButtons = new List <GameButton>();

            // load current path position (ie 1, 2, 3, -1)
            _storyPosition = MainResources.GetPathPosition();

            // set default video to play (first video in list)
            string videoPath = buttonData.VideoFilename[_currentlyPlayingVideo];

            // path for the current branch
            _branchPath = Path.Combine(_scenarioPath, MainResources.GetBranch() + _storyPosition.ToString());

            // if we are at -1 story position or no HP, it's game over
            if (_storyPosition == -1 || isPlayerDead())
            {
                ShowLoseScreen(buttonData);
                return;
            }
            // didn't lost the game, so save restore point
            MainResources.SaveCurrentState(buttonData);

            // callback to invoke after the video is played
            Action afterVideoPlayed = AfterChoiceVideoPlayed;

            // win conditions
            // 1. if there are no more folders along this story path
            // 2. if the button data has an ending
            if (!Directory.Exists(_branchPath) || buttonData.Endings.Count > 0)
            {
                // start by setting the ending video we will play
                string endVideoPath = videoPath;

                // determine which ending based on points
                foreach (Ending ending in buttonData.Endings)
                {
                    // the first ending that matches the condition will be set as the ending (so consider the order of endings in the list)
                    if (MainResources.GetPoints() >= ending.WhenPointsAreBetween[0] && MainResources.GetPoints() <= ending.WhenPointsAreBetween[1])
                    {
                        _hasEndingVideo = true;

                        // set this ending to play after the choice video
                        endVideoPath = Path.Combine(_scenarioPath, "endings", ending.VideoFilename);

                        // set the text to display on the ending screen depending on this ending
                        buttonData.EndScreenMessage = ending.EndScreenMessage;
                        // break on first match
                        break;
                    }
                }

                if (!_hasEndingVideo && buttonData.Endings.Count == 1)
                {
                    // only 1 ending, play it (no point condition)
                    _hasEndingVideo = true;
                    endVideoPath    = Path.Combine(_scenarioPath, "endings", buttonData.Endings[0].VideoFilename);
                }


                afterVideoPlayed = () => ShowWinScreen(buttonData, endVideoPath);
                // "just in case" there are  no matches
                if (!_hasEndingVideo || buttonData.Endings.Count == 0)
                {
                    // just show the regular win screen (no ending video)
                    ShowWinScreen(buttonData, videoPath);
                    return;
                }
            }

            // see if we have other videos to play after this one
            if (buttonData.VideoFilename.Count > 1)
            {
                // set the callback to invoke after ALL videos are played
                Action finalCallback = afterVideoPlayed;
                // set the immidiate callback to play other videos first
                afterVideoPlayed = () => PlayOtherVideosFirst(buttonData.VideoFilename, finalCallback);
            }

            _fadeInStoryboards  = new Storyboard();
            _fadeOutStoryboards = new Storyboard();

            // setting fade in animations (not running them yet)
            var fadeIn = FindResource("FadeInStoryboard") as Storyboard;

            Storyboard.SetTarget(fadeIn, GameMenuGrid);

            var fadeIn2 = FindResource("FadeInStoryboard2") as Storyboard;

            Storyboard.SetTarget(fadeIn2, ChoiceMenuBorder);

            var fadeOut = FindResource("FadeOutStoryboard") as Storyboard;

            // sets the callback when storyboard (choices) have faded out
            fadeOut.Completed += NextVideoStart;
            Storyboard.SetTarget(fadeOut, GameMenuGrid);

            var fadeOut2 = FindResource("FadeOutStoryboard2") as Storyboard;

            Storyboard.SetTarget(fadeOut2, ChoiceMenuBorder);


            _fadeInStoryboards.Children.Add(fadeIn);
            _fadeInStoryboards.Children.Add(fadeIn2);

            _fadeOutStoryboards.Children.Add(fadeOut);
            _fadeOutStoryboards.Children.Add(fadeOut2);

            if (!_hasEndingVideo)
            {
                // if we are not playing the ending video, we must be continuing the game, so add the choice buttons
                AddButtons();
            }

            // now play the video, and invoke the callback after it's played
            MainResources.MainWindow.PlayFile(videoPath, afterVideoPlayed);
        }
Exemplo n.º 6
0
        private void AddButtons()
        {
            gameButtons = new List <GameButton>();

            // load the buttons from json file
            string branchPath = Path.Combine(_branchPath, "options.json");

            using (StreamReader r = new StreamReader(branchPath))
            {
                string json = r.ReadToEnd();
                List <ButtonSchema> items = JsonConvert.DeserializeObject <List <ButtonSchema> >(json);
                foreach (var item in items)
                {
                    // set default path progression
                    StoryPath storyPath = new StoryPath
                    {
                        Branch        = MainResources.GetBranch(),
                        StartPosition = _storyPosition
                    };

                    // set default score adjustments
                    ScoreAdjustment scoreAdjustment = new ScoreAdjustment
                    {
                        HP     = 0,
                        Points = 0
                    };

                    // default empty ending list
                    List <Ending> endings = new List <Ending>();
                    // will hold the list of videos to play when the button is pressed
                    List <string> videoPaths = new List <string>()
                    {
                    };

                    // the video path is the CURRENT BRANCH PATH, even if the branch will be changed
                    string videoFilepath = Path.Combine(_scenarioPath, storyPath.Branch + storyPath.StartPosition);

                    // if we have conditional videos, they take priority over anything in VideoFilename
                    if (item.Videos != null)
                    {
                        // loop through our conditional options
                        foreach (ConditionalVideos cond in item.Videos)
                        {
                            // the first match will be used (so consider the order of endings in the list)
                            if (MainResources.GetPoints() >= cond.WhenPointsAreBetween[0] && MainResources.GetPoints() <= cond.WhenPointsAreBetween[1])
                            {
                                // add these videos to the list to be played
                                foreach (string vid in cond.VideoFilename)
                                {
                                    videoPaths.Add(Path.Combine(videoFilepath, vid));
                                }
                                // break on first match
                                break;
                            }
                        }
                        // if we still have no videos to play, just get the first one from the ConditionalVideos
                        if (videoPaths.Count == 0)
                        {
                            ConditionalVideos defaultVideos = item.Videos[0];
                            foreach (string video in defaultVideos.VideoFilename)
                            {
                                videoPaths.Add(Path.Combine(videoFilepath, video));
                            }
                        }
                    }
                    else
                    {
                        // no conditional videos, just play the list of VideoFilename
                        foreach (string vidPath in item.VideoFilename)
                        {
                            videoPaths.Add(Path.Combine(videoFilepath, vidPath));
                        }
                    }



                    // if item.Path is null, we stay on the same branch and advance 1 position (default behavior)
                    if (item.Path != null)
                    {
                        // if we change the path, we set the branch and the start position on that branch
                        storyPath.Branch        = item.Path.Branch;
                        storyPath.StartPosition = item.Path.StartPosition;
                    }

                    if (item.ScoreAdjustment != null)
                    {
                        scoreAdjustment.HP     = item.ScoreAdjustment.HP;
                        scoreAdjustment.Points = item.ScoreAdjustment.Points;
                    }

                    if (item.Endings != null)
                    {
                        endings = item.Endings;
                    }

                    ButtonSchema buttonData = new ButtonSchema()
                    {
                        ButtonType       = item.ButtonType,
                        VideoFilename    = videoPaths,
                        Path             = storyPath,
                        ScoreAdjustment  = scoreAdjustment,
                        Endings          = endings,
                        EndScreenMessage = item.EndScreenMessage
                    };

                    GameButton gameButton = new GameButton(item.Label, buttonData, ButtonClicked);
                    // disable the button by default
                    gameButton.IsEnabled = false;
                    // add the button to our global button container so we can re-enable them after the video is done
                    gameButtons.Add(gameButton);
                }
            }

            gameButtons.Shuffle();

            // making 2 columns with multiple rows for the buttons
            int buttonPos = 0;

            foreach (var gameButton in gameButtons)
            {
                if (buttonPos == 0 || buttonPos == 2 || buttonPos == 4)
                {
                    ButtonStackPanel.Children.Add(gameButton);
                }
                else
                {
                    ButtonStackPanel2.Children.Add(gameButton);
                }
                buttonPos += 1;
            }

            // Debug logging
            // display the current HP, points, branch and position on the choice menu
            HealthAndPositionLabel.Content = $"{MainResources.GetBranch()}{_storyPosition} | HP:{MainResources.GetHP()} Pts:{MainResources.GetPoints()}";
        }
Exemplo n.º 7
0
 private bool isPlayerDead()
 {
     return(MainResources.GetHP() < 0);
 }