public void gameFinished(boolean victory) { int mines = minesweeperGame.getMines(); int rows = minesweeperGame.getRows(); int cols = minesweeperGame.getCols(); if (Constants.BEGINNER.isEqual(rows, cols, mines)) { SharedPreferences.Editor editor = prefs.edit(); if (victory) { int score = prefs.getInt("begWins", 0); editor.putInt("begWins", ++score); int prevTime = prefs.getInt("begTime", 0); int time = this.seconds < prevTime || prevTime == 0 ? this.seconds : prevTime; editor.putInt("begTime", time); } else { int score = prefs.getInt("begLosses", 0); editor.putInt("begLosses", ++score); } editor.commit(); } else if (Constants.MEDIUM.isEqual(rows, cols, mines)) { SharedPreferences.Editor editor = prefs.edit(); if (victory) { int score = prefs.getInt("medWins", 0); editor.putInt("medWins", ++score); int prevTime = prefs.getInt("medTime", 0); int time = this.seconds < prevTime || prevTime == 0 ? this.seconds : prevTime; editor.putInt("medTime", time); } else { int score = prefs.getInt("medLosses", 0); editor.putInt("medLosses", ++score); } editor.commit(); } else if (Constants.HARD.isEqual(rows, cols, mines)) { SharedPreferences.Editor editor = prefs.edit(); if (victory) { int score = prefs.getInt("hardWins", 0); editor.putInt("hardWins", ++score); int prevTime = prefs.getInt("hardTime", 0); int time = this.seconds < prevTime || prevTime == 0 ? this.seconds : prevTime; editor.putInt("hardTime", time); } else { int score = prefs.getInt("hardLosses", 0); editor.putInt("hardLosses", ++score); } editor.commit(); } requestBackup(); }
@SuppressWarnings("NullableProblems") @Override public boolean dispatchKeyEvent(KeyEvent event) { final ImageButton flagButton = (ImageButton) findViewById(R.id.flagButton); int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { if (minesweeperGame.gameMode == Minesweeper.FLAGMODE) { minesweeperGame.gameMode = Minesweeper.MINEMODE; flagButton.setImageDrawable(getResources().getDrawable(R.drawable.mine)); } else if (minesweeperGame.gameMode == Minesweeper.MINEMODE) { minesweeperGame.gameMode = Minesweeper.FLAGMODE; flagButton.setImageDrawable(getResources().getDrawable(R.drawable.flag)); } } return true; default: return super.dispatchKeyEvent(event); } }
public void resizeMe(int big) { double resizeButton; double resizeText; boolean myCondition; boolean isSizeChanged = false; if (big == 0) { resizeButton = 1.25; resizeText = 0.175; // resizeText = 1; myCondition = true; } else { resizeButton = 0.8; resizeText = 0.175; myCondition = false; } for (int x = 0; x < minesweeperGame.getRows(); ++x) { for (int y = 0; y < minesweeperGame.getCols(); ++y) { Button change = minesweeperGame.board[x][y]; ViewGroup.LayoutParams params = change.getLayoutParams(); if (params != null) { if (((change.getHeight() * resizeButton > 50.0) && !myCondition) || ((change.getHeight() * resizeButton < 100.0) && myCondition)) { params.height = (int) (change.getHeight() * resizeButton); params.width = (int) (change.getWidth() * resizeButton); change.setLayoutParams(params); change.setTextSize((float) (params.height * resizeText)); isSizeChanged = true; } } } } if (isSizeChanged) { minesweeperGame.createNewImages(); } }
public static void main(String[] args) { Minesweeper game = new Minesweeper(10, 20, 20); game.setBombs(); game.checkAll(); System.out.println(); game.getUser().print(); Scanner scan = new Scanner(System.in); while (true) { System.out.println("Enter i="); int i = scan.nextInt(); if (i >= game.getHeight()) { System.out.println( "the number you entered is too big. re-enter the number less than game.getHeight()"); continue; } System.out.println("enter j="); int j = scan.nextInt(); if (j >= game.getWidth()) { System.out.println( "the number you entered is too big. re-enter the number less than game.getWidth()"); continue; } System.out.println("enter F="); int k = scan.nextInt(); if (k != 0 && k != 1) { System.out.println("enter 0(open) or 1(frag)"); continue; } int u = game.turn(i, j, k); if (u != 0) { break; } } }
public static void main(String[] args) { Minesweeper game; game = new MinesweeperImpl(4, 4); game.display(); game.displayInternal(); // game.displayRaw(); while (!game.isGameOver() && !game.isWinningGame()) { Scanner keyboard = new Scanner(System.in); System.out.print("Ingrese fila:"); int row = keyboard.nextInt(); System.out.print("Ingrese columna:"); int col = keyboard.nextInt(); System.out.print("Ingrese accion:"); String action = keyboard.next(); if (action.equals("U")) { game.uncover(row, col); game.display(); // game.displayInternal(); } else if (action.equals("F")) { game.flagAsMine(row, col); game.display(); // game.displayInternal(); } else if (action.equals("C")) { game.clearFlag(row, col); game.display(); // game.displayInternal(); } else { System.out.print("Solo puede ingresar U, F o C"); } } if (game.isWinningGame()) { System.out.print("¡Ganaste!"); } else { game.displayInternal(); System.out.print("¡Perdiste!"); } }