class Jeton {

  int dirX;
  int dirY;
  int dir;
  int pX;
  int pY;
  
  static final int [] dX = {  0, 1, 1, 1, 0,-1,-1,-1 };
  static final int [] dY = {  1, 1, 0,-1,-1,-1, 0, 1 };
  
  Jeton(int py,int px) {
    pY = py;
    pX = px;
    choisirDirection();
  }

  void choisirDirection() {
    dir =(int) (Math.random()*8);
    dirX = dX[dir];
    dirY = dY[dir];
  }
  
  void trouverNouvelleDirection(int nbC,int nbL) {
    int px;
    int py;
    do {
      choisirDirection();
      px = pX+dirX;
      py = pY+dirY; }
    while ( ( px < 0 ) || ( py < 0 ) || ( px >= nbC ) || ( py >= nbL ) );
  }
  
  void gererRebond(int nbC,int nbL) {
    int px = pX+dirX;
    int py = pY+dirY;
    if ( ( px < 0 ) || ( py < 0 ) || ( px >= nbC ) || ( py >= nbL ) ) {
      trouverNouvelleDirection(nbC,nbL); }
  }
  
  void deplacer() {
    pX += dirX;
    pY += dirY;
  }
}