Please help me
with this project by using Android Studio. I need to know the xml
and the java activities in both activities. Also the manifest
activity. I appreciate the effort and I'll rate you with 5
stars.Hi, This is what I could do in 2 hours .
MainActivity File :
package com.avi.samplememory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by anushab on 3/19/2017.
*/
public class MainActivity extends Activity {
Button startGame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startGame = (Button)findViewById(R.id.button);
startGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,Manager.class);
startActivity(intent);
}
});
}
}
Main activity xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Start Game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_weight="1" />
</LinearLayout>
Manager Activity :
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class Manager extends Activity {
private static int ROW_COUNT = -1;
private static int COL_COUNT = -1;
private Context context;
private Drawable backImage;
private int [] [] cards;
private List<Drawable> images;
private Card firstCard;
private Card seconedCard;
private ButtonListener buttonListener;
private static Object lock = new Object();
int turns =0;
private TableLayout mainTable;
private UpdateCardsHandler handler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new UpdateCardsHandler();
loadImages();
setContentView(R.layout.main);
backImage = getResources().getDrawable(R.drawable.icon);
buttonListener = new ButtonListener();
mainTable = (TableLayout)findViewById(R.id.TableLayout03);
context = mainTable.getContext();
newGame(4,4);
}
private void newGame(int c, int r) {
ROW_COUNT = r;
COL_COUNT = c;
cards = new int [COL_COUNT] [ROW_COUNT];
mainTable.removeView(findViewById(R.id.TableRow01));
mainTable.removeView(findViewById(R.id.TableRow02));
TableRow tr = ((TableRow)findViewById(R.id.TableRow03));
tr.removeAllViews();
mainTable = new TableLayout(context);
tr.addView(mainTable);
for (int y = 0; y < ROW_COUNT; y++) {
mainTable.addView(createRow(y));
}
firstCard=null;
loadCards();
turns=0;
((TextView)findViewById(R.id.tv1)).setText("Tries: "+turns);
}
private void loadImages() {
images = new ArrayList<Drawable>();
images.add(getResources().getDrawable(R.drawable.card1));
images.add(getResources().getDrawable(R.drawable.card2));
images.add(getResources().getDrawable(R.drawable.card3));
images.add(getResources().getDrawable(R.drawable.card4));
images.add(getResources().getDrawable(R.drawable.card5));
images.add(getResources().getDrawable(R.drawable.card6));
images.add(getResources().getDrawable(R.drawable.card7));
images.add(getResources().getDrawable(R.drawable.card8));
images.add(getResources().getDrawable(R.drawable.card9));
images.add(getResources().getDrawable(R.drawable.card10));
images.add(getResources().getDrawable(R.drawable.card11));
images.add(getResources().getDrawable(R.drawable.card12));
images.add(getResources().getDrawable(R.drawable.card13));
images.add(getResources().getDrawable(R.drawable.card14));
images.add(getResources().getDrawable(R.drawable.card15));
images.add(getResources().getDrawable(R.drawable.card16));
images.add(getResources().getDrawable(R.drawable.card17));
images.add(getResources().getDrawable(R.drawable.card18));
images.add(getResources().getDrawable(R.drawable.card19));
images.add(getResources().getDrawable(R.drawable.card20));
images.add(getResources().getDrawable(R.drawable.card21));
}
private void loadCards(){
try{
int size = ROW_COUNT*COL_COUNT;
Log.i("loadCards()","size=" + size);
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0;i<size;i++){
list.add(new Integer(i));
}
Random r = new Random();
for(int i=size-1;i>=0;i--){
int t=0;
if(i>0){
t = r.nextInt(i);
}
t=list.remove(t).intValue();
cards[i%COL_COUNT][i/COL_COUNT]=t%(size/2);
Log.i("loadCards()", "card["+(i%COL_COUNT)+
"]["+(i/COL_COUNT)+"]=" + cards[i%COL_COUNT][i/COL_COUNT]);
}
}
catch (Exception e) {
Log.e("loadCards()", e+"");
}
}
private TableRow createRow(int y){
TableRow row = new TableRow(context);
row.setHorizontalGravity(Gravity.CENTER);
for (int x = 0; x < COL_COUNT; x++) {
row.addView(createImageButton(x,y));
}
return row;
}
private View createImageButton(int x, int y){
Button button = new Button(context);
button.setBackgroundDrawable(backImage);
button.setId(100*x+y);
button.setOnClickListener(buttonListener);
return button;
}
class ButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
synchronized (lock) {
if(firstCard!=null && seconedCard != null){
return;
}
int id = v.getId();
int x = id/100;
int y = id%100;
if(turns > 18){
Toast.makeText(Manager.this,"Lost the game",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Manager.this,MainActivity.class);
startActivity(intent);
}else{
turnCard((Button)v,x,y);
}
}
}
private void turnCard(Button button,int x, int y) {
button.setBackgroundDrawable(images.get(cards[x][y]));
if(firstCard==null){
firstCard = new Card(button,x,y);
}
else{
if(firstCard.x == x && firstCard.y == y){
return; //the user pressed the same card
}
seconedCard = new Card(button,x,y);
turns++;
((TextView)findViewById(R.id.tv1)).setText("Tries: "+turns);
TimerTask tt = new TimerTask() {
@Override
public void run() {
try{
synchronized (lock) {
handler.sendEmptyMessage(0);
}
}
catch (Exception e) {
Log.e("E1", e.getMessage());
}
}
};
Timer t = new Timer(false);
t.schedule(tt, 1300);
}
}
}
class UpdateCardsHandler extends Handler{
@Override
public void handleMessage(Message msg) {
synchronized (lock) {
checkCards();
}
}
public void checkCards(){
if(cards[seconedCard.x][seconedCard.y] == cards[firstCard.x][firstCard.y]){
firstCard.button.setVisibility(View.INVISIBLE);
seconedCard.button.setVisibility(View.INVISIBLE);
}
else {
seconedCard.button.setBackgroundDrawable(backImage);
firstCard.button.setBackgroundDrawable(backImage);
}
firstCard=null;
seconedCard=null;
}
}
}
Manager activity xml :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout03"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:id="@+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
</TableRow>
<TableRow
android:id="@+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10sp">
</TextView>
</TableRow>
<TableRow
android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
</TableRow>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
</TableRow>
<TableRow
android:id="@+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
</TableRow>
</TableLayout>
Card Java file :
import android.widget.Button;
public class Card{
public int x;
public int y;
public Button button;
public Card(Button button, int x,int y) {
this.x = x;
this.y=y;
this.button=button;
}
}
Android Manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aviy.samplememory"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.aviy.samplememory.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.aviy.samplememory.Manager"></activity>
</application>
<uses-sdk android:minSdkVersion="2" />
</manifest>
Please help me with this project by using Android Studio. I need to know the xml...
Project 03 (Chapter 04 Multiple Activities) Code an app in android studio that does the following: There is one button in the middle of the screen. The button color is green and its text says 0. When the user clicks on the button GO, we go to a second activity that is red and has one button in the middle of the screen; its text says BACK. When the user clicks on that button, we go back to the first...
I need help developing this app using java in android studio Assignment: Tic-Tac-Toe app User interface Operation The app allows the user to play a game of Tic-Tac-Toe. The user can click the New Game button at any time to start a new game. The app displays other messages to the user as the game progresses such as (1) whose turn it is, (2) if a player wins, and (3) if the game ends in a tie. Specifications The app...
This is python3. Please help me out.
Develop the following GUI interface to allow the user to specify
the number of rows and number of columns of cards to be shown to
the user. Show default values 2 and 2 for number of rows and number
of columns. The buttons "New Game" and "Turn Over" span two
column-cells each.
Fig 1. The GUI when the program first starts.
When the user clicks the "New Game" button, the program will
read...
If anyone here is a Java and Android Studio expert please I really need help fulfilling the requirements needed to make a Rock Paper Scissors game. I mainly need Java code to complete it I will post what I have so far I don't have much time left please if anyone can help me I would really appreciate it. Here's what the app is supposed to do... The player should be able to select either Rock, Paper, or Scissors.The app...
programming language c++
its a project if anyone can help me it's will be
appreciated thnk u.
u have to create a code based on the information im giving
u
you can do it in 1 or 2 day i can wait
1:26 #WW 2.53% Example: A user starts with 1000 points. Game #1 - user chooses to risk 200 points. User wins game (beats the dealer). User now has 1200 points. Game #2 - user chooses to risk 500...
Please I need your help I have the code below but I need to add one thing, after player choose "No" to not play the game again, Add a HELP button or page that displays your name, the rules of the game and the month/day/year when you finished the implementation. import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; import java.util.Random; public class TicTacToe extends JFrame implements ChangeListener, ActionListener { private JSlider slider; private JButton oButton, xButton; private Board...
please help me fix this. I'm getting it all mixed up in user defined functions. here's the question. This week we'll write a C program that lets the user play the game of Rock, Paper, Scissors against the computer. Your program will call a user-defined function named display_rules that displays the rules of the game. It then proceeds to play the game. To determine the winner, your program will call another user- defined function called determine_winner that takes two integer...
I am just curious about this question... please can you answer with applying indent and space clearly. Furthermore, can you make answer shortly as possible..? This is a python question Question 6.34 The two-player card game war is played with a standard deck of 52 cards. A shuffled deck is evenly split among the two players who keep their decks face-down. The game consists of battles until one of the players runs out of cards. In a battle, each player...
please help me with the project it's an embedded system
project and i need a help with
the code (for setting part especially) the code should be in C
language not C++ and the mbed
application board will be used. thanks in advance
:)
Note: mbed development board are used here with the mbed
application board
Design and implement an Air Conditioner Controller System to control automatically an air conditioner based on the ambient tempreture and surrounding light (Daytime/Nighttime). The...
I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...