Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public class AnimationThread extends Thread{
  2. private gameBoard g;
  3. private circleF4[][] game;
  4. private circleF4 moneta;
  5. private int x;
  6. private int y;
  7. private boolean found;
  8. private circleF4 foundDisc;
  9. private int turno;
  10. private boolean fancy;
  11.  
  12. public AnimationThread() {
  13. //Costruttore di base che serve all'inizializzazione della gameBoard
  14. }
  15.  
  16. public AnimationThread(gameBoard g,circleF4[][] game, circleF4 moneta, int positionX, int turno,boolean fancy) {
  17. this.g=g;
  18. this.game=game;
  19. this.moneta=moneta;
  20. this.turno=turno;
  21. this.fancy=fancy;
  22. x=0;
  23. y=0;
  24.  
  25. found=false;
  26. //cerco e ottengo la posizione del "disco di arrivo"
  27. for(int i=5;i>=0 && !found;i--){
  28. for(int j=0;j<7 && !found;j++){
  29. circleF4 disco=game[i][j];
  30. if(j==positionX && disco.getStatus()==0){
  31. x=disco.getX();
  32. y=disco.getY();
  33. foundDisc=disco;
  34. found=true;
  35. }
  36. }
  37. }
  38.  
  39. }
  40.  
  41. @Override
  42. public void run(){
  43. if(found){
  44. moneta.setX(x);
  45. if(fancy){
  46. //Grafica complessa
  47. for(int i=moneta.getY();i<=y;i++){
  48. moneta.setY(i);
  49. g.repaint();
  50. try {Thread.sleep(1);} catch (InterruptedException ex) {this.interrupt();}
  51. }
  52. }else{
  53. //Grafica superveloce
  54. moneta.setY(y);
  55. g.repaint();
  56. }
  57.  
  58. //Cooldown di 250ms tra una mossa e l'altra
  59. try { Thread.sleep(100); } catch (InterruptedException ex) { }
  60.  
  61. //Imposto il colore al disco
  62. foundDisc.setStatus(turno);
  63.  
  64. //Controllo il vincitore
  65. try { g.checkWinner(); } catch (InterruptedException ex) { }
  66.  
  67. }
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement