I need move the players in board like Monopoly

Hi i need help for move players in board. I can show players but when move the player i can’t see this player. I use this code for set the player in tile.
pl1.setTileCount(2) and i thin this move the player for other tile but not show when use pl1.showPlayer(), its say the function is not a function but i’m not understand how resolve this problem because when start game show the players in board.

this is url for my game:
Game

so pl1 you’ve set to a tile class object, however the showPlayer function is in the Player class. The players are showing because you’ve called the showPlayer function in the for loop just before.

It also seems odd that in the Tile Constructor you’ve created the variable id

  constructor(x, y, lar, alt, id) {

however you use the id as the radius for the rectangle

    rect(this.centerPos.x, this.centerPos.y, this.lar, this.alt, this.id);

and you’ve defined the id of every tile to a radius variable that you’ve set to 0

tileColRight[i] = new Tile(width - width_x, posY2, height_y, height_y, radius);

it also appears that where you are calling setTileCount is bad. if you print the tileID of pl1 after setting it, the number continues going up, because it’s adding 2 every frame. You’ll need to call it somewhere other than draw.

I won’t provide you a full answer. By looking at the code, I suggest you implement some changes to encapsulate properties directly under proper objects. For instance, a player should contain position info or at least what title it is in. The Title should not manage the player position directly. This is my first suggestion (needs to be evaluated further) of what Player should look like, code below. I have added mouseHover and mouseDragged functions to show you the way I suggest you go next. You call one of this function in the mousePressed() and mouseReleased() functions to manage piece position live.

As a next step, I suggest you continue working by decoupling Title and Player. Notice the player only needs to know the Title ID and your TitleManager will first lay out the titles and they it will layout the players. There other approaches so this suggestion doe snot have to be the final solution.

Kf

P.S. Not sure what diceResults is about… I am thinking this should not be here. To be evaluated at a later time…

class Player {
  constructor(id) {
    this.id = id;
    this.tileID = 0;
    this.rad = 5;
    this.px;
    this.py;
    this.isDragged = false;
  }

  getID() {
    return this.id;
  }

  getTileID() {
    return this.tileID;
  }

  setTileCount(diceResult) {
    this.tileID = this.tileID + diceResult;
  }

  mouseHover(mx, my) {
    return dist(mx, my, this.px, this.py) < this.rad;
  }

  mouseDragged(mx, my) {
    if (mouseHover) {
      this.isDragged = true;
    }
  }

  resetDrag() {
    this.isDragged = false;
  }
}

Good feeback there kfrajer. I’ma stop going through the code as it’s kind of all over the place. kfrajer’s suggestion is probably the best direction to move. Good luck Xremix!