Commit adc20745 authored by Jared Shi's avatar Jared Shi
Browse files

fixed board reset

parent 26441abf
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -550,6 +550,46 @@ public:
        return verifiedMoves;
    }

    void reset()
    {
        for (int ii = 0; ii < 64; ii++)
        {
            boardState[ii] = Piece();
        }
        boardState[0] = Piece(1, 4);
        boardState[1] = Piece(1, 2);
        boardState[2] = Piece(1, 3);
        boardState[3] = Piece(1, 5);
        boardState[4] = Piece(1, 6);
        boardState[5] = Piece(1, 3);
        boardState[6] = Piece(1, 2);
        boardState[7] = Piece(1, 4);
        boardState[8] = Piece(1, 1);
        boardState[9] = Piece(1, 1);
        boardState[10] = Piece(1, 1);
        boardState[11] = Piece(1, 1);
        boardState[12] = Piece(1, 1);
        boardState[13] = Piece(1, 1);
        boardState[14] = Piece(1, 1);
        boardState[15] = Piece(1, 1);
        boardState[48] = Piece(0, 1);
        boardState[49] = Piece(0, 1);
        boardState[50] = Piece(0, 1);
        boardState[51] = Piece(0, 1);
        boardState[52] = Piece(0, 1);
        boardState[53] = Piece(0, 1);
        boardState[54] = Piece(0, 1);
        boardState[55] = Piece(0, 1);
        boardState[56] = Piece(0, 4);
        boardState[57] = Piece(0, 2);
        boardState[58] = Piece(0, 3);
        boardState[59] = Piece(0, 5);
        boardState[60] = Piece(0, 6);
        boardState[61] = Piece(0, 3);
        boardState[62] = Piece(0, 2);
        boardState[63] = Piece(0, 4);
    }

    void verifyMoveTarget(int currentKey, int targetKey)
    {
        // calls the verifyMove function before executing a move command
@@ -1012,8 +1052,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_example_ndktest_ChessView_startGame(J
/*
 * Delete the instance of the game when gameover or quit (NOT FINISHED)
 */
extern "C" JNIEXPORT void JNICALL Java_com_example_ndktest_GameBoard_endGame(JNIEnv* env,jobject mainActivityInstance /* this */) {
    delete board;
extern "C" JNIEXPORT void JNICALL Java_com_example_ndktest_MainActivity_resetGame(JNIEnv* env,jobject mainActivityInstance /* this */) {
    board->reset();
}


+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public static TextView btext;
        you quit and want to restart.
     */

    public native void endGame();
    public native void resetGame();

    /*
        the pieceid player wants to promote to (should ignore if the
+21 −3
Original line number Diff line number Diff line
package com.example.ndktest;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;


public class MainActivity extends AppCompatActivity {
    static {
        System.loadLibrary("ndktest");
    }
    public native void resetGame();

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            resetGame();
            return true;

        }

    public native void startGame();
    public native void endGame();
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);



        setContentView(R.layout.activity_main);
        Button mainButton = findViewById(R.id.angry_btn);

@@ -29,7 +44,9 @@ public class MainActivity extends AppCompatActivity {
        mainButton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v) {
                resetGame();
                startActivity(new Intent(MainActivity.this, GameBoard.class));

            }
        });
        tutorialButton.setOnClickListener(new View.OnClickListener()
@@ -41,6 +58,7 @@ public class MainActivity extends AppCompatActivity {
        aiButton.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v) {
                resetGame();
                startActivity(new Intent(MainActivity.this, AiGame.class));
            }
        });