-1
\$\begingroup\$

So I've got a simple game with different levels. For the most part the levels use the same code, with only slightly different things. Do i have to make a new Activity for every level? The app will have a 'level select' screen. Is there a way to tell one activity to run a certain set of java based on what level I selected? Any suggestions would be appreciated.

\$\endgroup\$
0

2 Answers 2

0
\$\begingroup\$

Perhaps activities can inherit from different "gameplay" classes using a common interface? Multiple inheritance could be useful here. Then you assign an activity to a level and get the gameplay.

\$\endgroup\$
0
0
\$\begingroup\$

I've figured it out.

On the level picking activity, basically have an Intent that can send information to the activity that actually runs the game. Based on what level is selected, you can set it to change a string to whatever level it is. The gameplay activity will get the information from the level selection activity and use it to choose which "game" (lines of code) to run. For example:

if  (level.getString("level", "").equals("1")) {
                        //change aspect of game like time or the score: each of those 
                        would be a Double
                    }
if  (level.getString("level", "").equals("2")) {
                        //change the time or score to be harder than the level before.
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.