• Solo Great Sale

    Solo Great Sale Powered By Circle Card 2015

  • Solo Great Sale

    Solo Great Sale Powered By Circle Card 2015

  • Oracle Java Magazine

    As Cover of Oracle Java Magazine March/April 2012 issue

  • Launching jDuchess Indonesia

    Gunadarma University 2011

    www.jduchess.or.id

  • Launching jDuchess Indonesia

    Gunadarma University 2011

    www.jduchess.or.id

  • Launching Java 7

    Binus University 2011

  • Eclipse Democamp

    Microsoft Indonesia 2011

  • Oracle Academy

    SMK PGRI 3 Malang 2010

  • Launching JENI 2.0

    ITB Bandung 2012

  • Oracle Academy

    SMK PGRI 3 Malang 2010

  • Java and Android Roadshow

    SMK PGRI 3 Malang 2012

  • Oracle Academy

    SMK PGRI 3 Malang 2010

  • Launching JENI 2.0

    ITB Bandung 2012

  • Oracle Academy

    SMK PGRI 3 Malang 2011

  • Java and Android Roadshow

    SMK Plus Darussalam Kediri 2012

  • Oracle Academy Seminar

    LIKMI Bandung, 2012

  • Oracle Academy Seminar

    Indonesia University, 2012

  • Seminar Android

    Universitas Budi Luhur 2010

  • Java and Android Roadshow

    SMK Hasan Kafrawi Jepara 2012

  • Sosialisasi Kurikulum 2013

    LPMP Surabaya 2013

  • IOSA

    Indonesia Open Source Award 2011

  • Java Training

    SMKN 02 Sukabumi 2010

  • Sosialisasi Kurikulum

    SMKN 01 Tulungagung 2011

  • Sosialisasi Kurikulum 2013

    LPMP Surabaya 2013

Monday, July 4, 2011

Posted by Netty Herawaty
| 1:57 PM

Game ABC

Game ABC adalah game android sederhana untuk membantu anak – anak menghafal dan mengenali abjad dari A – Z. 

Membuat Game ABC

Untuk membuat game tersebut ikuti langkah – langkah dibawah ini :

Menyimpan Gambar Game

Simpan semua file gambar yang akan ditampilkan pada folder res/drawable

Menyimpan Suara Game

Simpan semua file suara yang akan ditampilkan pada folder res/raw


Membuat Layout

Buat file main.xml pada folder res/layout untuk membuat layout atau UI game

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/background"

android:orientation="vertical" >



<GridView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/gridView"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:columnWidth="@dimen/column_width_grid"

android:gravity="center"

android:numColumns="auto_fit"

android:stretchMode="columnWidth" >

</GridView>



<LinearLayout

android:id="@+id/InnerRelativeLayout"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom"

android:orientation="horizontal" >



<Button

android:id="@+id/letter_btn"

style="@style/main_menu_btnTop"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:background="@drawable/blue_menu_btn"

android:text="@string/letter_label" />



<Button

android:id="@+id/words_btn"

style="@style/main_menu_btnTop"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:background="@drawable/blue_menu_btn"

android:text="@string/words_label" />

</LinearLayout>

Membuat Class Java

Buat class Huruf_Gambar.java yang berisi kode untuk memasukkan semua file gambar yang sudah disimpan pada folder res/drawable

