Wrote Match3 in one shot HAHAHAHA
This commit is contained in:
parent
04736a9fb7
commit
431d607e71
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -12,6 +12,9 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.AndroidProjectCollection"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".Match3Exercise"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".CalculatorExercise"
|
||||
android:exported="false" />
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import androidx.core.view.WindowInsetsCompat;
|
|||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
Button btn1,btn2,btn3;
|
||||
Button btn1,btn2,btn3,btn4;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -50,6 +50,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
startActivity(intent1);
|
||||
}
|
||||
});
|
||||
btn4 = findViewById(R.id.btnCM3);
|
||||
|
||||
btn4.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startCM3 = new Intent(MainActivity.this, Match3Exercise.class);
|
||||
startActivity(startCM3);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,670 @@
|
|||
package com.example.androidprojectcollection;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Match3Exercise extends AppCompatActivity {
|
||||
Button[] btns = new Button[25];
|
||||
ButtonProperties[] props = new ButtonProperties[25];
|
||||
TextView tv;
|
||||
|
||||
int clicks = 0,score = 0;
|
||||
|
||||
int[] held_tile = new int[2];
|
||||
|
||||
Button reset;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_match3_exercise);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
reset = findViewById(R.id.BtnReset);
|
||||
tv = findViewById(R.id.ScoreBoard);
|
||||
|
||||
props[0] = new ButtonProperties();
|
||||
props[1] = new ButtonProperties();
|
||||
props[2] = new ButtonProperties();
|
||||
props[3] = new ButtonProperties();
|
||||
props[4] = new ButtonProperties();
|
||||
props[5] = new ButtonProperties();
|
||||
props[6] = new ButtonProperties();
|
||||
props[7] = new ButtonProperties();
|
||||
props[8] = new ButtonProperties();
|
||||
props[9] = new ButtonProperties();
|
||||
props[10] = new ButtonProperties();
|
||||
props[11] = new ButtonProperties();
|
||||
props[12] = new ButtonProperties();
|
||||
props[13] = new ButtonProperties();
|
||||
props[14] = new ButtonProperties();
|
||||
props[15] = new ButtonProperties();
|
||||
props[16] = new ButtonProperties();
|
||||
props[17] = new ButtonProperties();
|
||||
props[18] = new ButtonProperties();
|
||||
props[19] = new ButtonProperties();
|
||||
props[20] = new ButtonProperties();
|
||||
props[21] = new ButtonProperties();
|
||||
props[22] = new ButtonProperties();
|
||||
props[23] = new ButtonProperties();
|
||||
props[24] = new ButtonProperties();
|
||||
|
||||
|
||||
|
||||
//First Row
|
||||
btns[0] = findViewById(R.id.btn0);
|
||||
//props[0] = new ButtonProperties(true ,false,true,false);
|
||||
btns[1] = findViewById(R.id.btn1);
|
||||
//props[1] = new ButtonProperties(true ,false,false,false);
|
||||
btns[2] = findViewById(R.id.btn2);
|
||||
//props[2] = new ButtonProperties(true ,false,false,false);
|
||||
btns[3] = findViewById(R.id.btn3);
|
||||
//props[3] = new ButtonProperties(true ,false,false,false);
|
||||
btns[4] = findViewById(R.id.btn4);
|
||||
//props[4] = new ButtonProperties(true ,false,false,true);
|
||||
|
||||
//Second Row
|
||||
btns[5] = findViewById(R.id.btn5);
|
||||
//props[5] = new ButtonProperties(false ,false,true,false);
|
||||
btns[6] = findViewById(R.id.btn6);
|
||||
//props[6] = new ButtonProperties(false ,false,false,false);
|
||||
btns[7] = findViewById(R.id.btn7);
|
||||
//props[7] = new ButtonProperties(false ,false,false,false);
|
||||
btns[8] = findViewById(R.id.btn8);
|
||||
//props[8] = new ButtonProperties(false ,false,false,false);
|
||||
btns[9] = findViewById(R.id.btn9);
|
||||
//props[9] = new ButtonProperties(false ,false,false,true);
|
||||
|
||||
//Third Row
|
||||
btns[10] = findViewById(R.id.btn10);
|
||||
//props[10] = new ButtonProperties(false ,false,true,false);
|
||||
btns[11] = findViewById(R.id.btn11);
|
||||
//props[11] = new ButtonProperties(true ,false,false,false);
|
||||
btns[12] = findViewById(R.id.btn12);
|
||||
//props[12] = new ButtonProperties(false ,false,false,false);
|
||||
btns[13] = findViewById(R.id.btn13);
|
||||
//props[13] = new ButtonProperties(false ,false,false,false);
|
||||
btns[14] = findViewById(R.id.btn14);
|
||||
//props[14] = new ButtonProperties(false,false,false,true);
|
||||
|
||||
//Fourth Row
|
||||
btns[15] = findViewById(R.id.btn15);
|
||||
//props[15] = new ButtonProperties(false ,false,true,false);
|
||||
btns[16] = findViewById(R.id.btn16);
|
||||
//props[16] = new ButtonProperties(false ,false,false,false);
|
||||
btns[17] = findViewById(R.id.btn17);
|
||||
//props[17] = new ButtonProperties(false ,false,false,false);
|
||||
btns[18] = findViewById(R.id.btn18);
|
||||
//props[18] = new ButtonProperties(false ,false,false,false);
|
||||
btns[19] = findViewById(R.id.btn19);
|
||||
//props[19] = new ButtonProperties(false ,false,false,true);
|
||||
|
||||
//Fifth Row
|
||||
btns[20] = findViewById(R.id.btn20);
|
||||
//props[20] = new ButtonProperties(false ,true,true,false);
|
||||
btns[21] = findViewById(R.id.btn21);
|
||||
//props[21] = new ButtonProperties(false ,true,false,false);
|
||||
btns[22] = findViewById(R.id.btn22);
|
||||
//props[22] = new ButtonProperties(false ,true,false,false);
|
||||
btns[23] = findViewById(R.id.btn23);
|
||||
//props[23] = new ButtonProperties(false ,true,false,false);
|
||||
btns[24] = findViewById(R.id.btn24);
|
||||
//props[24] = new ButtonProperties(false ,true,false,true);
|
||||
buttonLabeler();
|
||||
|
||||
btns[0].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(0);
|
||||
}
|
||||
});
|
||||
btns[1].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(1);
|
||||
}
|
||||
});
|
||||
|
||||
btns[2].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(2);
|
||||
}
|
||||
});
|
||||
|
||||
btns[3].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(3);
|
||||
}
|
||||
});
|
||||
|
||||
btns[4].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(4);
|
||||
}
|
||||
});
|
||||
|
||||
btns[5].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(5);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btns[6].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(6);
|
||||
}
|
||||
});
|
||||
|
||||
btns[7].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(7);
|
||||
}
|
||||
});
|
||||
|
||||
btns[8].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(8);
|
||||
}
|
||||
});
|
||||
|
||||
btns[9].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(9);
|
||||
}
|
||||
});
|
||||
|
||||
btns[10].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(10);
|
||||
}
|
||||
});
|
||||
|
||||
btns[11].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(11);
|
||||
}
|
||||
});
|
||||
|
||||
btns[12].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(12);
|
||||
}
|
||||
});
|
||||
|
||||
btns[13].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(13);
|
||||
}
|
||||
});
|
||||
|
||||
btns[14].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(14);
|
||||
}
|
||||
});
|
||||
|
||||
btns[15].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(15);
|
||||
}
|
||||
});
|
||||
|
||||
btns[16].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(16);
|
||||
}
|
||||
});
|
||||
|
||||
btns[17].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(17);
|
||||
}
|
||||
});
|
||||
|
||||
btns[18].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(18);
|
||||
}
|
||||
});
|
||||
|
||||
btns[19].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(19);
|
||||
}
|
||||
});
|
||||
|
||||
btns[20].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(20);
|
||||
}
|
||||
});
|
||||
|
||||
btns[21].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(21);
|
||||
}
|
||||
});
|
||||
|
||||
btns[22].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(22);
|
||||
}
|
||||
});
|
||||
|
||||
btns[23].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(23);
|
||||
}
|
||||
});
|
||||
|
||||
btns[24].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stuffer(24);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
reset.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
buttonLabeler();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void buttonLabeler(){
|
||||
Random rd = new Random();
|
||||
for (int i = 0 ; i < 25 ; i++){
|
||||
switch (rd.nextInt(4) + 1){
|
||||
case 1:{
|
||||
btns[i].setBackgroundColor(Color.RED);
|
||||
props[i].color = 1;
|
||||
break;
|
||||
}case 2:{
|
||||
btns[i].setBackgroundColor(Color.BLUE);
|
||||
props[i].color = 2;
|
||||
break;
|
||||
} case 3:{
|
||||
btns[i].setBackgroundColor(Color.GREEN);
|
||||
props[i].color = 3;
|
||||
break;
|
||||
} case 4:{
|
||||
btns[i].setBackgroundColor(Color.YELLOW);
|
||||
props[i].color = 4;
|
||||
break;
|
||||
}default:{
|
||||
btns[i].setBackgroundColor(Color.BLACK);
|
||||
props[i].color = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stuffer(int index){
|
||||
if(clicks < 1){
|
||||
held_tile[clicks] = index;
|
||||
clicks++;
|
||||
}else {
|
||||
held_tile[clicks] = index ;
|
||||
clicks++;
|
||||
swapper(held_tile[0],held_tile[1]);
|
||||
clicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void swapper(int wan, int tuo){
|
||||
if (validity(wan, tuo)) {
|
||||
int swap = props[wan].color;
|
||||
props[wan].color = props[tuo].color;
|
||||
props[tuo].color = swap;
|
||||
colorer(wan);
|
||||
colorer(tuo);
|
||||
for (int i = 0 ;i < 25 ; i++){
|
||||
matchCheck(i);
|
||||
}
|
||||
tv.setText("Score: " + score);
|
||||
}
|
||||
}
|
||||
|
||||
boolean validity(int wan, int tuo){
|
||||
if (wan == (tuo-1) || wan == (tuo+1) || wan == (tuo-5) || wan == (tuo+5)){
|
||||
return props[wan].color != props[tuo].color;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void colorer(int index){
|
||||
|
||||
switch (props[index].color){
|
||||
case 1:{
|
||||
btns[index].setBackgroundColor(Color.RED);
|
||||
break;
|
||||
}case 2:{
|
||||
btns[index].setBackgroundColor(Color.BLUE);
|
||||
break;
|
||||
} case 3:{
|
||||
btns[index].setBackgroundColor(Color.GREEN);
|
||||
break;
|
||||
} case 4:{
|
||||
btns[index].setBackgroundColor(Color.YELLOW);
|
||||
break;
|
||||
}default:{
|
||||
btns[index].setBackgroundColor(Color.BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void matchCheck(int index) {
|
||||
int row = index / 5; // Calculate the row of the button
|
||||
int col = index % 5; // Calculate the column of the button
|
||||
int color = props[index].color; // Get the color of the current button
|
||||
|
||||
// Check for horizontal matches
|
||||
if (col <= 2 && props[index + 1].color == color && props[index + 2].color == color) {
|
||||
// Match found, update colors
|
||||
props[index].color = getRandomColor();
|
||||
props[index + 1].color = getRandomColor();
|
||||
props[index + 2].color = getRandomColor();
|
||||
colorer(index);
|
||||
colorer(index + 1);
|
||||
colorer(index + 2);
|
||||
score++;
|
||||
}
|
||||
|
||||
// Check for vertical matches
|
||||
if (row <= 2 && props[index + 5].color == color && props[index + 10].color == color) {
|
||||
// Match found, update colors
|
||||
props[index].color = getRandomColor();
|
||||
props[index + 5].color = getRandomColor();
|
||||
props[index + 10].color = getRandomColor();
|
||||
colorer(index);
|
||||
colorer(index + 5);
|
||||
colorer(index + 10);
|
||||
score++;
|
||||
}
|
||||
|
||||
// Check for matches in upward direction
|
||||
if (row >= 2 && props[index - 5].color == color && props[index - 10].color == color) {
|
||||
// Match found, update colors
|
||||
props[index].color = getRandomColor();
|
||||
props[index - 5].color = getRandomColor();
|
||||
props[index - 10].color = getRandomColor();
|
||||
colorer(index);
|
||||
colorer(index - 5);
|
||||
colorer(index - 10);
|
||||
score++;
|
||||
}
|
||||
}
|
||||
|
||||
int getRandomColor() {
|
||||
Random rd = new Random();
|
||||
return rd.nextInt(4) + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ButtonProperties{
|
||||
/* boolean isTopMost;
|
||||
boolean isBottomMost;
|
||||
boolean isLeftMost;
|
||||
boolean isRightMost;*/
|
||||
int color;
|
||||
/*
|
||||
public ButtonProperties(boolean isTopMost, boolean isBottomMost, boolean isLeftMost, boolean isRightMost) {
|
||||
this.isTopMost = isTopMost;
|
||||
this.isBottomMost = isBottomMost;
|
||||
this.isLeftMost = isLeftMost;
|
||||
this.isRightMost = isRightMost;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*basement code*/
|
||||
/* int matchCheck(int index){
|
||||
Random rd = new Random();
|
||||
switch (props[index].spewer()){
|
||||
case 1:{ //Topmost
|
||||
if(props[index].color == props[index-1].color && props[index].color == props[index+1].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+1].color = rd.nextInt(4)+1;
|
||||
props[index-1].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+1);
|
||||
colorer(index-1);
|
||||
}else if (props[index].color == props[index+5].color && props[index].color == props[index+10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+5].color = rd.nextInt(4)+1;
|
||||
props[index+10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+5);
|
||||
colorer(index+10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
} case 2:{ //BottomMost
|
||||
if(props[index].color == props[index-1].color && props[index].color == props[index+1].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+1].color = rd.nextInt(4)+1;
|
||||
props[index-1].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+1);
|
||||
colorer(index-1);
|
||||
}else if (props[index].color == props[index-5].color && props[index].color == props[index-10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-5].color = rd.nextInt(4)+1;
|
||||
props[index-10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-5);
|
||||
colorer(index-10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
} case 3:{//LeftMost
|
||||
if(props[index].color == props[index+1].color && props[index].color == props[index+2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+1].color = rd.nextInt(4)+1;
|
||||
props[index+2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+1);
|
||||
colorer(index+2);
|
||||
}else if (props[index].color == props[index+5].color && props[index].color == props[index-5].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+5].color = rd.nextInt(4)+1;
|
||||
props[index-5].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+5);
|
||||
colorer(index-5);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
} case 4:{//RightMost
|
||||
|
||||
if(props[index].color == props[index-1].color && props[index].color == props[index-2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-1].color = rd.nextInt(4)+1;
|
||||
props[index-2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-1);
|
||||
colorer(index-2);
|
||||
}else if (props[index].color == props[index+5].color && props[index].color == props[index-5].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+5].color = rd.nextInt(4)+1;
|
||||
props[index-5].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+5);
|
||||
colorer(index-5);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
} case 5:{//TopLeftMost
|
||||
if(props[index].color == props[index+1].color && props[index].color == props[index+2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+1].color = rd.nextInt(4)+1;
|
||||
props[index+2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+1);
|
||||
colorer(index+2);
|
||||
}else if (props[index].color == props[index+5].color && props[index].color == props[index+10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+5].color = rd.nextInt(4)+1;
|
||||
props[index+10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+5);
|
||||
colorer(index+10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
|
||||
} case 6:{//TopRightMost
|
||||
if(props[index].color == props[index-1].color && props[index].color == props[index-2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-1].color = rd.nextInt(4)+1;
|
||||
props[index-2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-1);
|
||||
colorer(index-2);
|
||||
}else if (props[index].color == props[index+5].color && props[index].color == props[index+10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+5].color = rd.nextInt(4)+1;
|
||||
props[index+10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+5);
|
||||
colorer(index+10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
|
||||
} case 7:{//BottomLeftMost
|
||||
if(props[index].color == props[index+1].color && props[index].color == props[index+2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index+1].color = rd.nextInt(4)+1;
|
||||
props[index+2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index+1);
|
||||
colorer(index+2);
|
||||
}else if (props[index].color == props[index-5].color && props[index].color == props[index-10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-5].color = rd.nextInt(4)+1;
|
||||
props[index-10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-5);
|
||||
colorer(index-10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
|
||||
} case 8:{//BottomRightMost
|
||||
if(props[index].color == props[index-1].color && props[index].color == props[index-2].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-1].color = rd.nextInt(4)+1;
|
||||
props[index-2].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-1);
|
||||
colorer(index-2);
|
||||
}else if (props[index].color == props[index-5].color && props[index].color == props[index-10].color){
|
||||
props[index].color = rd.nextInt(4)+1;
|
||||
props[index-5].color = rd.nextInt(4)+1;
|
||||
props[index-10].color = rd.nextInt(4)+1;
|
||||
colorer(index);
|
||||
colorer(index-5);
|
||||
colorer(index-10);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
score++;
|
||||
break;
|
||||
} default:{
|
||||
System.exit(69);
|
||||
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
}*/
|
||||
|
|
@ -64,4 +64,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/Calculaotr" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCM3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="160dp"
|
||||
android:layout_marginTop="88dp"
|
||||
android:layout_marginEnd="160dp"
|
||||
android:layout_marginBottom="181dp"
|
||||
android:text="Fuck you"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button3" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
250
app/src/main/res/layout/activity_match3_exercise.xml
Normal file
250
app/src/main/res/layout/activity_match3_exercise.xml
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<?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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Match3Exercise">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="407dp"
|
||||
android:layout_height="415dp"
|
||||
android:layout_marginStart="1dp"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="3"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" >
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="7">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ScoreBoard"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="Score: 0"
|
||||
android:textSize="20sp" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn0"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn8"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn9"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn10"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn11"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn13"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn14"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn15"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn16"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn17"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn18"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn19"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:weightSum="5">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn20"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn21"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn22"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn23"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn24"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:foregroundGravity="center"
|
||||
android:gravity="center|center_horizontal"
|
||||
android:weightSum="1">
|
||||
|
||||
<Button
|
||||
android:id="@+id/BtnReset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0.3"
|
||||
android:text="Reset" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user