How to create a simple Android Game?
Hi, guys!! Today let's see how to build a simple game which I named it as RGB game. If you are new to Android App development I would suggest you go through my previous posts.
I am creating this simple game in Android Studio. It's easy Just follow the steps following. By the end, you are ready with a game. So let's go write the code.
So what is RGB color code?
The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors.An RGB color value is specified with rgb(red,green,blue)
Each parameter defines the intensity of the color as an integer between 0 to 255.
How this Android game works:
There are a total of 3 levels in this game. Easy, Medium & Hard levels. In easy level, there are 3 colors to guess from, 6 and 9 colors for the next colors respectively.
![]() |
Hard Level |
![]() |
Easy Level |
![]() |
Medium Level |
In the hard level, you have 9 colors and you need to guess the correct one with the RGB color code shown on the top of the page.
So, if you want to try this even before going to the coding part, here is the link for apk download. Put this into your mobile if you are seeing this from PC, and mobile users can directly download this into the mobile and install it.
Let's get into coding part now:
First, we will create the project.
So, if you want to try this even before going to the coding part, here is the link for apk download. Put this into your mobile if you are seeing this from PC, and mobile users can directly download this into the mobile and install it.
Let's get into coding part now:
First, we will create the project.

Create a name for the project. I named it Guess RGB.
Select API:17 Jellybean as the minimum SDK for the app. So this is the version that a mobile should minimum have to run your app.
Select Empty activity.
Let the activity name and layout name be default as it is.
activity_main.xml file:
It consists of 3 linear layouts wherein each linear layout we have 3 Card Views and inside of the cards, we have buttons. We will show the layouts according to the level, 1 linear layout for easy level, 2 linear layouts for medium and 3 linear layouts for hard level.dialog_items.xml:
Model class:
The RGB class is a plain old java object(POJO) class. It consists of three double type variables r,g,b and getter and setters for them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RGB { | |
double r,g,b; | |
boolean isrowvisible; | |
public boolean isIsrowvisible() { | |
return isrowvisible; | |
} | |
public void setIsrowvisible(boolean isrowvisible) { | |
this.isrowvisible = isrowvisible; | |
} | |
public double getR() { | |
return r; | |
} | |
public void setR(double r) { | |
this.r = r; | |
} | |
public double getG() { | |
return g; | |
} | |
public void setG(double g) { | |
this.g = g; | |
} | |
public double getB() { | |
return b; | |
} | |
public void setB(double b) { | |
this.b = b; | |
} | |
@Override | |
public String toString() { | |
return "RGB("+ r +"," + g + "," + b + ')'; | |
} | |
} |
Now MainActivity.java:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity{ | |
TextView title; | |
Button c1,c2,c3,c4,c5,c6,c7,c8,c9,level; | |
int pickedcolor; | |
List<RGB>cardcolors,cardcolors2; | |
boolean isrowvisible = false; | |
boolean isrow1visible = false; | |
boolean isIsrow3visible =false; | |
LinearLayout row1,row2,row3; | |
Button playagain; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
c1 = findViewById(R.id.c1b); | |
c2 = findViewById(R.id.c2b); | |
row1 = findViewById(R.id.row1); | |
row2 = findViewById(R.id.row2); | |
c3 = findViewById(R.id.c3b); | |
c7 = findViewById(R.id.c7b); | |
c8 = findViewById(R.id.c8b); | |
c9 = findViewById(R.id.c9b); | |
row3 = findViewById(R.id.row3); | |
level = findViewById(R.id.level); | |
c4 = findViewById(R.id.c4b); | |
c5 = findViewById(R.id.c5b); | |
c6 = findViewById(R.id.c6b); | |
title = findViewById(R.id.rgbcode); | |
playagain = findViewById(R.id.playagain); | |
cardcolors = new ArrayList <>(); | |
cardcolors2 = new ArrayList <>(); | |
row3.setVisibility(View.INVISIBLE); | |
for (int i = 0; i < 6; i++) { | |
RGB rgb = new RGB(); | |
isrow1visible = true; | |
rgb.setR(Math.floor(Math.random() * 256)); | |
rgb.setG(Math.floor(Math.random() * 256)); | |
rgb.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb); | |
Log.d("rgb colors", rgb.toString()); | |
} | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
c4.setBackgroundColor(Color.rgb((int) cardcolors.get(3).getR(), (int) cardcolors.get(3).getG(), (int) cardcolors.get(3).getB())); | |
c5.setBackgroundColor(Color.rgb((int) cardcolors.get(4).getR(), (int) cardcolors.get(4).getG(), (int) cardcolors.get(4).getB())); | |
c6.setBackgroundColor(Color.rgb((int) cardcolors.get(5).getR(), (int) cardcolors.get(5).getG(), (int) cardcolors.get(5).getB())); | |
level.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
final Dialog dialog = new Dialog(MainActivity.this); | |
dialog.setContentView(R.layout.dialog_items); | |
final RadioButton rb1 = dialog.findViewById(R.id.cb1); | |
final RadioButton rb2 = dialog.findViewById(R.id.cb2); | |
final RadioButton rb3 = dialog.findViewById(R.id.cb3); | |
rb1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(rb1.isChecked()){ | |
cardcolors.clear(); | |
dialog.cancel(); | |
isrow1visible = true; | |
row2.setVisibility(View.INVISIBLE); | |
row3.setVisibility(View.INVISIBLE); | |
for (int i = 0; i < 3; i++) { | |
RGB rgb = new RGB(); | |
rgb.setR(Math.floor(Math.random() * 256)); | |
rgb.setG(Math.floor(Math.random() * 256)); | |
rgb.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb); | |
Log.d("rgb 3 colors", rgb.toString()); | |
} | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("Pickedcolor",cardcolors.get(pickedcolor).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
} | |
} | |
}); | |
rb2.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(rb2.isChecked()){ | |
dialog.cancel(); | |
cardcolors.clear(); | |
row2.setVisibility(View.VISIBLE); | |
row3.setVisibility(View.INVISIBLE); | |
for (int i = 0; i < 6; i++) { | |
RGB rgb = new RGB(); | |
rgb.setR(Math.floor(Math.random() * 256)); | |
rgb.setG(Math.floor(Math.random() * 256)); | |
rgb.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb); | |
Log.d("rgb 6 colors", rgb.toString()); | |
} | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("Pickedcolor",cardcolors.get(pickedcolor).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
c4.setBackgroundColor(Color.rgb((int) cardcolors.get(3).getR(), (int) cardcolors.get(3).getG(), (int) cardcolors.get(3).getB())); | |
c5.setBackgroundColor(Color.rgb((int) cardcolors.get(4).getR(), (int) cardcolors.get(4).getG(), (int) cardcolors.get(4).getB())); | |
c6.setBackgroundColor(Color.rgb((int) cardcolors.get(5).getR(), (int) cardcolors.get(5).getG(), (int) cardcolors.get(5).getB())); | |
} | |
} | |
}); | |
rb3.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(row3.getVisibility()==View.INVISIBLE) { | |
dialog.cancel(); | |
cardcolors.clear(); | |
isIsrow3visible = true; | |
row3.setVisibility(View.VISIBLE); | |
row2.setVisibility(View.VISIBLE); | |
row1.setVisibility(View.VISIBLE); | |
for (int i = 0; i < 9; i++) { | |
RGB rgb = new RGB(); | |
rgb.setR(Math.floor(Math.random() * 256)); | |
rgb.setG(Math.floor(Math.random() * 256)); | |
rgb.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb); | |
Log.d("rgb 9 colors", rgb.toString()); | |
} | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("Pickedcolor", cardcolors.get(pickedcolor).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
c4.setBackgroundColor(Color.rgb((int) cardcolors.get(3).getR(), (int) cardcolors.get(3).getG(), (int) cardcolors.get(3).getB())); | |
c5.setBackgroundColor(Color.rgb((int) cardcolors.get(4).getR(), (int) cardcolors.get(4).getG(), (int) cardcolors.get(4).getB())); | |
c6.setBackgroundColor(Color.rgb((int) cardcolors.get(5).getR(), (int) cardcolors.get(5).getG(), (int) cardcolors.get(5).getB())); | |
c7.setVisibility(View.VISIBLE); | |
c8.setVisibility(View.VISIBLE); | |
c9.setVisibility(View.VISIBLE); | |
c7.setBackgroundColor(Color.rgb((int) cardcolors.get(6).getR(), (int) cardcolors.get(6).getG(), (int) cardcolors.get(6).getB())); | |
c8.setBackgroundColor(Color.rgb((int) cardcolors.get(7).getR(), (int) cardcolors.get(7).getG(), (int) cardcolors.get(7).getB())); | |
c9.setBackgroundColor(Color.rgb((int) cardcolors.get(8).getR(), (int) cardcolors.get(8).getG(), (int) cardcolors.get(8).getB())); | |
} | |
} | |
}); | |
dialog.setTitle("Select a level"); | |
dialog.show(); | |
} | |
}); | |
c1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(0).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(0).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(0).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c1.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c2.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(1).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(1).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(1).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c1.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c3.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(2).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(2).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(2).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c3.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c4.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(3).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(3).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(3).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c4.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c5.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(4).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(4).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(4).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c5.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c6.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(5).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(5).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(5).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c6.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c7.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(6).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(6).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(6).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c7.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c8.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(7).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(7).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(7).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
c9.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c8.setVisibility(View.GONE); | |
} | |
} | |
}); | |
c9.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (cardcolors.get(8).getR() == cardcolors.get(pickedcolor).getR() && cardcolors.get(8).getG() == cardcolors.get(pickedcolor).getG() | |
&& cardcolors.get(8).getB() == cardcolors.get(pickedcolor).getB()) { | |
Toast.makeText(MainActivity.this, "yes they are equal", Toast.LENGTH_SHORT).show(); | |
c2.setVisibility(View.GONE); | |
c3.setVisibility(View.GONE); | |
c4.setVisibility(View.GONE); | |
c5.setVisibility(View.GONE); | |
c1.setVisibility(View.GONE); | |
c7.setVisibility(View.GONE); | |
c8.setVisibility(View.GONE); | |
c6.setVisibility(View.GONE); | |
} else { | |
Toast.makeText(MainActivity.this, "choose another one", Toast.LENGTH_SHORT).show(); | |
c9.setVisibility(View.GONE); | |
} | |
} | |
}); | |
playagain.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(c4.getVisibility()==View.INVISIBLE&&c7.getVisibility()==View.INVISIBLE){ | |
cardcolors.clear(); | |
for (int i = 0; i < 3; i++) { | |
RGB rgb2 = new RGB(); | |
rgb2.setR(Math.floor(Math.random() * 256)); | |
rgb2.setG(Math.floor(Math.random() * 256)); | |
rgb2.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb2); | |
} | |
Log.d("playagain 3 colors",cardcolors.toString()); | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("pickedcolor", cardcolors.get(pickedcolor).toString()); | |
Log.d("firstlistafterplayagain", cardcolors.get(0).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setVisibility(View.VISIBLE); | |
c2.setVisibility(View.VISIBLE); | |
c3.setVisibility(View.VISIBLE); | |
}else | |
if(row3.getVisibility()==View.VISIBLE){ | |
cardcolors.clear(); | |
Toast.makeText(MainActivity.this, ""+isrowvisible, Toast.LENGTH_SHORT).show(); | |
for (int i = 0; i < 9; i++) { | |
RGB rgb2 = new RGB(); | |
rgb2.setR(Math.floor(Math.random() * 256)); | |
rgb2.setG(Math.floor(Math.random() * 256)); | |
rgb2.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb2); | |
} | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
c4.setBackgroundColor(Color.rgb((int) cardcolors.get(3).getR(), (int) cardcolors.get(3).getG(), (int) cardcolors.get(3).getB())); | |
c5.setBackgroundColor(Color.rgb((int) cardcolors.get(4).getR(), (int) cardcolors.get(4).getG(), (int) cardcolors.get(4).getB())); | |
c6.setBackgroundColor(Color.rgb((int) cardcolors.get(5).getR(), (int) cardcolors.get(5).getG(), (int) cardcolors.get(5).getB())); | |
c7.setBackgroundColor(Color.rgb((int) cardcolors.get(6).getR(), (int) cardcolors.get(6).getG(), (int) cardcolors.get(6).getB())); | |
c8.setBackgroundColor(Color.rgb((int) cardcolors.get(7).getR(), (int) cardcolors.get(7).getG(), (int) cardcolors.get(7).getB())); | |
c9.setBackgroundColor(Color.rgb((int) cardcolors.get(8).getR(), (int) cardcolors.get(8).getG(), (int) cardcolors.get(8).getB())); | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("pickedcolor", cardcolors.get(pickedcolor).toString()); | |
Log.d("firstlistafterplayagai", cardcolors.get(0).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setVisibility(View.VISIBLE); | |
c2.setVisibility(View.VISIBLE); | |
c3.setVisibility(View.VISIBLE); | |
c4.setVisibility(View.VISIBLE); | |
c5.setVisibility(View.VISIBLE); | |
c6.setVisibility(View.VISIBLE); | |
c7.setVisibility(View.VISIBLE); | |
c8.setVisibility(View.VISIBLE); | |
c9.setVisibility(View.VISIBLE); | |
}else { | |
cardcolors.clear(); | |
for (int i = 0; i < 6; i++) { | |
RGB rgb2 = new RGB(); | |
rgb2.setR(Math.floor(Math.random() * 256)); | |
rgb2.setG(Math.floor(Math.random() * 256)); | |
rgb2.setB(Math.floor(Math.random() * 256)); | |
cardcolors.add(rgb2); | |
Log.d("rgb colors", rgb2.toString()); | |
} | |
c1.setBackgroundColor(Color.rgb((int) cardcolors.get(0).getR(), (int) cardcolors.get(0).getG(), (int) cardcolors.get(0).getB())); | |
c2.setBackgroundColor(Color.rgb((int) cardcolors.get(1).getR(), (int) cardcolors.get(1).getG(), (int) cardcolors.get(1).getB())); | |
c3.setBackgroundColor(Color.rgb((int) cardcolors.get(2).getR(), (int) cardcolors.get(2).getG(), (int) cardcolors.get(2).getB())); | |
c4.setBackgroundColor(Color.rgb((int) cardcolors.get(3).getR(), (int) cardcolors.get(3).getG(), (int) cardcolors.get(3).getB())); | |
c5.setBackgroundColor(Color.rgb((int) cardcolors.get(4).getR(), (int) cardcolors.get(4).getG(), (int) cardcolors.get(4).getB())); | |
c6.setBackgroundColor(Color.rgb((int) cardcolors.get(5).getR(), (int) cardcolors.get(5).getG(), (int) cardcolors.get(5).getB())); | |
pickedcolor = (int) Math.floor(Math.random() * cardcolors.size()); | |
Log.d("pickedcolor", cardcolors.get(pickedcolor).toString()); | |
Log.d("firstlistafterplayagai", cardcolors.get(0).toString()); | |
title.setText("Guess this " + cardcolors.get(pickedcolor).toString()); | |
c1.setVisibility(View.VISIBLE); | |
c2.setVisibility(View.VISIBLE); | |
c3.setVisibility(View.VISIBLE); | |
c4.setVisibility(View.VISIBLE); | |
c5.setVisibility(View.VISIBLE); | |
c6.setVisibility(View.VISIBLE); | |
} | |
} | |
}); | |
} | |
} |
That's it: you made an Android Game.
Thank you, Happy learning.
Comments
Post a Comment