Example #1
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()}";
        }
Example #2
0
 private bool isPlayerDead()
 {
     return(MainResources.GetHP() < 0);
 }