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