|
8 | 8 | import android.widget.ImageView; |
9 | 9 | import android.widget.Toast; |
10 | 10 | import androidx.appcompat.app.AppCompatActivity; |
| 11 | +import android.content.DialogInterface; |
| 12 | +import android.app.AlertDialog; |
| 13 | + |
| 14 | + |
11 | 15 |
|
12 | 16 | import com.caverock.androidsvg.SVG; |
13 | 17 | import com.caverock.androidsvg.PreserveAspectRatio; |
@@ -58,6 +62,34 @@ public boolean onTouch(View v, MotionEvent event) { |
58 | 62 | ImageView backArrow = findViewById(R.id.back_arrow); |
59 | 63 | backArrow.setOnClickListener(v -> finish()); |
60 | 64 | } |
| 65 | + private void showGameOverDialog(String result) { |
| 66 | + new AlertDialog.Builder(this) |
| 67 | + .setTitle("Game Over") |
| 68 | + .setMessage("The game is over. " + result + ". Would you like to rematch?") |
| 69 | + .setPositiveButton("Rematch", new DialogInterface.OnClickListener() { |
| 70 | + @Override |
| 71 | + public void onClick(DialogInterface dialog, int which) { |
| 72 | + startRematch(); |
| 73 | + } |
| 74 | + }) |
| 75 | + .setNegativeButton("Exit", new DialogInterface.OnClickListener() { |
| 76 | + @Override |
| 77 | + public void onClick(DialogInterface dialog, int which) { |
| 78 | + finish(); // Exits Activity |
| 79 | + } |
| 80 | + }) |
| 81 | + .show(); |
| 82 | + } |
| 83 | + private void startRematch() { |
| 84 | + currentFEN = chessLogic.callAttr("create_board").toString(); |
| 85 | + selectedSquare = null; |
| 86 | + legalMoves = null; |
| 87 | + |
| 88 | + // Updates the board view |
| 89 | + updateBoard(); |
| 90 | + } |
| 91 | + |
| 92 | + |
61 | 93 |
|
62 | 94 | private void handleTouch(float x, float y) { |
63 | 95 | String square = getSquareFromTouch(x, y); |
|
0 commit comments