@SideOnly(Side.CLIENT) public void playBackgroundMusic(String sound) { if (options.musicVolume == 0f) { if (bgm.playing(sound)) bgm.stop(sound); if (bgm.playing(currentMusic)) bgm.stop(currentMusic); currentMusic = ""; } else { if (sound == currentMusic && bgm.playing(sound)) bgm.setVolume(sound, options.musicVolume); else if (sound != currentMusic || currentMusic == null || !bgm.playing(currentMusic)) { if (bgm.playing(currentMusic) && currentMusic != null) bgm.stop(currentMusic); ArrayList<SoundPoolEntry> songList = SoundHandler.getMusicList(sound); if (songList.size() == 0) return; int songNum = musicRand.nextInt(songList.size()); bgm.backgroundMusic( sound, songList.get(songNum).soundUrl, songList.get(songNum).soundName, false); bgm.setVolume(sound, options.musicVolume); bgm.play(sound); currentMusic = sound; System.out.println("Playing background music: " + songList.get(songNum).soundName); } } }
// Checks if the player has found all the letters private void checkIfDone() { if (correctLetters == numberOfLetters) { // Win - Save and Show Score SoundHandler.PlaySound(SoundHandler.correct_sound_id); Score.setRiddleScore(70 - mistakes * 2); Intent itn = new Intent(getApplicationContext(), Score.class); itn.putExtra("nextStage", 11); startActivity(itn); finish(); } }
public void playMenuMusic(String sound) { ArrayList<SoundPoolEntry> songList = SoundHandler.getMusicList(sound); if (songList.size() == 0) return; int songNum = musicRand.nextInt(songList.size()); bgm.backgroundMusic( sound, songList.get(songNum).soundUrl, songList.get(songNum).soundName, true); bgm.setVolume(sound, 0.3f); bgm.play(sound); currentMusic = sound; System.out.println("Playing menu music: " + songList.get(songNum).soundName); }
@Override public boolean onTouchEvent(MotionEvent ev) { // Check if pause button is hit if (ev.getAction() == MotionEvent.ACTION_DOWN) { float touchX = ev.getX(); float touchY = ev.getY(); if (pauseBt.getRect().contains((int) touchX, (int) touchY)) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { // LeaveMemoryGame(); Intent itn; itn = new Intent(getApplicationContext(), PauseMenuActivity.class); startActivity(itn); } } final int pointerIndex = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); PlayerTouchX = (int) x; PlayerTouchY = (int) y; if (!showCardsState) { if (currentSelectedRectIndex1 == -1 && currentSelectedRectIndex2 == -1 && (currentSelectedRectIndex1 = findSelectedRect()) != -1) // nothing is selected: read first { Log.w( "Warn", "Selected 111: " + currentSelectedRectIndex1 + " 2 is: " + currentSelectedRectIndex2); } else if (currentSelectedRectIndex1 != -1 && currentSelectedRectIndex2 == -1 && (currentSelectedRectIndex2 = findSelectedRect()) != -1) // selected 1: read second { // Log.w("Warn", "Selected 222: " + currentSelectedRectIndex2 + " 1 is " + // currentSelectedRectIndex1); // search for pairs // if (KeysArray[currentSelectedRectIndex1] == currentSelectedRectIndex2 && // KeysArray[currentSelectedRectIndex2] == currentSelectedRectIndex1) { if (cardList.get(currentSelectedRectIndex1).code == cardList.get(currentSelectedRectIndex2).code) { // Log.w("Warn", "Pair found"); SoundHandler.PlaySound(SoundHandler.correct_sound_id3); pairs++; if (pairs == (M * N) / 2) LeaveMemoryGame(); cardList.get(currentSelectedRectIndex1).turned = true; // reveal 'cards' cardList.get(currentSelectedRectIndex2).turned = true; currentSelectedRectIndex1 = -1; currentSelectedRectIndex2 = -1; } else // if no pairs found activate 'no select timer' { canSelectState = false; noSelectTimer = System.currentTimeMillis(); // start counting time.. } } else if (currentSelectedRectIndex1 != -1 && currentSelectedRectIndex2 != -1) { Log.w("Warn", "Cant Select, waiting timer.."); } } } return true; }
// Check if the letter of pressed button exists in the word private void checkLetter(Button bt) { String letter = bt.getText().toString(); // get the button letter // make the button disable so the user can't hit it again and change it's color bt.setEnabled(false); bt.setClickable(false); bt.setBackgroundColor(getResources().getColor(R.color.disable_button)); char letterChar = letter.charAt(0); // convert string to char boolean found = false; // initialize found as false, it becomes true when the letter is found in the word // Check if the letter exists in the word, if so then change the text of the specific textView // from _ to the letter for (int i = 0; i < numberOfLetters; i++) { if (wordArray[i] == letterChar) { found = true; correctLetters++; TextView tv = (TextView) findViewById(lettersView[i].getId()); tv.setText("" + letterChar); tv.invalidate(); } } // If the letter does not exists, increase mistakes and update the image of the the arch image // view, then check if // the game is over if (!found) { SoundHandler.PlaySound(SoundHandler.wrong_sound_id2); mistakes++; if (mistakes == 1) { currentArch.setImageResource(R.drawable.hangman_wrong_1); } else if (mistakes == 2) { currentArch.setImageResource(R.drawable.hangman_wrong_2); } else if (mistakes == 3) { currentArch.setImageResource(R.drawable.hangman_wrong_3); } else if (mistakes == 4) { currentArch.setImageResource(R.drawable.hangman_wrong_4); } else if (mistakes > 4) { // Lost - Save and Show Score for (int i = 0; i < numberOfLetters; i++) // show letters { TextView tv = (TextView) findViewById(lettersView[i].getId()); tv.setText("" + wordArray[i]); tv.invalidate(); } currentArch.setImageBitmap(null); CountDownTimer countDownTimer = new CountDownTimer(3000, 1000) { // after 3 seconds quit public void onTick(long t) {} public void onFinish() { SoundHandler.PlaySound(SoundHandler.wrong_sound_id4); Score.setRiddleScore(correctLetters * 2); Intent itn = new Intent(getApplicationContext(), Score.class); itn.putExtra("nextStage", 11); startActivity(itn); // Change and store the question Mode QrCodeScanner.questionMode = true; QrCodeScanner.storeQuestionMode(true); finish(); } }.start(); } } checkIfDone(); }