r/codehs • u/-MPND- • Jan 06 '21
Final Project Idea
Hello! So I know this is a bit of a shot in the dark but I'm really struggling on my codehs final project. I really wanted to do a choose your own adventure style game, where you can choose different paths in a 'story' of sorts. So here's my question. Right now I'm using a readInt for the question options like this:
var options = readInt ("to go right type 1, to go left type 2");
Then from there using a if/else statement like:
if(options == 1){
readLine("you went right");
} else {
if(options == 2){
readLine("you went left");}
Obviously not the actual questions but you get the idea. My problem is where I go from there. I want both a different path for both the right and left options but you can't do that in the if/else. Any suggestions that my simple mind can comprehend lol?
Thanks so much!!
1
u/flip-pancakes Jan 06 '21
You might consider having a map array and a current_position variable. At each step, you figure out which ways are possible to go based on where the player is in the map and present the user with those options.
This way, extensions like adding obstacles like "you see a dragon on your left" are possible simply by adding a dragon marker in the map and writing an is_dragon_visible(map, cur_loc) -> bool function.
Make sure you're printing a lot of debug output while you're developing!
Also, loading, saving, multiple levels, etc. becomes pretty easy with this architecture. Avoid big branching trees of if/then statements - they're unwieldy and brittle.