Skip to content

Commit

Permalink
fix the corlor
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielDu committed Nov 19, 2022
1 parent bad9868 commit 78657cb
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 180 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import com.example.memorygame.GlobalObject;
import com.example.memorygame.HandleStageButton;
import com.example.memorygame.Listener.DragListener.BoardDragListener;
import com.example.memorygame.Object.CorlorRecycleViewObject;
import com.example.memorygame.Object.ImageRecycleViewObject;
import com.example.memorygame.Object.MatchingObject;
import com.example.memorygame.R;
import com.example.memorygame.RecycleView.RecycleViewInterface;
import com.google.android.material.imageview.ShapeableImageView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -55,7 +56,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(GlobalObject.getInstance().getGameState()==1?R.layout.activity_match_color_1:R.layout.activity_match_color_2);
initialButton();
this.selectedImage = getIntent().getParcelableArrayListExtra("selectedImages");
for (ImageRecycleViewObject imageRecycleViewObject : this.selectedImage = new ArrayList<>(GlobalObject.getInstance().getSelectedImage())) {
imageRecycleViewObject.setSelected(false);
}
initialRecyleView();
this.globalObject = GlobalObject.getInstance();
this.selectedButtonList = new ArrayList<>();
Expand All @@ -73,15 +76,29 @@ public void initialRecyleView(){
public ArrayList<MatchingObject> generatingMatchingObject(Integer NumberPerrow){
AtomicReference<Integer> currentRow = new AtomicReference<>(0);
AtomicReference<Integer> currentColumn= new AtomicReference<>(0);
Iterator<Integer> corlorListIterator = ButtonList.getInstance().getSuffleCorlorList().iterator();
List<CorlorRecycleViewObject> initCorlorList ;
switch(GlobalObject.getInstance().getGameState()){
case 1:
initCorlorList = Collections.nCopies( ButtonList.getInstance().getButtonBoard().size(),new CorlorRecycleViewObject(false,R.color.white));
break;
default:
initCorlorList = ButtonList
.getInstance()
.getSuffleCorlorList()
.stream()
.map(element->new CorlorRecycleViewObject(false,element))
.collect(Collectors.toList());
break;
}
Iterator<CorlorRecycleViewObject> corlorListIterator = initCorlorList.iterator();
return (ArrayList<MatchingObject>) ButtonList.getInstance().getButtonBoard().stream().map(elementId->{
MatchingObject currentObject = new MatchingObject();
int nextCorlor = GlobalObject.getInstance().getGameState()==1?R.color.white:corlorListIterator.next();
CorlorRecycleViewObject corlor = corlorListIterator.next();
ShapeableImageView button = findViewById(elementId);
button.setImageResource(nextCorlor);
button.setStrokeColorResource(nextCorlor);
currentObject.setColor(nextCorlor);
currentObject.setInitCorlor(nextCorlor);
button.setImageResource(corlor.getCorlorId());
button.setStrokeColorResource(corlor.getCorlorId());
currentObject.setCorlor(corlor);
currentObject.setInitCorlor(corlor);
button.setOnDragListener( new BoardDragListener(this,currentObject));
currentObject.setViewId(button.getId());
currentObject.setColumn(currentColumn.get());
Expand All @@ -106,7 +123,7 @@ public void initialButton(){
}
@Override
public void handleNextButton(View view){
if(this.selectedImage.stream().filter(ImageRecycleViewObject::isSelected).count()>0){
if(this.selectedImage.stream().anyMatch(ImageRecycleViewObject::isSelected)){
this.globalObject.getResult().setCorrect(this.selectedButtonList);

Intent intent = new Intent(this,WaitingActivity.class);
Expand Down Expand Up @@ -155,7 +172,6 @@ public void HandleUnSelected(ImageRecycleViewObject target) {
this.recyclerViewAdapter.notifyItemChanged(filterIndex);
}
}

@Override
public void HandleSelected(Integer viewId,ImageRecycleViewObject image, MatchingObject matchingObject) {
ShapeableImageView targetView = findViewById(viewId);
Expand All @@ -177,19 +193,12 @@ public void HandleSelected(Integer viewId,ImageRecycleViewObject image, Matching
HandleSelected(image);
}
targetView.setImageResource(image.getImageId());

}
@Override
public void HandleUnSelected(Integer viewId, ImageRecycleViewObject image, @NonNull MatchingObject matchingObject) {
HandleUnSelected(image);
ShapeableImageView shapeableImageView = findViewById(viewId);
shapeableImageView.setImageResource(matchingObject.getColor());
shapeableImageView.setImageResource(matchingObject.getCorlor().getCorlorId());
this.selectedButtonList.remove(matchingObject);
}

@Override
public void HandleUpdated(Integer viewId, ImageRecycleViewObject image, MatchingObject matchingObject) {

}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
package com.example.memorygame.Activity;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.memorygame.ButtonList;
import com.example.memorygame.GlobalObject;
import com.example.memorygame.HandleStageButton;
import com.example.memorygame.Language;
import com.example.memorygame.Object.ImageRecycleViewObject;
import com.example.memorygame.Object.MatchingObject;
import com.example.memorygame.Object.Result;
import com.example.memorygame.R;
import com.google.android.material.imageview.ShapeableImageView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -105,7 +102,7 @@ public void selectedClick(Integer image, ShapeableImageView button){
public void handleNextButton(View view) {
if(this.selectedImage.size()>0){
Intent intent = new Intent(this,PredictActivity2.class);
intent.putParcelableArrayListExtra("selectedImages", (ArrayList<ImageRecycleViewObject>) this.selectedImage);
GlobalObject.getInstance().setSelectedImage(this.selectedImage);
GlobalObject.getInstance().getResult().setSelected1(this.selectedImage.stream().map(MatchingObject::new).collect(Collectors.toList()));
this.startActivity(intent);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.memorygame.Adapter.RecyclerViewAdapter;
import com.example.memorygame.ButtonList;
import com.example.memorygame.CallBack.ButtonImageCall;
import com.example.memorygame.CallBack.CorlorRecycleViewCallBack;
import com.example.memorygame.GlobalObject;
import com.example.memorygame.HandleStageButton;
import com.example.memorygame.Language;
import com.example.memorygame.Listener.DragListener.BoardDragListener;
import com.example.memorygame.Object.CorlorRecycleViewObject;
import com.example.memorygame.Object.ImageRecycleViewObject;
import com.example.memorygame.Object.MatchingObject;
import com.example.memorygame.Object.Result;
import com.example.memorygame.R;
import com.example.memorygame.RecycleView.RecycleViewInterface;
import com.google.android.material.imageview.ShapeableImageView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -46,14 +48,13 @@ public class PredictActivity2 extends AppCompatActivity implements
private ArrayList<MatchingObject> objectList;
private ArrayList<MatchingObject> selectedObject;




@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_predict2);
this.selectedImage = getIntent().getParcelableArrayListExtra("selectedImages");
for (ImageRecycleViewObject imageRecycleViewObject : this.selectedImage = new ArrayList<>(GlobalObject.getInstance().getSelectedImage())) {
imageRecycleViewObject.setSelected(false);
}
this.globalObject = GlobalObject.getInstance();
this.objectList = this.generatingMatchingObject(3);
this.globalObject.setObjectList(this.objectList);
Expand Down Expand Up @@ -97,43 +98,47 @@ public void onItemClick(View view, int Position) {
this.globalObject.setTmpClickedImage(this.tmpClickedImage);
}

public void HandleSelected(ImageRecycleViewObject target) {
public void HandleSelected(@NonNull ImageRecycleViewObject target) {

Integer filterIndex = IntStream.range(0,this.selectedImage
.size())
.filter(i->this.selectedImage.get(i).getImageId()==target.getImageId())
.filter(i->this.selectedImage.get(i).equals(target))
.findFirst()
.orElseGet(null);

target.setSelected(true);
this.selectedImage.set(filterIndex,target);
this.recyclerViewAdapter.notifyItemChanged(filterIndex);
}
public ArrayList<MatchingObject> generatingMatchingObject(Integer NumberPerrow){
public ArrayList<MatchingObject> generatingMatchingObject(Integer NumberPerrow) {

AtomicReference<Integer> currentRow = new AtomicReference<>(0);
AtomicReference<Integer> currentColumn= new AtomicReference<>(0);
ArrayList<MatchingObject> matchingObjects = (ArrayList<MatchingObject>) ButtonList.getInstance().getButtonBoard().stream().map(elementId->{
MatchingObject currentObject = new MatchingObject();
ShapeableImageView button = findViewById(elementId);
button.setImageResource(R.color.white);
currentObject.setColor(R.color.white);
button.setOnDragListener( new BoardDragListener(this,currentObject));
currentObject.setViewId(button.getId());
currentObject.setColumn(currentColumn.get());
currentObject.setRow(currentRow.get());
if (currentColumn.get() ==NumberPerrow-1){
currentRow.getAndSet(currentRow.get() + 1);
currentColumn.set(0);
}
else {
currentColumn.set(currentColumn.get()+1);
}
return currentObject;
}).collect(Collectors.toList());
return matchingObjects;
AtomicReference<Integer> currentColumn = new AtomicReference<>(0);

List<CorlorRecycleViewObject> corlorList = Collections.nCopies(ButtonList.getInstance().getButtonBoard().size(), new CorlorRecycleViewObject(false, R.color.white));
Iterator<CorlorRecycleViewObject> finalCorlorList = corlorList.iterator();
return (ArrayList<MatchingObject>) ButtonList.getInstance().getButtonBoard().stream().map(elementId -> {
CorlorRecycleViewObject initCorlor = finalCorlorList.next();
MatchingObject currentObject = new MatchingObject();
ShapeableImageView button = setShape(elementId, initCorlor.getCorlorId(), initCorlor.getCorlorId());
currentObject.setCorlor(initCorlor);
button.setOnDragListener(new BoardDragListener(this, currentObject));
currentObject.setViewId(button.getId());
currentObject.setColumn(currentColumn.get());
currentObject.setRow(currentRow.get());
currentObject.setInitCorlor(initCorlor);

if (currentColumn.get() == NumberPerrow - 1) {
currentRow.getAndSet(currentRow.get() + 1);
currentColumn.set(0);
} else {
currentColumn.set(currentColumn.get() + 1);
}
return currentObject;
}).collect(Collectors.toList());
}

public void HandleUnSelected(ImageRecycleViewObject target) {
@Override
public void HandleUnSelected(@NonNull ImageRecycleViewObject target) {
Integer filterIndex = IntStream.range(0,this.selectedImage
.size())
.filter(i->this.selectedImage.get(i).getImageId()==target.getImageId())
Expand All @@ -145,28 +150,42 @@ public void HandleUnSelected(ImageRecycleViewObject target) {
this.recyclerViewAdapter.notifyItemChanged(filterIndex);
}

@Override
public void HandleSelected(Integer viewId,ImageRecycleViewObject image, MatchingObject matchingObject) {
HandleSelected(image);
this.selectedObject.add(matchingObject);
ShapeableImageView targetView = findViewById(viewId);

MatchingObject selectedObject = this.selectedObject.size() <= 0 ? null : this.selectedObject
.stream()
.filter(element -> element.getViewId().equals(viewId))
.findAny()
.orElse(null);

if (selectedObject==null){
selectedObject = objectList.stream().filter(element->element.getViewId().equals(viewId)).findFirst().get();
HandleSelected(image);
selectedObject.setImage(image);
this.selectedObject.add(selectedObject);
}
else{
HandleUnSelected(matchingObject.getImage());
HandleSelected(image);
}
targetView.setImageResource(image.getImageId());
}


@Override
public void HandleUnSelected(Integer viewId,ImageRecycleViewObject image, MatchingObject matchingObject) {
public void HandleUnSelected(Integer viewId, ImageRecycleViewObject image, @NonNull MatchingObject matchingObject) {
HandleUnSelected(image);
this.selectedObject.remove(matchingObject);
ShapeableImageView shapeableImageView = findViewById(viewId);
shapeableImageView.setImageResource(R.color.white);
}

@Override
public void HandleUpdated(Integer viewId, ImageRecycleViewObject image, MatchingObject matchingObject) {

shapeableImageView.setStrokeColorResource(matchingObject.getInitCorlor().getCorlorId());
shapeableImageView.setImageResource(matchingObject.getInitCorlor().getCorlorId());
this.selectedObject.remove(matchingObject);
}

@Override
public void onPointerCaptureChanged(boolean hasCapture) {
super.onPointerCaptureChanged(hasCapture);
public ShapeableImageView setShape(Integer viewId,Integer Image,Integer corlor){
ShapeableImageView button = findViewById(viewId);
button.setImageResource(Image);
button.setStrokeColorResource(corlor);
return button;
}
}
Loading

0 comments on commit 78657cb

Please sign in to comment.