Created
March 6, 2020 04:45
-
-
Save efturtle/46dc7b633855aa9d4c0eec8ee8005f4a to your computer and use it in GitHub Desktop.
Memory Letter Game
This file contains hidden or 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
| package com.example.letterflipgame; | |
| import androidx.appcompat.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import java.util.Random; | |
| public class MainActivity extends AppCompatActivity { | |
| String[]letters = new String[]{"A","A","B","B","C","C","D","D"}; | |
| Button buttonA,buttonA1,buttonB,buttonB1,buttonC,buttonC1,buttonD,buttonD1,reset1; | |
| boolean bandera1 = false, bandera2 = false; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| init(); | |
| } | |
| public void init(){ | |
| buttonA = (Button)findViewById(R.id.button4); | |
| buttonB = (Button)findViewById(R.id.button); | |
| buttonC = (Button)findViewById(R.id.button2); | |
| buttonD = (Button)findViewById(R.id.button3); | |
| buttonA1 = (Button)findViewById(R.id.button9); | |
| buttonB1 = (Button)findViewById(R.id.button11); | |
| buttonC1 = (Button)findViewById(R.id.button12); | |
| buttonD1 = (Button)findViewById(R.id.button13); | |
| reset1 = (Button)findViewById(R.id.reset1); | |
| buttonA.setVisibility(View.VISIBLE); | |
| buttonA1.setVisibility(View.VISIBLE); | |
| buttonB.setVisibility(View.VISIBLE); | |
| buttonB1.setVisibility(View.VISIBLE); | |
| buttonC.setVisibility(View.VISIBLE); | |
| buttonC1.setVisibility(View.VISIBLE); | |
| buttonD.setVisibility(View.VISIBLE); | |
| buttonD1.setVisibility(View.VISIBLE); | |
| letters = shuffleArray(letters); | |
| buttonA.setText(letters[0]); | |
| buttonB.setText(letters[1]); | |
| buttonC.setText(letters[2]); | |
| buttonD.setText(letters[3]); | |
| buttonA1.setText(letters[4]); | |
| buttonB1.setText(letters[5]); | |
| buttonC1.setText(letters[6]); | |
| buttonD1.setText(letters[7]); | |
| } | |
| public void b1(View view){ | |
| buttonA.setVisibility(View.INVISIBLE); | |
| } | |
| public void b2(View view){ | |
| buttonB.setVisibility(View.INVISIBLE); | |
| } | |
| public void b3(View view){ | |
| buttonC.setVisibility(View.INVISIBLE); | |
| } | |
| public void b4(View view){ | |
| buttonD.setVisibility(View.INVISIBLE); | |
| } | |
| public void b5(View view){ | |
| buttonA1.setVisibility(View.INVISIBLE); | |
| } | |
| public void b6(View view){ | |
| buttonB1.setVisibility(View.INVISIBLE); | |
| } | |
| public void b7(View view){ | |
| buttonC1.setVisibility(View.INVISIBLE); | |
| } | |
| public void b8(View view){ | |
| buttonD1.setVisibility(View.INVISIBLE); | |
| } | |
| public void reset(View view){ | |
| init(); | |
| } | |
| private static String[] shuffleArray(String[]array){ | |
| int index; | |
| String temp; | |
| Random random = new Random(); | |
| for (int i = array.length -1; i > 0 ; i--) { | |
| index = random.nextInt(i + 1); | |
| temp = array[index]; | |
| array[index] = array[i]; | |
| array[i] = temp; | |
| } | |
| return array; | |
| } | |
| } |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <Button | |
| android:id="@+id/button4" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="76dp" | |
| android:onClick="b1" | |
| android:text="@string/button1" | |
| android:visibility="visible" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.445" /> | |
| <Button | |
| android:id="@+id/button" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="196dp" | |
| android:onClick="b2" | |
| android:text="@string/button2" | |
| android:visibility="visible" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.445" /> | |
| <Button | |
| android:id="@+id/button2" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="76dp" | |
| android:text="@string/button3" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.56" | |
| android:onClick="b3"/> | |
| <Button | |
| android:id="@+id/button3" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="196dp" | |
| android:onClick="b4" | |
| android:text="@string/button4" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.56" /> | |
| <Button | |
| android:id="@+id/button9" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="76dp" | |
| android:text="@string/button5" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.669" | |
| android:onClick="b5"/> | |
| <Button | |
| android:id="@+id/button11" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="196dp" | |
| android:text="@string/button6" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.669" | |
| android:onClick="b6"/> | |
| <Button | |
| android:id="@+id/button12" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="76dp" | |
| android:text="@string/button7" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.765" | |
| android:onClick="b7"/> | |
| <Button | |
| android:id="@+id/button13" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="196dp" | |
| android:text="@string/button8" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| app:layout_constraintVertical_bias="0.765" | |
| android:onClick="b8"/> | |
| <Button | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="80dp" | |
| android:text="@string/resetButton" | |
| app:layout_constraintEnd_toEndOf="parent" | |
| app:layout_constraintHorizontal_bias="0.82" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" | |
| android:onClick="reset" | |
| android:id="@+id/reset1"/> | |
| </androidx.constraintlayout.widget.ConstraintLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment