There will be two files that will need to be uploaded and they can be found in t
ID: 3877179 • Letter: T
Question
There will be two files that will need to be uploaded and they can be found in the project folder / src / package folders One will be the source file that contains the class definition of the form as well as the logic that you created. This will have the .JAVA extension. The other file will have the same name but will have the .FORM extension. This file contains information regarding which components are used and their properties that have been set using the designer. Both are required before marking can be done.
Design and code a graphical game that allows three players to play a simple board game. This game allows the players to take turns placing their mark on the 8x8 game board. The game is won by the player who successfully places 4 of their marks adjacent to one another in a straight line. The group of marks can be oriented vertically, horizontally or diagonally. Player One Player TwD Player Thre¢ Start a new Game Design the form so that the players can pick the character that will indicate their squares on the game board. Do not allow players to play on the board until all three players have determined their character. For each player's turn devise some method to show whose turn it happens to be and once they select an unused square the turn passes to the next player. Game play continues until any player has 4 adjacent squares or until the board is fullExplanation / Answer
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
open class Game broadens Activity {
gridView;
Item[] gridArray = new Item[16];
ImageAdapter iAdapter;
/*
* Here is the measure of collumns in the application - This is utilized to get the y and
* x position
*/
int columncount = 4;
@Override
secured void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
/4X4 cluster
for (int I = 0; I < 16; i++) {
gridArray[i] = new Item(R.drawable.grey, "dim", I);
}
Gridview = (GridView) findViewById(R.id.gridview);
iAdapter = new ImageAdapter(this, gridArray);
gridview.setAdapter(iAdapter);
gridview.setOnItemClickListener(new OnItemClickListener() {
open void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
/*
* Here is the place we get the clicked position Simply partition the
* position by the columncount (9) to get the x and do likewise
* for the y yet rather change the gap to a modulus which
* will get the rest of: utilization this for the task
*/
int x = position/columncount;
int y = position % columncount;
int c = gridArray[position].nextColor();
/Run the checkWinner strategy that will check if
checkWinner();
((ImageView) v).setImageResource(c);
/*
* If you need to show the collumns/lines not founded on a 0
* record at that point utilize this toast
* Toast.makeText(getApplicationContext(),(x+1) + " +
* (y+1),Toast.LENGTH_SHORT).show(); All this does
*/
Toast.makeText(getApplicationContext(), x + " + y,
Toast.LENGTH_SHORT).show();
}
});
}
@Override
open boolean onCreateOptionsMenu(Menu menu) {
/Inflate the menu; this adds things to the activity bar on the off chance that it is available.
getMenuInflater().inflate(R.menu.main, menu);
return genuine;
}
open void checkWinner() {
/Check for flat misfortune
for (int I = 0; I < 16; I += 4) {
/Check for white
on the off chance that ((gridArray[i].getRDC() == R.drawable.white
&& gridArray[i + 1].getRDC() == R.drawable.white && gridArray[i + 2]
.getRDC() == R.drawable.white)
|| (gridArray[i + 1].getRDC() == R.drawable.white
&& gridArray[i + 2].getRDC() == R.drawable.white && gridArray[i + 3]
.getRDC() == R.drawable.white)) {
Toast.makeText(getApplicationContext(),
"THREE WHITE IN A ROW HORIZONTALLY", Toast.LENGTH_SHORT)
.appear();
Log.d("MyApp", "3 in push on a level plane WHITE");
}
/Check for red
in the event that ((gridArray[i].getRDC() == R.drawable.red
&& gridArray[i + 1].getRDC() == R.drawable.red && gridArray[i + 2]
.getRDC() == R.drawable.red)
|| (gridArray[i + 1].getRDC() == R.drawable.white
&& gridArray[i + 2].getRDC() == R.drawable.red && gridArray[i + 3]
.getRDC() == R.drawable.red)) {
Toast.makeText(getApplicationContext(),
"THREE RED IN A ROW HORIZONTALLY", Toast.LENGTH_SHORT)
.appear();
Log.d("MyApp", "3 in push on a level plane RED");
}
}
/Check for vertical misfortune
for (int I = 0; I <= 7; i++) {
/*
* This for circle is circling through every section and checking if 3 drawables are in succession
*/
/Check for white misfortune
on the off chance that (gridArray[i].getRDC() == R.drawable.white
&& gridArray[i + 4].getRDC() == R.drawable.white
&& gridArray[i + 8].getRDC() == R.drawable.white) {
Toast.makeText(getApplicationContext(),
"THREE WHITE IN A ROW VERTICALLY", Toast.LENGTH_SHORT).show();
Log.d("MyApp", "3 in push vertically WHITE");
}
/Check for red misfortune
on the off chance that (gridArray[i].getRDC() == R.drawable.red
&& gridArray[i + 4].getRDC() == R.drawable.red
&& gridArray[i + 8].getRDC() == R.drawable.red) {
Toast.makeText(getApplicationContext(),
"THREE RED IN A ROW VERTICALLY", Toast.LENGTH_SHORT).show();
Log.d("MyApp", "3 in push vertically RED");
}
}
}
@Override
open boolean onOptionsItemSelected(MenuItem thing) {
Aim I;
switch (item.getItemId()) {
case R.id.homeMenuItem:
I = new Intent(this, Main.class);
startActivity(i);
return genuine;
case R.id.settingMenuItem:
I = new Intent(this, Setting.class);
startActivity(i);
return genuine;
case R.id.highscoreMenuItem:
I = new Intent(this, Highscores.class);
startActivity(i);
return genuine;
case R.id.gamesLabel:
I = new Intent(this, Game.class);
startActivity(i);
return genuine;
case R.id.helpLabel:
I = new Intent(this, help.class);
startActivity(i);
return genuine;
}
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.