Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnimationThread extends Thread{
- private gameBoard g;
- private circleF4[][] game;
- private circleF4 moneta;
- private int x;
- private int y;
- private boolean found;
- private circleF4 foundDisc;
- private int turno;
- private boolean fancy;
- public AnimationThread() {
- //Costruttore di base che serve all'inizializzazione della gameBoard
- }
- public AnimationThread(gameBoard g,circleF4[][] game, circleF4 moneta, int positionX, int turno,boolean fancy) {
- this.g=g;
- this.game=game;
- this.moneta=moneta;
- this.turno=turno;
- this.fancy=fancy;
- x=0;
- y=0;
- found=false;
- //cerco e ottengo la posizione del "disco di arrivo"
- for(int i=5;i>=0 && !found;i--){
- for(int j=0;j<7 && !found;j++){
- circleF4 disco=game[i][j];
- if(j==positionX && disco.getStatus()==0){
- x=disco.getX();
- y=disco.getY();
- foundDisc=disco;
- found=true;
- }
- }
- }
- }
- @Override
- public void run(){
- if(found){
- moneta.setX(x);
- if(fancy){
- //Grafica complessa
- for(int i=moneta.getY();i<=y;i++){
- moneta.setY(i);
- g.repaint();
- try {Thread.sleep(1);} catch (InterruptedException ex) {this.interrupt();}
- }
- }else{
- //Grafica superveloce
- moneta.setY(y);
- g.repaint();
- }
- //Cooldown di 250ms tra una mossa e l'altra
- try { Thread.sleep(100); } catch (InterruptedException ex) { }
- //Imposto il colore al disco
- foundDisc.setStatus(turno);
- //Controllo il vincitore
- try { g.checkWinner(); } catch (InterruptedException ex) { }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement