From 58f55f19bf393368bb48b9f27c93d24ad6455f38 Mon Sep 17 00:00:00 2001 From: agp8x Date: Mon, 10 Apr 2017 00:15:27 +0200 Subject: [PATCH] try to work around overdeletion --- .../android/games/fillgrid/FillGridView.java | 34 ++++++------------- .../games/fillgrid/data/GridBoard.java | 10 ++++-- .../games/fillgrid/data/GroupCell.java | 3 +- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/agp8x/android/games/fillgrid/FillGridView.java b/app/src/main/java/org/agp8x/android/games/fillgrid/FillGridView.java index 26bc1ed..9344c07 100644 --- a/app/src/main/java/org/agp8x/android/games/fillgrid/FillGridView.java +++ b/app/src/main/java/org/agp8x/android/games/fillgrid/FillGridView.java @@ -207,17 +207,11 @@ public class FillGridView extends View { private class FillGridTouchListener implements OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { - System.out.println("EVENT!"); - ; - Log.d(TAG, "EVENT"); Pair position = Util.event2pair(event); boolean updated = false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - Log.d(TAG, "EVENT: AcitonDown"); if (Util.in(position, spawnBoundaries)) { - Log.d(TAG, " in boundary"); - Log.d(TAG, ""); updated = handleStart(event, position); } break; @@ -226,7 +220,6 @@ public class FillGridView extends View { break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - //TODO: drop updated = handleStop(event, position); break; } @@ -250,13 +243,9 @@ public class FillGridView extends View { return false; } boolean updated = false; - Log.d(TAG, "no object dragged aleady"); // spawnPositions.entrySet().stream().filter(entry -> selects(position, entry.getValue())).findFirst().ifPresent(entry -> startDragging(entry, position)); for (Map.Entry, Pair> entry : spawnPositions.entrySet()) { - Log.d(TAG, "handleStart: "+position+""); if (selects(position, entry.getValue())) { - Log.d(TAG, "handleStart: SELECTED"); - Log.d(TAG, "now we drag"); dragging.object = entry.getKey(); dragging.xy = position; updated = true; @@ -271,13 +260,11 @@ public class FillGridView extends View { boolean updated = false; if (dragging.object != null) { if (board.drop(coordinate2offset(position), dragging.object)) { - System.out.println(spawnGrid); - System.out.println(dragging.object); //Offset key = spawnGrid.entrySet().stream().filter(entry -> entry==dragging.object).findFirst().get().getKey(); - Offset key=null; + Offset key = null; for (Map.Entry> entry : spawnGrid.entrySet()) { - if (entry.getValue() == dragging.object){ - key= entry.getKey(); + if (entry.getValue() == dragging.object) { + key = entry.getKey(); break; } } @@ -285,14 +272,17 @@ public class FillGridView extends View { spawnPositions.remove(dragging.object); } dragging.object = null; - if (spawnGrid.isEmpty()){ + if (spawnGrid.isEmpty()) { populateSpawnArea(); } - score += board.collapseFilledLines(); - if (scoreView != null) { - scoreView.setText(String.valueOf(score)); + int count = board.collapseFilledLines(); + if (count > 0) { + score += count; + if (scoreView != null) { + scoreView.setText(String.valueOf(score)); + } + board.removeCollapsed(); } - board.removeCollapsed(); updated = true; } return updated; @@ -307,7 +297,6 @@ public class FillGridView extends View { private boolean selects(Pair eventPos, Pair spawnPos) { float xdiff = Math.abs(eventPos.first - spawnPos.first); float ydiff = Math.abs(eventPos.second - spawnPos.second); - System.out.println("diffs: " + xdiff + " --- " + ydiff); return xdiff < 40 && ydiff < 40; } } @@ -315,6 +304,5 @@ public class FillGridView extends View { private class Dragging { GridBlock object; Pair xy; - Offset key; } } diff --git a/app/src/main/java/org/agp8x/android/games/fillgrid/data/GridBoard.java b/app/src/main/java/org/agp8x/android/games/fillgrid/data/GridBoard.java index ab2dc53..b02677c 100644 --- a/app/src/main/java/org/agp8x/android/games/fillgrid/data/GridBoard.java +++ b/app/src/main/java/org/agp8x/android/games/fillgrid/data/GridBoard.java @@ -51,9 +51,11 @@ public class GridBoard, C extends Cell> implements Grid< } public void removeCollapsed() { - List removals = contents.entrySet().stream().filter(offsetCEntry -> offsetCEntry.getValue().isCollapsed()).map(Map.Entry::getKey).collect(Collectors.toList()); + /*List removals = contents.entrySet().stream().filter(offsetCEntry -> offsetCEntry.getValue().isCollapsed()).map(Map.Entry::getKey).collect(Collectors.toList()); + System.out.println("REMOVALS QUEUE ("+removals.size()+"): "+removals); removals.forEach(contents::remove); - removals.clear(); + removals.clear();*/ + System.err.println("!!! BUG ALERT !!!"); } /** @@ -63,8 +65,10 @@ public class GridBoard, C extends Cell> implements Grid< */ public int collapseFilledLines() { List deletionQueue = findFullLines(); - deletionQueue.stream().map(contents::get).forEach(Cell::markCollapsed); + deletionQueue.stream().map(contents::get).distinct().forEach(Cell::markCollapsed); int count = deletionQueue.size(); + System.out.println("DELETION QUEUE ("+count+"): "+deletionQueue); + deletionQueue.forEach(contents::remove); deletionQueue.clear(); return count; } diff --git a/app/src/main/java/org/agp8x/android/games/fillgrid/data/GroupCell.java b/app/src/main/java/org/agp8x/android/games/fillgrid/data/GroupCell.java index 30f1284..dee8754 100644 --- a/app/src/main/java/org/agp8x/android/games/fillgrid/data/GroupCell.java +++ b/app/src/main/java/org/agp8x/android/games/fillgrid/data/GroupCell.java @@ -28,12 +28,13 @@ public class GroupCell implements Cell { @Override public void markCollapsed() { + System.out.println("DIE"); collapsionMark = true; } @Override public boolean isCollapsed() { - return collapsionMark; + System.out.println("die? "+collapsionMark);return collapsionMark; } }