Free Projects developed by Java, C# and PHP

Mouse catcher game app


We have many web application and mobile applications in GitHub for public use.

This project specifically developed to show how we can implement a simple 
android game in Android Studio with Java.

This project also demonstrated how we can implement rating and other custom 
dialog in android projects.

The project contains 4 main layouts described below:
	- Main Activity: is used as a home/landing page to show list of 
	  functions and options
	- Starter Activity: is used as a started activity to start the game and 
	  also show STOP and RESUME when the game is paused
	- Result Activity: is used to show the result/score of the game when one 
	  session is completed with options to REPLAY and EXIT
	- Setting Activity: is used to provide different preferences/setting for 
	  the game to be selected like complexity of the game


--> SettingActivity.java
============================================================================================
package com.btitsolutions.cookiecatcher;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class SettingActivity extends AppCompatActivity implements View.OnClickListener {
    Button btnSave;
    RadioButton rdbtnEasy, rdbtnMedium, rdbtnHard;
    RadioButton rdbtnCatcherSlow, rdbtnCatcherMedium, rdbtnCatcherFast;

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

        rdbtnEasy = (RadioButton)findViewById(R.id.rdbtnEasy);
        rdbtnMedium = (RadioButton)findViewById(R.id.rdbtnMedium);
        rdbtnHard = (RadioButton)findViewById(R.id.rdbtnHard);

        rdbtnCatcherSlow = (RadioButton)findViewById(R.id.rdbtnCatcherSlow);
        rdbtnCatcherMedium = (RadioButton)findViewById(R.id.rdbtnCatcherMedium);
        rdbtnCatcherFast = (RadioButton)findViewById(R.id.rdbtnCatcherFast);

        btnSave = (Button)findViewById(R.id.btnSave);
        btnSave.setOnClickListener(this);

        SharedPreferences Game_Setting = getSharedPreferences("Game_Setting", Context.MODE_PRIVATE);
        String SelectedLevel = Game_Setting.getString("SelectedLevel", "Easy");
        String SelectedSensitivity = Game_Setting.getString("SelectedSensitivity", "Slow");

        if(SelectedLevel.equals("Easy")){
            rdbtnEasy.setChecked(true);
        }
        else if(SelectedLevel.equals("Medium")){
            rdbtnMedium.setChecked(true);
        }
        else if(SelectedLevel.equals("Hard")){
            rdbtnHard.setChecked(true);
        }

        if(SelectedSensitivity.equals("Slow")){
            rdbtnCatcherSlow.setChecked(true);
        }
        else if(SelectedSensitivity.equals("Medium")){
            rdbtnCatcherMedium.setChecked(true);
        }
        else if(SelectedSensitivity.equals("Fast")){
            rdbtnCatcherFast.setChecked(true);
        }
    }

    @Override
    public void onClick(View view) {
        SharedPreferences Game_Setting = getSharedPreferences("Game_Setting", Context.MODE_PRIVATE);
        String SelectedLevel = "";
        String SelectedSensitivity = "";

        if(rdbtnEasy.isChecked() == true){
            SelectedLevel = "Easy";
        }
        else if(rdbtnMedium.isChecked() == true){
            SelectedLevel = "Medium";
        }
        else if(rdbtnHard.isChecked() == true){
            SelectedLevel = "Hard";
        }

        if(rdbtnCatcherSlow.isChecked() == true){
            SelectedSensitivity = "Slow";
        }
        else if(rdbtnCatcherMedium.isChecked() == true){
            SelectedSensitivity = "Medium";
        }
        else if(rdbtnCatcherFast.isChecked() == true){
            SelectedSensitivity = "Fast";
        }

        SharedPreferences.Editor editor = Game_Setting.edit();
        editor.putString("SelectedLevel", SelectedLevel);
        editor.putString("SelectedSensitivity", SelectedSensitivity);
        editor.commit();

        Toast.makeText(this, "Saved Successfully.", Toast.LENGTH_SHORT).show();
    }
}