1. Download our Official Android App: Forums for Android!

Help with making a text-based game

Discussion in 'Android Development' started by PKJUni, Oct 3, 2017.

  1. PKJUni

    PKJUni Lurker
    Thread Starter
    Oct 3, 2017

    Oct 3, 2017
    Hi, first time poster here!

    So, we've started planning for our project in Android programming this semester, which is making an app in Android Studio of our own choosing, and I've decided looking into making a text based game as I'm a big fan of those (And I couldn't think of any other decent ideas...)

    So, I've started planning how I'm going to make it, but I quickly ran into an obstacle that I can't quite get past: How am I going to handle "going forward"/progression, and how will I save this progress?

    Being a text-based game it needs to have branching and choices. Nothing to complex as I've only got so much time to make it, but enough to demonstrate different features I want to implement. But I'm uncertain as to how I will handle the progression and branching.

    My first thought was to have Activities for each and every page with text and choices, but I think this might be a terrible way to make it. Then I thought about Fragments, and how I might be able to just go to a new Fragment every time a choice is made, with the Fragments covering the "entire" screen-space.

    And then comes the part where I need to save progress. So that if the user is at "page 12" and he exits and closes the app, it will start back up at "page 12" when the app is started again. I saw some suggestions on using SharedPreferences, but I'm a bit confused as to how I can have it store an Activity or a Fragment instead of a value like bolean or int.

    I would really appreciate some pointers on how I need to set this up, as I'm kinda at a loss on how I should proceed. Is my best bet to use Fragments? Are there any alternatives that I'm not seeing? As you can tell, I'm very new to Android, and programming as a whole, so my train of thought, so to speak, isn't quite "there yet", so everything helps!

    Edit: I've come up with a possible solution. I will have a textview and, let's say, two buttons, and I will keep arrays with the blocks of text I want to display and give them IDs. So when a button is pressed it will tell the textview which block of text it should display based on the ID. I will also change the text of the buttons based on which ID is in the textview, as well as what IDs the buttons will trigger.

    So for example: Textview is displaying ID 1. Buttons A and B changes textview to ID 2 or ID 3 respectively. Buttons A and B is then changed to buttons C and D, or E and F (Through IDs, the buttons themselves won't change, only the displayed buttontext and where it directs next), depending on if ID 2 or ID 3 i displayed. This will quickly escalate and become really messy, but I only need it to work in small scale.


    #1 PKJUni, Oct 3, 2017
    Last edited: Oct 4, 2017

Share This Page