Download presentation
Presentation is loading. Please wait.
Published byMarybeth Robertson Modified over 9 years ago
1
Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third // parameter. The stack specified by the fourth parameter // is avaialable for use as a spare. if (disks == 1) { // There is only one disk to be moved. Just move it. console.putln("Move a disk from stack number " + from + " to stack number " + to); } else { // Move all but one disk to the spare stack, then move the bottom disk, then put all the // other disks on top of it. TowersOfHanoi(disks-1, from, spare, to); console.putln("Move a disk from stack number " + from + " to stack number " + to); TowersOfHanoi(disks-1, spare, to, from); }
2
Labirinto
9
Inseguitore public class Utils { /** readFile */ public static String readFile(String file) { String str = new String(""); char buf[] = new char[8192]; try { FileReader fin = new FileReader(file); while(fin.read(buf) != -1) str += new String(buf); } catch(Exception e) { str = "Eccezione rilevata: " + e + " "; } return str; } /** replace */ public static String replace(String str, String source, String dest) { int index = 0, lunghSource = source.length(); while ( (index = str.indexOf(source,index)) != -1) { str = str.substring(0,index) + dest + str.substring(index+lunghSource); index += dest.length(); } return str; }
10
/** * getYear: from a date (source format indicated by flag) */ public static int getYear(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(0,4)); else return 0; } catch(Exception e) {} return 0; } /** * getMonth: from a date (source format indicated by flag) */ public static int getMonth(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(5,7)); else return 0; } catch (Exception e) {} return 0; } /** * getDay: from a date (source format indicated by flag) */ public static int getDay(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(8,10)); else return 0; } catch(Exception e) {} return 0; } /** * getHour: from a date * (source format indicated by flag) */ public static int getHour(String date, int flag){ try { if (flag == 0) return Integer.parseInt(date.substring(11,13)); else return 0; } catch(Exception e) {} return 0; } /** * getMinutes: from a date (source format indicated by flag) */ public static int getMinutes(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(14,16)); else return 0; } catch (Exception e) {} return 0; }
11
/** * formatDate */ public static String formatDate(String date, int flag) { String strHour; String strMin; int h = Utils.getHour(date,0); if (h < 10) strHour = "0"+h; else strHour = "" + h; int m = Utils.getMinutes(date,0); if (m < 10) strMin = "0"+m; else strMin = ""+m; if (flag == 0) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; if (flag == 1) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0); // default return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; }
12
/** * Interface for timer functions * * @author Ignazio Locatelli - Media Illusion - (C) 2000 */ package it.MediaIllusion.Anim; public interface TimerInterface { public void tick(); }
13
* Timer class: calls the tick method every n milliseconds. * * Timer timer = new Timer(this,1000); // 1 second interval * timer.start(); * * @author Ignazio Locatelli */ package it.MediaIllusion.Anim; public class Timer implements Runnable { // main thread protected Thread myThread = null; // milliseconds to wait protected long interval; // interface used TimerInterface callback;
14
/** * default constructor */ public Timer() { interval = 1000; } /** * constructor * @param long millisecond number of millisecond for the interval * @param TimerInterface callback reference to the interface */ public Timer(long milliseconds, TimerInterface callback) { interval = milliseconds; this.callback = callback; } /** * return milliseconds for an interval */ public long getInterval() { return interval; } /** * set interval * @param long milliseconds number of milliseconds */ public void setInterval(long milliseconds) { interval = milliseconds; }
15
/** * starts the timer */ public void start() { myThread = new Thread(this); myThread.start(); } /** * stops the timer */ public void stop() { myThread.stop(); myThread = null; }
16
/** * run */ public void run() { while(true) { long sTime = System.currentTimeMillis(); if (callback != null) callback.tick(); long eTime = System.currentTimeMillis(); long sleep = interval - (eTime-sTime); if (sleep <= 0) continue; try { Thread.sleep(sleep); } catch (Exception e) { System.out.println("Exception during sleep operation\n"); }
17
/** * Pos: class abstracting a 2D position on a grid * @author Ignazio Locatelli - Media Illusion (C) 2000 */ public class Pos { public int x; public int y; /** * Position */ public Pos() { x = y = 0; } /** * Position */ public Pos(int x, int y) { this.x = x; this.y = y; }
18
public class InseguitoreConst { public static final int NUM_VITE=4; public static final int MAP_ROWS = 39; public static final int MAP_COLOUMNS = 39; public static final int MAP_CELL_DIMENSION = 8; public static final int PASSO = 4; public static final int DISTANZA_CONTATTO = 36; public static final int SPEED=18; public static final int ACCELERAZIONE=4; public static final int ATTESA=1000; public static final int OFFSET_X = 54; public static final int OFFSET_Y = 34; public static final int OFFSET_PERS_X = 50; public static final int OFFSET_PERS_Y = 30; public static final int START_X1 = 416; public static final int START_X2 = 465; public static final int START_Y1 = 323; public static final int START_Y2 = 377;
19
public static final int map[][][] = { //liv 1 { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
20
import java.awt.image.*; import java.awt.*; import java.applet.*; public class FiltraImmagine extends RGBImageFilter { public FiltraImmagine() { canFilterIndexColorModel = true; } public Image filter(Applet a, Image in) { return a.createImage( new FilteredImageSource(in.getSource(),this) ); } public int filterRGB(int x, int y, int rgb) { int r = ((rgb >> 16) & 0xff)/4; // estra la componente rossa int g = ((rgb >> 8) & 0xff)/4; // verde int b = (rgb & 0xff)/4; // blu int k = (int)(.56*g+.33*r+.11*b); return (0xff000000 | k << 16 | k << 8 | k); //return rgb; }
21
* @author Ing. Alessandro Campi */ public class Rettangolo { int pezziVisitati=0; int totalePezzi=0; //vertici //in alto a sinistra public int x1, y1; //in basso a destra public int x2, y2; public int x1RealeNormale, y1RealeNormale; public int x1RealeScuro, y1RealeScuro; public int w, h; public int saltoNormaleX, saltoNormaleY; public int saltoNormaleDirettoX,saltoNormaleDirettoY; public int saltoScuroX, saltoScuroY; /** Creates new Rettangolo */ public Rettangolo(int ix1,int iy1,int ix2,int iy2, int xSfondoLivelloNormale,int ySfondoLivelloNormale, int xSfondoLivelloScuro,int ySfondoLivelloScuro, int xBackground,int yBackground) { x1=ix1; y1=iy1; x2=ix2; y2=iy2; x1RealeNormale=xSfondoLivelloNormale+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeNormale=ySfondoLivelloNormale+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1;
22
x1RealeScuro=xSfondoLivelloScuro+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeScuro=ySfondoLivelloScuro+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; w=(x2-x1)*InseguitoreConst.MAP_CELL_DIMENSION-1; h=(y2-y1)*InseguitoreConst.MAP_CELL_DIMENSION-1; saltoNormaleX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroX=InseguitoreConst.OFFSET_X- xSfondoLivelloScuro+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroY=InseguitoreConst.OFFSET_Y- ySfondoLivelloScuro+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; }
23
public boolean isIn(int x,int y) { return (x>=x1&&x =y1&&y<=y2); } public void incrementaVisitati() { pezziVisitati++; } public void incrementaTotale() { totalePezzi++; } public boolean controllaCompleto() { return (pezziVisitati==totalePezzi); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.