package org.meruvian.androidgame.abcgame;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
public class Huruf_Gambar extends BaseAdapter {
private Context context;
private final String[] hurufgambar;
public Huruf_Gambar(Context context, String[] hurufgambars) {
this.context = context;
this.hurufgambar = hurufgambars;
}
getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
gridView = inflater.inflate(R.layout.mobile, null);
ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
String gambar = hurufgambar[position];
if (gambar.equals("a")) {
imageView.setImageResource(R.drawable.a);
} else if (gambar.equals("b")) {
imageView.setImageResource(R.drawable.b);
} else if (gambar.equals("c")) {
imageView.setImageResource(R.drawable.c);
} else if (gambar.equals("d")) {
imageView.setImageResource(R.drawable.d);
} else if (gambar.equals("e")) {
imageView.setImageResource(R.drawable.e);
} else if (gambar.equals("f")) {
imageView.setImageResource(R.drawable.f);
} else if (gambar.equals("g")) {
imageView.setImageResource(R.drawable.g);
} else if (gambar.equals("h")) {
imageView.setImageResource(R.drawable.h);
} else if (gambar.equals("i")) {
imageView.setImageResource(R.drawable.i);
} else if (gambar.equals("j")) {
imageView.setImageResource(R.drawable.j);
} else if (gambar.equals("k")) {
imageView.setImageResource(R.drawable.k);
} else if (gambar.equals("l")) {
imageView.setImageResource(R.drawable.l);
} else if (gambar.equals("m")) {
imageView.setImageResource(R.drawable.m);
} else if (gambar.equals("n")) {
imageView.setImageResource(R.drawable.n);
} else if (gambar.equals("o")) {
imageView.setImageResource(R.drawable.o);
} else if (gambar.equals("p")) {
imageView.setImageResource(R.drawable.p);
} else if (gambar.equals("q")) {
imageView.setImageResource(R.drawable.q);
} else if (gambar.equals("r")) {
imageView.setImageResource(R.drawable.r);
} else if (gambar.equals("s")) {
imageView.setImageResource(R.drawable.s);
} else if (gambar.equals("t")) {
imageView.setImageResource(R.drawable.t);
} else if (gambar.equals("u")) {
imageView.setImageResource(R.drawable.u);
} else if (gambar.equals("v")) {
imageView.setImageResource(R.drawable.v);
} else if (gambar.equals("w")) {
imageView.setImageResource(R.drawable.w);
} else if (gambar.equals("x")) {
imageView.setImageResource(R.drawable.x);
} else if (gambar.equals("y")) {
imageView.setImageResource(R.drawable.y);
} else if (gambar.equals("z")) {
imageView.setImageResource(R.drawable.z);
}
} else {
gridView = (View) convertView;
}
return gridView;
}
public int getCount() {
return hurufgambar.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
}

Kemudian buat kelas Huruf_Suara.java yang berisi kode untuk memasukkan suara dan method OnItemClickListener() sehingga ketika gambar di klik akan mengeluarkan

package org.meruvian.androidgame.abcgame;

import android.app.Activity;

import android.content.Intent;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.widget.AdapterView;

import android.widget.Button;

import android.widget.GridView;

import android.widget.Toast;

import android.widget.AdapterView.OnItemClickListener;

