Question

1. SUMMARY This project will simulate the card game Concentration for one player. In Concentration, all cards, or pictures in this case, are upside down. Two cards are chosen, and if they match they are taken out of the game. If they dont match in this version, one allowed fail is decremented. The player starts with a set number of allowed fails, such as 8. This project will involve the following: 2 Activities hooked together by an Intent. TableLayout Image Views. User OnClick event handling. 2. DETAILS a. Home Activity screen. i. Shows Wins, Losses, and highest number of Allowed Fails eft. ii. Shows a button to begin game. 1. Game Activity is started by expecting values back via its Intent. iii. Handles return from Game Activity upon GAME END. 1. If return is -1, then Losses number goes up 1. 2. If return is 0 or more, then Wins is incremented and the number returned from the game Activity replaces highest Allowed Fails left number if higher b. Game Activity. i. Displays 4x4 grid of pictures using the TableLayout type. ii. The pictures will be ImageView view types and each will have a unique ID. 1. There are 3 sets of pictures for each of the 16 ImageViews. a. The upside down pic, which can be a pic or something like that. b. The pic itself, revealed when the user clicks the upside down pic c. The completed pic, which can be a check mark, green light, etc. iii. The Activity java file will handle onClick events on the pictures 1. On first of two grid clicks: The picture is shown. 2. On second of two grid clicks: The second picture is shown for about 3 seconds or you can simply show a Continue button, then after the timer has ticked off 3 seconds or the user clicks the button (whichever way you designed it)...
media%2Fbe3%2Fbe35bd9c-eb95-4bf3-82f6-d6Please 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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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> 
Add a comment
Know the answer?
Add Answer to:
Please help me with this project by using Android Studio. I need to know the xml...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help developing this app using java in android studio Assignment: Tic-Tac-Toe app User interface...

    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...

  • Project 03 (Chapter 04 Multiple Activities) Code an app in android studio that does the following:...

    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...

  • This is python3. Please help me out. Develop the following GUI interface to allow the user...

    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...

    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...

    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...

  • In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST...

    In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST use GUI, that means all user input must be through the windows. The "first window" is the window on the top left of the following picture. Add 5 more items to be purchased. Search is accessed from second window, top right. Thw third window is the bottom left, and the fourth window is the bottom right. The program MUST CONTAIN EVERYTHING IN THE PICTURES....

  • Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows...

    Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows users to register and login into the system. The focus of this project is for you to create an app with several activities and has data validation. You should have for your app: A welcome screen (splash screen) with your app name and a picture. You should then move to a screen that asks the user for either to log in or to register....

  • (Mobile-Android Studio) Hello. Thank you for coming to help me:) I am using the Andriod studio...

    (Mobile-Android Studio) Hello. Thank you for coming to help me:) I am using the Andriod studio on mac. and using Java code to develop. and Please start with basic activity with constraints layout (not empty). (audio file is not given, let's say there any audio file). I just would like to see the codes how it works. Thank you very much. I would like to know how to write a program that includes two buttons called plays Play and Stop....

  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • ***Java Project*** Please upload the entire code and attach the screenshots of the code. The screenshots help me to write the code, so please attach that. Thank you so much. If you could use the comme...

    ***Java Project*** Please upload the entire code and attach the screenshots of the code. The screenshots help me to write the code, so please attach that. Thank you so much. If you could use the comment to explain the code, it would be perfect! Thank you so much~ Design and code a Swing GUl for a two-player tic-tac-toe (noughts and crosses) game on a 3 x 3 game board. The JFrame should use a BorderLayout with a JLabel in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT