Skip to content

Commit 71e23b7

Browse files
committed
Cleaning up final submission
1 parent 29b16f0 commit 71e23b7

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.example.chaiss;
22

3+
/**
4+
* Medium Activity handles the medium difficulty using algorithms
5+
* Similar to HardActivity and EasyActivity
6+
* includes premoving, sound effects, and dragging-dropping pieces
7+
*
8+
*/
9+
310
import android.content.Intent;
411
import android.content.SharedPreferences;
512
import android.graphics.drawable.PictureDrawable;
@@ -86,7 +93,7 @@ public class MediumActivity extends AppCompatActivity {
8693
PIECE_IMAGES.put("q", R.drawable.bqueen);
8794
PIECE_IMAGES.put("k", R.drawable.bking);
8895
}
89-
96+
// Initializes board, pieces, settings, and feed
9097
@Override
9198
protected void onCreate(Bundle savedInstanceState) {
9299
super.onCreate(savedInstanceState);
@@ -259,6 +266,7 @@ private void startRematch() {
259266
updateCapturedPiecesUI();
260267
}
261268

269+
// Handles premoving and sensors for touch for all purposes
262270
private void handleTouch(float x, float y) {
263271
if (gameOver) return;
264272
String square = getSquareFromTouch(x, y);
@@ -378,6 +386,7 @@ private void updateCapturedPiecesUI() {
378386
capturedBlackText.setText("");
379387
}
380388

389+
// Handles logic behind all legal moves for pieces
381390
private void makeMove(String move) {
382391
try {
383392
char turnBefore = currentFEN.split(" ")[1].charAt(0);
@@ -428,14 +437,10 @@ private void makeMove(String move) {
428437
@Override
429438
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
430439
super.onActivityResult(requestCode, resultCode, data);
431-
432440
if (requestCode == 1) {
433441
updateBoard();
434-
435-
// FIX: re-read the sound setting
436442
SharedPreferences prefs = getSharedPreferences("AppSettings", MODE_PRIVATE);
437443
isSoundEnabled = prefs.getBoolean("soundEnabled", true);
438-
439444
Toast.makeText(this, "Settings updated!", Toast.LENGTH_SHORT).show();
440445
}
441446
}
@@ -445,7 +450,7 @@ private String getSquareFromTouch(float x, float y) {
445450
chessBoardImage.getLocationOnScreen(location);
446451
int boardLeft = location[0];
447452
int boardTop = location[1];
448-
int boardSize = chessBoardImage.getWidth(); // assumes square board
453+
int boardSize = chessBoardImage.getWidth();
449454
float localX = x;
450455
float localY = y;
451456
int squareSize = boardSize / 8;
@@ -468,6 +473,7 @@ private String getSquareFromTouch(float x, float y) {
468473
return "" + file + rank;
469474
}
470475

476+
// Analyzes the FEN of the current position
471477
private void updateBoard() {
472478
new Thread(() -> {
473479
try {
@@ -609,6 +615,7 @@ private void showColorSelectionDialog() {
609615
dialog.show();
610616
}
611617

618+
// Starts game after color selection. Also handles piece selection and scrolling of board
612619
private void startGame() {
613620
currentFEN = chessLogic.callAttr("create_board").toString();
614621
updateBoard();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.example.chaiss;
22

3+
/**
4+
* PLayActivity handles the easy difficulty using random legal moves
5+
* Similar to HardActivity and MediumActivity
6+
* includes premoving, sound effects, and dragging-dropping pieces
7+
*
8+
*/
9+
310
import android.content.Intent;
411
import android.graphics.Color;
512
import android.graphics.Typeface;
@@ -84,6 +91,7 @@ public class PlayActivity extends AppCompatActivity {
8491
PIECE_IMAGES.put("k", R.drawable.bking);
8592
}
8693

94+
// Initializes board, pieces, settings, and feed
8795
@Override
8896
protected void onCreate(Bundle savedInstanceState) {
8997
super.onCreate(savedInstanceState);
@@ -278,6 +286,7 @@ private void startRematch() {
278286
updateCapturedPiecesUI();
279287
}
280288

289+
// Handles premoving and sensors for touch for all purposes
281290
private void handleTouch(float x, float y) {
282291
if (gameOver) return;
283292
String square = getSquareFromTouch(x, y);
@@ -386,6 +395,7 @@ private void updateCapturedPiecesUI() {
386395
capturedBlackText.setText("");
387396
}
388397

398+
// Handles logic behind all legal moves for pieces
389399
private void makeMove(String move) {
390400
try {
391401
char turnBefore = currentFEN.split(" ")[1].charAt(0);
@@ -436,6 +446,7 @@ private String getSquareFromTouch(float x, float y) {
436446
return "" + (char)('a'+col) + (row+1);
437447
}
438448

449+
// Analyzes the FEN of the current position
439450
private void updateBoard() {
440451
new Thread(() -> {
441452
try {
@@ -502,6 +513,7 @@ protected void onDestroy() {
502513
}
503514
}
504515

516+
// Function for random legal moves
505517
private void makeRandomAIMove() {
506518
new Handler(Looper.getMainLooper()).postDelayed(() -> {
507519
try {
@@ -565,6 +577,7 @@ private void showColorSelectionDialog() {
565577
dialog.show();
566578
}
567579

580+
// Starts game after color selection. Also handles piece selection and scrolling of board
568581
private void startGame() {
569582
currentFEN = chessLogic.callAttr("create_board").toString();
570583
updateBoard();

0 commit comments

Comments
 (0)