Skip to content

Commit

Permalink
Refactored to use Previous/Next rather than Choice1 and Choice2 (Prev…
Browse files Browse the repository at this point in the history
…ious/Next hard-coded as any page).

Updated throughout Page and Story classes where needed. Also refactored activity_story.xml to use previousButton and nextButton rather than choiceButton1 and choiceButton2.

Choice renamed to Choices - Choices class deals with BOTH CHOICES.
Choices uses getNextPage() and getPreviousPage(), it previously only used a getNextPage(). Slightly confusing but both buttons do actually lead to a "next page".

IMPORTANT: THIS COMMIT WILL NOT CHECK WHETHER THE PREVIOUS PAGE IS IN FACT A PREVIOUS PAGE (It won't do the maths of current page - 1). Please check next commit if this is the functionality you were looking for.
  • Loading branch information
harryjamesuk committed Jan 9, 2016
1 parent 7a02c9d commit db1b082
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 76 deletions.

This file was deleted.

@@ -0,0 +1,52 @@
package com.harryjamesuk.interactivestory.model;

/**
* Created by Harry on 22/03/2015.
*/
public class Choices {

private String mText1;
private String mText2;

private int mPreviousPage;
private int mNextPage;

public Choices(int previousPage, String text1, int nextPage, String text2) {
mPreviousPage = previousPage;
mText1 = text1;
mNextPage = nextPage;
mText2 = text2;
}

public String getText1() {
return mText1;
}

public void setText1(String text1) {
mText1 = text1;
}

public String getText2() {
return mText2;
}

public void setText2(String text2) {
mText2 = text2;
}

public int getPreviousPage() {
return mPreviousPage;
}

public void setPreviousPage(int previousPage) {
mPreviousPage = previousPage;
}

public int getNextPage() {
return mNextPage;
}

public void setNextPage(int nextPage) {
mNextPage = nextPage;
}
}
Expand Up @@ -7,22 +7,19 @@ public class Page {

private int mImageId;
private String mText;
private Choice mChoice1;
private Choice mChoice2;
private Choices mChoices;
private boolean mIsFinal = false;

public Page(int imageId, String text, Choice choice1, Choice choice2) {
public Page(int imageId, String text, Choices choices) {
mImageId = imageId;
mText = text;
mChoice1 = choice1;
mChoice2 = choice2;
mChoices = choices;
}

public Page(int imageId, String text) {
mImageId = imageId;
mText = text;
mChoice1 = null;
mChoice2 = null;
mChoices = null;
mIsFinal = true;
}

Expand All @@ -42,20 +39,12 @@ public void setText(String text) {
mText = text;
}

public Choice getChoice1() {
return mChoice1;
public Choices getChoices() {
return mChoices;
}

public void setChoice1(Choice choice1) {
mChoice1 = choice1;
}

public Choice getChoice2() {
return mChoice2;
}

public void setChoice2(Choice choice2) {
mChoice2 = choice2;
public void setChoices(Choices choices) {
mChoices = choices;
}

public boolean isFinal() {
Expand Down
Expand Up @@ -14,32 +14,27 @@ public Story() {
mPages[0] = new Page(
R.mipmap.page0,
"On your return trip from studying Saturn's rings, you hear a distress signal that seems to be coming from the surface of Mars. It's strange because there hasn't been a colony there in years. Even stranger, it's calling you by name: \"Help me, %1$s, you're my only hope.\"",
new Choice("Stop and investigate", 1),
new Choice("Continue home to Earth", 2));
new Choices(1, "Stop and investigate", 2, "Continue home to Earth"));

mPages[1] = new Page(
R.mipmap.page1,
"You deftly land your ship near where the distress signal originated. You didn't notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.",
new Choice("Explore the cave", 3),
new Choice("Explore the rover", 4));
new Choices(3, "Explore the cave", 4, "Explore the rover"));

mPages[2] = new Page(
R.mipmap.page2,
"You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.",
new Choice("Head back to Mars to investigate", 4),
new Choice("Continue home to Earth", 6));
new Choices(4, "Head back to Mars to investigate", 6, "Continue home to Earth"));

mPages[3] = new Page(
R.mipmap.page3,
"Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there's a very faint light up ahead.",
new Choice("Refill at ship and explore the rover", 4),
new Choice("Continue towards the faint light", 5));
new Choices(4, "Refill at ship and explore the rover", 5, "Continue towards the faint light"));

mPages[4] = new Page(
R.mipmap.page4,
"The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren't far, but you don't know if your oxygen will last there and back.",
new Choice("Explore the coordinates", 5),
new Choice("Return to Earth", 6));
new Choices(5, "Explore the coordinates", 6, "Return to Earth"));

mPages[5] = new Page(
R.mipmap.page5,
Expand Down
Expand Up @@ -23,8 +23,8 @@ public class StoryActivity extends Activity {

private ImageView mImageView;
private TextView mTextView;
private Button mChoice1;
private Button mChoice2;
private Button mPreviousButton;
private Button mNextButton;

private String mName;

Expand All @@ -45,8 +45,8 @@ protected void onCreate(Bundle savedInstanceState) {

mImageView = (ImageView) findViewById(R.id.storyImageView);
mTextView = (TextView) findViewById(R.id.storyTextView);
mChoice1 = (Button) findViewById(R.id.choiceButton1);
mChoice2 = (Button) findViewById(R.id.choiceButton2);
mPreviousButton = (Button) findViewById(R.id.previousButton);
mNextButton = (Button) findViewById(R.id.nextButton);

loadPage(0);
}
Expand All @@ -63,29 +63,29 @@ private void loadPage(int choice) {
mTextView.setText(pageText);

if (mCurrentPage.isFinal()) {
mChoice1.setVisibility(View.INVISIBLE);
mChoice2.setText("PLAY AGAIN");
mChoice2.setOnClickListener(new View.OnClickListener() {
mPreviousButton.setVisibility(View.INVISIBLE);
mNextButton.setText("PLAY AGAIN");
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
} else {
mChoice1.setText(mCurrentPage.getChoice1().getText());
mChoice2.setText(mCurrentPage.getChoice2().getText());
mPreviousButton.setText(mCurrentPage.getChoices().getText1());
mNextButton.setText(mCurrentPage.getChoices().getText2());

mChoice1.setOnClickListener(new View.OnClickListener() {
mPreviousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int nextPage = mCurrentPage.getChoice1().getNextPage();
loadPage(nextPage);
int previousPage = mCurrentPage.getChoices().getPreviousPage();
loadPage(previousPage);
}
});
mChoice2.setOnClickListener(new View.OnClickListener() {
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int nextPage = mCurrentPage.getChoice2().getNextPage();
int nextPage = mCurrentPage.getChoices().getNextPage();
loadPage(nextPage);
}
});
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_story.xml
Expand Up @@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STOP AND INVESTIGATE"
android:id="@+id/choiceButton2"
android:id="@+id/nextButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
Expand All @@ -43,8 +43,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CONTINUE HOME TO EARTH"
android:id="@+id/choiceButton1"
android:layout_above="@+id/choiceButton2"
android:id="@+id/previousButton"
android:layout_above="@+id/nextButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/white"
Expand Down

0 comments on commit db1b082

Please sign in to comment.