Skip to content

Add Title Screen Controls #2

@CodeRhymesLife

Description

@CodeRhymesLife

Problem

The title screen shows, but you can't select different options 😮! WHAT'S HAPPENING😱!?

I deleted the code that selects the next and previous options on the TitleScreen. To fix this issue you'll have to add that code back!

Where's The Problem?

File: src/screen/TitleScreen.java
Functions: getNextMenuItem( ... ) and getPreviousMenuItem( ... )

To fix this issue you will need to add code to both of the above functions.

Instructions

According to the comments above the two functions in TitleScreen.java:

getNextMenuItem( ScreenType selectedMenuItem ) is passed in the currently selected item and should return the next item to select.

getPreviousMenuItem( ScreenType selectedMenuItem ) is passed in the currently selected item and should return the previous item to select.

Let's start by working on getNextMenuItem( ... ).

getNextMenuItem( ... )

When image is pressed getNextMenuItem( ... ) is called to retrieve the next menu item. When the TitleScreen starts Play is selected.

image

When image is pressed High Scores should get selected.

image

When image is pressed again Exit should get selected.

image

Finally, when image is pressed again Play should get selected.

image

And so on...

Right now getNextMenuItem( ... ) always returns ScreenType.GameScreen as the next menu item, which is why Play is always selected. To fix this you need to return the appropriate next menu item. Use selectedMenuItem to detect the currently selected menu item, then return the correct next menu item using a member of ScreenType. To do this follow the 4 steps below:

  1. Delete return ScreenType.GameScreen;
  2. if selectedMenuItem equals ScreenType.GameScreen
    return ScreenType.HighSoresScreen
  3. else if selectedMenuItem equals ScreenType.HighScoreScreen
    return ScreenType.EndGame
  4. else return ScreenType.GameScreen

Don't forget to add brackets! Your if statements should look something like this:

if( ... ) {
     ...
}
else if ( ... ) {
     ...
}
else {
     ...
}

At this point you should be able to compile and run your code, and use the image key to select items on the title screen. Great Job!

Now we need to do something similar for getPreviousMenuItem( ... ) so the correct menu item is chosen when image is pressed.

getPreviousMenuItem( ... )

I'l let you figure this one out on your own 😄. Hint: use the working version of Invaders to figure out what should happen when the up key is pressed, then make this behavior happen by returning the correct values from getPreviousMenuItem( ... ).

After you have fixed this bug:

  1. Commit and push your changes to GitHub
  2. For groups, have each group member sync, run and test the latest code to make sure everything is working properly.
  3. Move on to Enable All Screens #3!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions