Simple Android Game application
Simple Android Game application
Using android studio I developed a simple game application, which can show images and let the select correct image according to name of the object audio file.
This was my first android experience and it was little bit hard when I trying to do it first.
After learning the basic stuff in general android code, specially in game application, there are many requirements we need to know both back end and front end.
Back End: MBaaS (Mobile Back end as a Service)
ex:- Fire Base
Dream Factory
AppStax
- how to read the documentation
- basics of internet communication
- basics of databases and relational data.
- understand the basics of JSON
- understand the basics of file storage.
Front End: Native Android Client
- Java
- Android, Android Studio, XML
- Material Design
Based on those requirements I have developed below code to get my outcome.
Simply what happening here is displaying two different objects, while playing a audio file by pronouncing the name of one of these object. Then let the user to select correct picture. Correct and wrong answers will recorded.
package ehs.bluethoothcontrolrobot;
import
android.media.MediaPlayer;
import
android.os.Bundle;
import
android.support.v7.app.AppCompatActivity;
import
android.view.View;
import
android.widget.ImageButton;
import
android.widget.TextView;
public class GameActivity extends AppCompatActivity {
TextView
txtView;
MediaPlayer
myPlayer;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_game);
myPlayer = MediaPlayer.create(this, R.raw.bottle); txtView= (TextView) findViewById(R.id.textresult);
/* Button button = (Button)
findViewById(R.id.butplay); button.setOnClickListener(new
View.OnClickListener() { @Override
public void
onClick(View v) { playMusic(View v);
}
});*/
ImageButton img1
= (ImageButton)findViewById(R.id.butbottle);
img1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){ result(1);
}
});
ImageButton img2
= (ImageButton)findViewById(R.id.butpencil); img2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{ result(2);
}
});
}
void result(int x){ txtView.setEnabled(true); if(x==1){
txtView.setText("Correct");
}
else if(x==2){ txtView.setText("Incorrect");
}
}
@Override
protected void onPause () {
super.onPause(); myPlayer.release();
}
public void playMusic(View view) {
myPlayer.start();
}
}
To do this I have to learn about inbuilt media player class and how to access to the files in the local directory. This android application development was a fresh experience hence this is my 1st time in android developing

Comments
Post a Comment