Jump to content

Java 2D Arrays


msp301
 Share

Recommended Posts

I am trying to move an object from 1 location in a 2D array to another, but I seem to be referencing the object itself and making it equal to another :S

This a code snippet of what I've been doing, any pointers would be appreciated

ChessPiece currentLocation = objBoard.board[curX][curY];    //current coordinates of piece
ChessPiece destination = objBoard.board[desX][desY];    //intended destination

if((desX == curX) && (desY == (curY + 1)))
    {
      destination = currentLocation;    //copy contents of current location to destination square
      currentLocation = null;    //remove contents of the old location to complete the piece move
    }

Thanks :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...