Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

java - 跳棋游戏捕获逻辑的实现(Implementation of Capture Logic For Checkers Game)

I need help with the capture logic for my Android Application.

(我需要有关Android应用程序捕获逻辑的帮助。)

I have implemented movement where the pieces only move diagonally.

(我实现了运动,其中棋子只沿对角线移动。)

So, now I need help so that I would be able to implement the capture logic for checkers game.

(因此,现在我需要帮助,以便能够实现跳棋游戏的捕获逻辑。)

Here is my code I used move movement and to move diagonally:

(这是我使用移动动作并沿对角线移动的代码:)

private boolean handleDownAction(MotionEvent event) {

        // determine what kind of touch event we have

        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && touch == false) {
            theX = (int) (event.getX() / WidthBoard);
            theY = (int) (event.getY() / HeightBoard);
            touch = true;
            invalidate();
            return true;
        }


        // determine what kind of touch event we have
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && touch == true) {

            if(player2 == true) {
                if(coins[theY][theX] == 2) {



                    axixX = (int) (event.getX() / WidthBoard);
                    axixY = (int) (event.getY() / HeightBoard);

                    if(axixY == theY - 1 && axixX == theX + 1  ){

                        //if( pieces[end_y][end_x] == 1){

                        coins[axixY][axixX] = coins[theY][theX];

                        Toast.makeText(getContext(), "Player 2 Your Turn", Toast.LENGTH_LONG).show();

                        coins[theY][theX] = 0;
                        player1 = true;
                        player2 = false;

                        //}
                        touch = false;

                        invalidate();
                    }

                    else {

                        Toast.makeText(getContext(), "Illegal Move Can Only Move Diagonaly", Toast.LENGTH_LONG).show();
                    }


                    System.out.println("ACTION DOWN Y " + axixY+ " End x " + axixX  );
                    System.out.println("Start X " + theY + " Start Y " + theX);
                    //  touch = false;
                    // playerPieces(event,start_y,start_x);
                }
            }

            else if( coins[theY][theX] == 1){
                axixX = (int) (event.getX() / WidthBoard);
                axixY = (int) (event.getY() / HeightBoard);
                System.out.println("ACTION DOWN AC " + axixY + " " + axixX);

                if(axixY == theY+1 && axixX == theX -1 ){
                    Toast.makeText(getContext(), "Player 1 Your Turn", Toast.LENGTH_LONG).show();

                    coins[axixY][axixX]= coins[theY][theX] ;
                    coins[theY][theX]= 0;
                    player1=false;
                    player2=true;
                    touch = false;

                    invalidate();

                }

                // invalidate();

            }
            touch =false;
            return true;
        }

        System.out.println( x + " " + y);

        return true;

    }

Please help me to resolve this issue.

(请帮助我解决此问题。)

  ask by PandaMan108 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...