public class Huruf_sr extends Activity {

GridView grid;

Button huruf, kata;

static final String[] abc = new String[] { "a", "b", "c",

"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",

"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

final MediaPlayer sr_a = MediaPlayer.create(this, R.raw.a);

final MediaPlayer sr_b = MediaPlayer.create(this, R.raw.b);

final MediaPlayer sr_c = MediaPlayer.create(this, R.raw.c);

final MediaPlayer sr_d = MediaPlayer.create(this, R.raw.d);

final MediaPlayer sr_e = MediaPlayer.create(this, R.raw.e);

final MediaPlayer sr_f = MediaPlayer.create(this, R.raw.f);

final MediaPlayer sr_g = MediaPlayer.create(this, R.raw.g);

final MediaPlayer sr_h = MediaPlayer.create(this, R.raw.h);

final MediaPlayer sr_i = MediaPlayer.create(this, R.raw.i);

final MediaPlayer sr_j = MediaPlayer.create(this, R.raw.j);

final MediaPlayer sr_k = MediaPlayer.create(this, R.raw.k);

final MediaPlayer sr_l = MediaPlayer.create(this, R.raw.l);

final MediaPlayer sr_m = MediaPlayer.create(this, R.raw.m);

final MediaPlayer sr_n = MediaPlayer.create(this, R.raw.n);

final MediaPlayer sr_o = MediaPlayer.create(this, R.raw.o);

final MediaPlayer sr_p = MediaPlayer.create(this, R.raw.p);

final MediaPlayer sr_q = MediaPlayer.create(this, R.raw.q);

final MediaPlayer sr_r = MediaPlayer.create(this, R.raw.r);

final MediaPlayer sr_s = MediaPlayer.create(this, R.raw.s);

final MediaPlayer sr_t = MediaPlayer.create(this, R.raw.t);

final MediaPlayer sr_u = MediaPlayer.create(this, R.raw.u);

final MediaPlayer sr_v = MediaPlayer.create(this, R.raw.v);

final MediaPlayer sr_w = MediaPlayer.create(this, R.raw.w);

final MediaPlayer sr_x = MediaPlayer.create(this, R.raw.x);

final MediaPlayer sr_y = MediaPlayer.create(this, R.raw.y);

final MediaPlayer sr_z = MediaPlayer.create(this, R.raw.z);

grid = (GridView) findViewById(R.id.gridView);

grid.setAdapter(new Huruf_Gambar(this, abc));

kata = (Button) findViewById(R.id.words_btn);

kata.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Intent mainIntent = new Intent(Huruf_sr.this,

Kata_sr.class);

startActivity(mainIntent);

}

});

grid.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View v,

int position, long id) {

Toast.makeText(getApplicationContext(),

abc[position],

Toast.LENGTH_SHORT).show();

String alphabet = abc[position];

if (alphabet.equalsIgnoreCase("a")) {

sr_a.start();

} else if (alphabet.equalsIgnoreCase("b")) {

sr_b.start();

} else if (alphabet.equalsIgnoreCase("c")) {

sr_c.start();

} else if (alphabet.equalsIgnoreCase("d")) {

sr_d.start();

} else if (alphabet.equalsIgnoreCase("e")) {

sr_e.start();

} else if (alphabet.equalsIgnoreCase("f")) {

sr_f.start();

} else if (alphabet.equalsIgnoreCase("g")) {

sr_g.start();

} else if (alphabet.equalsIgnoreCase("h")) {

sr_h.start();

} else if (alphabet.equalsIgnoreCase("i")) {

sr_i.start();

} else if (alphabet.equalsIgnoreCase("j")) {

sr_j.start();

} else if (alphabet.equalsIgnoreCase("k")) {

sr_k.start();

} else if (alphabet.equalsIgnoreCase("l")) {

sr_l.start();

} else if (alphabet.equalsIgnoreCase("m")) {

sr_m.start();

} else if (alphabet.equalsIgnoreCase("n")) {

sr_n.start();

} else if (alphabet.equalsIgnoreCase("o")) {

sr_o.start();

} else if (alphabet.equalsIgnoreCase("p")) {

sr_p.start();

} else if (alphabet.equalsIgnoreCase("q")) {

sr_q.start();

} else if (alphabet.equalsIgnoreCase("r")) {

sr_r.start();

} else if (alphabet.equalsIgnoreCase("s")) {

sr_s.start();

} else if (alphabet.equalsIgnoreCase("t")) {

sr_t.start();

} else if (alphabet.equalsIgnoreCase("u")) {

sr_u.start();

} else if (alphabet.equalsIgnoreCase("v")) {

sr_v.start();

} else if (alphabet.equalsIgnoreCase("w")) {

sr_w.start();

} else if (alphabet.equalsIgnoreCase("x")) {

sr_x.start();

} else if (alphabet.equalsIgnoreCase("y")) {

sr_y.start();

} else if (alphabet.equalsIgnoreCase("z")) {

sr_z.start();

}

}

});

}

} 

Hasil contoh Game ABC

Jalankan project ABC Game dan hasilnya akan tampil seperti dibawah ini


Ketika salah satu dari huruf abjad di klik  maka akan keluar mengeluarkan suara



Reactions: