Hey guys! I'm currently working on a simple matching game. The game has 3 difficulties: easy, medium, and hard. When the game starts up, it is already set to the easy difficulty with 12 tiles. Medium difficulty displays 20 tiles and hard difficulty displays 30 tiles. I've figured out how to display 12 tiles under the easy difficulty. There is a "Change Difficulty" which shows two buttons: Medium and hard. When the user clicks either, it leads them back to the main page of the app. My question is: how do I make it so that when I select either medium or hard, it would display the corresponding tiles? Any advice on a simple way to do this? I'm just a beginner :P
Here's my ChangeDifficulty activity:

public class ChangeDifficulty extends AppCompatActivity {

    Button mediumDifficulty;
    Button hardDifficulty;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_difficulty);

        mediumDifficulty = (Button) findViewById(R.id.button_medium);
        hardDifficulty = (Button) findViewById(R.id.button_hard);

        mediumDifficulty.setOnClickListener(medium);
        hardDifficulty.setOnClickListener(hard);
    }

    View.OnClickListener medium = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), MainActivity.class);
            startActivity(i);
            Toast.makeText(getApplicationContext(), "Medium difficulty selected!",
                    Toast.LENGTH_SHORT).show();

        }
    };

    View.OnClickListener hard = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), MainActivity.class);
            startActivity(i);
            Toast.makeText(getApplicationContext(), "Hard difficulty selected!",
                    Toast.LENGTH_SHORT).show();
        }
    };

Also, the MainActivity:

public class MainActivity extends AppCompatActivity {

    Button playButton;
    Button difficultyButton;
    Button logoButton;
    Button leaderboardButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        playButton = (Button) findViewById(R.id.button_play);
        difficultyButton = (Button) findViewById(R.id.button_difficulty);
        logoButton = (Button) findViewById(R.id.button_logos);
        leaderboardButton = (Button) findViewById(R.id.button_leaderboards);

        playButton.setOnClickListener(playGame);
        difficultyButton.setOnClickListener(changeDifficulty);
        logoButton.setOnClickListener(chooseLogos);
        leaderboardButton.setOnClickListener(viewLeaderboards);

    }

    View.OnClickListener playGame = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), Play.class);
            startActivity(i);
        }
    };

    View.OnClickListener changeDifficulty = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), ChangeDifficulty.class);
            startActivity(i);
        }
    };

    View.OnClickListener chooseLogos = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), ChooseLogo.class);
            startActivity(i);
        }
    };

    View.OnClickListener viewLeaderboards = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent();
            i.setClass(getBaseContext(), Leaderboard.class);
            startActivity(i);
        }
    };

And lastly, the Play activity:

public class Play extends AppCompatActivity {

    TextView tvTimer;
    GridView gvTile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);

        tvTimer = (TextView) findViewById(R.id.tv_timer);
        GridView gridview = (GridView) findViewById(R.id.gv_tile);
        gridview.setAdapter(new ImageAdapter(this));


        CountDownTimer timer = new CountDownTimer(7000, 1000) {

            public void onTick(long millisUntilFinished) {
                tvTimer.setText(" " + millisUntilFinished / 1000);
            }

            public void onFinish() {
                tvTimer.setText("Go!");
            }
        }.start();

    }

Would it be ideal if I just made an activity for Easy, Medium and Hard then have Intents calling the class? ie PlayMedium.class, PlayHard.class similar to Play.class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.