public void update() { bg.update(); int remaining = 0; if (state != 4) { done.setBitmap(scaledDone); if (state == 1) { for (int i = 0; i < gameObject1.size(); i++) { gameObject1.get(i).update(); score11.update(); gameWord1.update(); } } if (state == 2) { for (int i = 0; i < gameObject2.size(); i++) { gameObject2.get(i).update(); score22.update(); gameWord2.update(); } } } if (state == 4) { done.setBitmap(scaledNew); if (score1 > score2) { totalWinner = 1; } else if (score1 < score2) { totalWinner = 2; } else { totalWinner = 0; } } done.update(); moneyPanel.update(); timer.update(); mid.update(); newMoney(scaledTimer, timer.drawUpdate()); timer.setBitmap(scaledTimer.get(0), scaledTimer.get(1)); if (timer.getGG() && state == 1) { state = 2; timer.resetTimer(); } if (timer.getGG() && state == 2) { state = 3; compare.setCompare(choose, usedDiamond, choose2, usedDiamond2); winner = compare.comparator(); choose = "Nope"; choose2 = "Nope"; usedDiamond = false; usedDiamond2 = false; timer.resetTimer(); } // System.out.println("test"); }
@Override public boolean onTouchEvent(MotionEvent event) { ArrayList<GameObject> gameObject = new ArrayList<GameObject>(); String player = null; GameWord gameWord = gameWord1; boolean playerDiamond = false; if (state == 1) { gameObject = gameObject1; playerDiamond = usedDiamond; player = choose; gameWord = gameWord1; } if (state == 2) { gameObject = gameObject2; playerDiamond = usedDiamond2; player = choose2; gameWord = gameWord2; } if (state == 3) { gameObject = gameObject3; } if (state == 4) { gameObject = gameObject4; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: playerDiamond = false; xTouch = event.getX(); yTouch = event.getY(); // System.out.println("x: "+ (int)(xTouch/scaleFactorX)+" "+scaleFactorX); // System.out.println("y: "+ (int)(yTouch/scaleFactorY)+" "+scaleFactorY); for (int i = 0; i < gameObject.size(); i++) { gameObjectName = collision( (int) (xTouch / scaleFactorX), (int) (yTouch / scaleFactorY), gameObject.get(i)); if (gameObjectName != null) { imageWord(gameWord, gameObjectName); System.out.println(gameObjectName); num = i; // gameObject.get(i).setX((int)(xTouch/scaleFactorX)); // gameObject.get(i).setY((int)(yTouch/scaleFactorY)); break; } } break; case MotionEvent.ACTION_MOVE: if (state == 1 || state == 2) { if (num != -1) { if (gameObjectName != "Done") { xTouch = event.getX(); // System.out.println("X: " + xTouch); yTouch = event.getY(); // System.out.println("Y: " + yTouch); if (num >= 0) { gameObject .get(num) .setX((int) (xTouch / scaleFactorY) - (gameObject.get(num).getWidth() / 2)); gameObject .get(num) .setY((int) (yTouch / scaleFactorY) - (gameObject.get(num).getHeight() / 2)); } } } } break; case MotionEvent.ACTION_UP: /*if (collBetObj(gameObject.get(num),mid)){ System.out.println("collide"); gameObject.remove(num); overlayBitmap.eraseColor(Color.TRANSPARENT); }*/ if (num != -1) { if ((collBetObj(gameObject.get(num), mid) && player == "Nope") || (collBetObj(gameObject.get(num), mid)) && (gameObject.get(num).getString() == "Diamond")) { if (gameObject.get(num).getString() != "Diamond") { player = gameObject.get(num).getString(); // System.out.println("Choose: " + player); gameObject.remove(num); } else if (gameObject.get(num).getString() == "Diamond" && player == "Nope") { // System.out.println("Choose: " + player); gameObject.get(num).setX(gameObject.get(num).getInitialX()); gameObject.get(num).setY(gameObject.get(num).getInitialY()); } else { playerDiamond = true; // System.out.println("Diamond used: " + playerDiamond); gameObject.remove(num); } if (state == 1) { usedDiamond = playerDiamond; choose = player; } else if (state == 2) { usedDiamond2 = playerDiamond; choose2 = player; } // gameObject.get(num).getBit().eraseColor(Color.TRANSPARENT); } else { if (gameObject.get(num).getString() != "Done") { gameObject.get(num).setX(gameObject.get(num).getInitialX()); gameObject.get(num).setY(gameObject.get(num).getInitialY()); } else { if (state == 1) { // usedDiamond = playerDiamond; // choose = player; state = 2; scaledGameWord = Bitmap.createScaledBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.player2), 192, 64, true); gameWord2.setBitmap(scaledGameWord); timer.resetTimer(); } else if (state == 2) { // usedDiamond2 = playerDiamond; // choose2 = player; state = 3; timer.resetTimer(); compare.setCompare(choose, usedDiamond, choose2, usedDiamond2); winner = compare.comparator(); System.out.println("Winner: " + winner); choose = "Nope"; choose2 = "Nope"; usedDiamond = false; usedDiamond2 = false; } else if (state == 3) { state = 1; scaledGameWord = Bitmap.createScaledBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.player1), 192, 64, true); gameWord1.setBitmap(scaledGameWord); // gameWord2.setBitmap(scaledGameWord); if (winner == 1) { score1 = score1 + money.vals[round]; newMoney(Money1, score11.drawUpdate(score1)); score11.setBitmap(Money1.get(0), Money1.get(1)); } else if (winner == 2) { score2 = score2 + money.vals[round]; newMoney(Money2, score22.drawUpdate(score2)); score22.setBitmap(Money2.get(0), Money2.get(1)); } if (round < 5) { round++; if (round == 5) { state = 4; } else { newMoney(scaledMoney, money.drawUpdate(money.vals[round])); money.setBitmap(scaledMoney.get(0), scaledMoney.get(1)); } } int remaining = 0; for (int i = 0; i < ((money.vals.length) - round); i++) { remaining = remaining + money.vals[4 - i]; System.out.println("Money: " + money.vals[4 - i]); } System.out.println(remaining); System.out.println((score1 + remaining) < score2); System.out.println((score2 + remaining) < score1); if (((score1 + remaining) < score2) || ((score2 + remaining) < score1)) { state = 4; System.out.println("Sad"); } timer.resetTimer(); winner = 0; } else if (state == 4) { newGame(); } // System.out.println("State: "+ state); // System.out.println("Score1: "+ score1); // System.out.println("Score2: "+ score2); } } num = -1; gameObjectName = null; } break; } return true; }