M Winda/src/winda/gui/WindaView.java poprawiono animację

M    Winda/src/winda/logic/AlgorytmGoraDol.java naprawiono algorytm
M    Winda/src/winda/logic/PasazerSort.java usunięto błąd podwójnego zwiększania iteratora j
This commit is contained in:
Przemek Grondek 2011-04-20 00:18:40 +00:00
parent 34f526e708
commit ddba9e63f5
4 changed files with 51 additions and 23 deletions

View File

@ -59,10 +59,6 @@ platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}

View File

@ -102,9 +102,17 @@ public class WindaView extends FrameView{
}
private void setupAnimation(){
int []passangers = new int[this.floor_count];
for(int i=0;i<this.floor_count;i++)
passangers[i] = w.GetTrasa().get(i).pasazerowieWsiadający.size();
int []passangers = new int[this.floor_count+1];
ArrayList<Pietro> temp = (ArrayList) this.w.GetTrasa();
for(int i=0;i<temp.size();i++){
int floor = temp.get(i).numerPietra;
int tmp = passangers[floor];
System.out.println("iterator: "+i+"<"+temp.size());
System.out.println("pietra: "+floor+"<"+this.floor_count);
passangers[floor] = tmp+ temp.get(i).pasazerowieWsiadający.size();
}
/* for(int i=0;i<this.floor_count && i<w.GetTrasa().size();i++)
passangers[i] = w.GetTrasa().get(i).pasazerowieWsiadający.size();*/
this.em.setPassangersOnFloors(passangers);
@ -123,7 +131,7 @@ public class WindaView extends FrameView{
}
private void drawAnimation(){
this.em = new ElevatorMovement(12);
this.em = new ElevatorMovement(12+1);
this.scrollPane1.add(em.getElevatorAnimation());
}
@ -772,8 +780,8 @@ public class WindaView extends FrameView{
String ip = (String) jSpinner1.getValue().toString();
int iloscPieter = Integer.parseInt(ip);
w.SetIloscPieter(iloscPieter);
this.newAnimation(iloscPieter);
this.floor_count = iloscPieter;
this.newAnimation(iloscPieter+1);
this.floor_count = iloscPieter+1;
}//GEN-LAST:event_jSpinner1StateChanged
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

View File

@ -22,16 +22,19 @@ public class AlgorytmGoraDol implements IAlgorytm {
public AlgorytmGoraDol(){
this.start_floor = 0;
this.floor_count = 0;
this.floors = new ArrayList();
}
public AlgorytmGoraDol(int floor_count){
this.start_floor = 0;
this.floor_count = floor_count;
this.floors = new ArrayList();
}
public AlgorytmGoraDol(int floor_count, int start_floor){
this.floor_count = floor_count;
this.start_floor = start_floor;
this.floors = new ArrayList();
}
public void setStartFloor(int start_floor){
@ -43,10 +46,11 @@ public class AlgorytmGoraDol implements IAlgorytm {
}
public void setFloorCount(int floor_count){
System.out.println("setFloorCount ("+floor_count+")");
this.floor_count = floor_count;
}
public int getFloorCount(int floor_count){
public int getFloorCount(){
return this.floor_count;
}
@ -55,13 +59,17 @@ public class AlgorytmGoraDol implements IAlgorytm {
ArrayList<Pietro> pietra = this.setupPietra();
while(this.pasazerowie.get(i).GetStart()<this.acctual_floor)
i++;
while(i<this.pasazerowie.size())
while(i<this.pasazerowie.size()){
if( this.pasazerowie.get(i).GetStart()<this.pasazerowie.get(i).GetStop()){
pietra.get(this.pasazerowie.get(i).GetStart()).pasazerowieWsiadający.add(this.pasazerowie.get(i));
pietra.get(this.pasazerowie.get(i).GetStop()).pasazerowieWysiadajacy.add(this.pasazerowie.get(i));
}
i++;
}
this.clearPietra(pietra);
this.floors.addAll(pietra);
if(!pietra.isEmpty())
this.floors.addAll(pietra);
}
private void goDown(){
@ -69,26 +77,29 @@ public class AlgorytmGoraDol implements IAlgorytm {
ArrayList<Pietro> pietra = this.setupPietra();
while(this.pasazerowie.get(i).GetStart()<this.acctual_floor)
i++;
while(i<this.pasazerowie.size())
while(i<this.pasazerowie.size()){
if( this.pasazerowie.get(i).GetStart()>this.pasazerowie.get(i).GetStop()){
pietra.get(this.pasazerowie.get(i).GetStart()).pasazerowieWsiadający.add(this.pasazerowie.get(i));
pietra.get(this.pasazerowie.get(i).GetStop()).pasazerowieWysiadajacy.add(this.pasazerowie.get(i));
}
i++;
}
this.clearPietra(pietra);
this.floors.addAll(pietra);
if(!pietra.isEmpty())
this.floors.addAll(pietra);
}
private void clearPietra(ArrayList<Pietro> pietro){
Pietro tmp;
for(int i=0;i<pietro.size();i++){
tmp=pietro.get(i);
if(tmp.pasazerowieWsiadający.isEmpty() && tmp.pasazerowieWysiadajacy.isEmpty())
for(int i=pietro.size()-1;i >= 0;i--){
if(pietro.get(i).pasazerowieWsiadający.isEmpty() && pietro.get(i).pasazerowieWysiadajacy.isEmpty())
pietro.remove(i);
}
}
public List<Pietro> setCourse(){
PasazerSort sort = new PasazerSort(pasazerowie);
this.calculateFloors();
PasazerSort sort = new PasazerSort(this.pasazerowie);
sort.sortByStart();
this.acctual_floor = this.start_floor;
@ -103,7 +114,20 @@ public class AlgorytmGoraDol implements IAlgorytm {
}
public void SetMaxPietro(int maxPietro) {
this.setFloorCount(floor_count);
this.setFloorCount(floor_count+1);
}
/*
* Fix for wrong number of floors
*/
private void calculateFloors(){
for(int i=0;i<this.pasazerowie.size();i++){
if(this.pasazerowie.get(i).GetStart()>this.floor_count)
this.floor_count = this.pasazerowie.get(i).GetStart();
if(this.pasazerowie.get(i).GetStop()>this.floor_count)
this.floor_count = this.pasazerowie.get(i).GetStop();
}
this.floor_count++;
}
private ArrayList<Pietro> setupPietra(){

View File

@ -24,7 +24,7 @@ public class PasazerSort {
for( i = 1+ (j = start);i<end;i++)
if(this.array.get(i).GetStart()<this.array.get(start).GetStart()){
Pasazer tmp = this.array.get(++j);
this.array.set(++j, this.array.get(i));
this.array.set(j, this.array.get(i));
this.array.set(i, tmp);
}
@ -38,7 +38,7 @@ public class PasazerSort {
private void mksortByStart(int start, int end){
if( start < end ){
int tmp = this.splitByStart( start, end );
this.mksortByStart( start, tmp-1 );
this.mksortByStart( start, tmp );
this.mksortByStart( tmp+1, end );
}
}