Skip to content

Commit 0278f13

Browse files
committed
added logic for game to be able to restart once the game is complete. this is still a WIP as I need to connect the UI and front end to this, however, the logic and backend side should work.
1 parent a32a28d commit 0278f13

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

app/src/main/java/com/example/chaiss/PlayActivity.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import android.widget.ImageView;
99
import android.widget.Toast;
1010
import androidx.appcompat.app.AppCompatActivity;
11+
import android.content.DialogInterface;
12+
import android.app.AlertDialog;
13+
14+
1115

1216
import com.caverock.androidsvg.SVG;
1317
import com.caverock.androidsvg.PreserveAspectRatio;
@@ -58,6 +62,34 @@ public boolean onTouch(View v, MotionEvent event) {
5862
ImageView backArrow = findViewById(R.id.back_arrow);
5963
backArrow.setOnClickListener(v -> finish());
6064
}
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+
6193

6294
private void handleTouch(float x, float y) {
6395
String square = getSquareFromTouch(x, y);

0 commit comments

Comments
 (0)