09-12-2004, 10:10 AM | #21 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
Tadaa! Loop works fine, except that it draw black spots instead of the boxes, but it knows where they have to come. Probably just named them wrong. Borders of any level are set too. Now the next part: Giving properties to each part (so that he won't walk through walls anymore)
|
||
|
|
10-12-2004, 12:30 PM | #22 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
|
||
|
|
10-12-2004, 12:44 PM | #23 | ||
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
|
you have to post the code trough forum. I have only VJ.net on this computer.
Also, can you explain in plain english what you like to accomplishe. While you do this, here is my recomendation for code (In example I'll write the pseudo code): [code] move up: check if cell is empty if yes, just move up if no, check if is the end of the world () if yes, don't move, put something , or play some bad sound (perhaps fart ) if no, check what colort is the first box you hitting check the next box if is empty, move only that one box if is not empty, check if next box is same color if it is, do the same check with next cell if not, play that bad sound again. in this checks, you should also make sure that you don't move world's blocks. also, can you tell how do you check win situation |
||
|
|
10-12-2004, 12:56 PM | #24 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
Well, that already works fine (but I like the fart-sound thing ) Main problem now is the winning condition. This's the code:
Code:
import bvp.*; import java.io.*; public class VoorbeeldPijltjes { * *public static void main(String[] args) { String bestandsnaam; bestandsnaam = "Voorbeeld.txt"; BestandsInvoer bi = new BestandsInvoer (bestandsnaam); String regel = bi.leesRegel(); // ******************************** // ** De begin-coordinaten lezen ** // ******************************** int Checker = 0; Checker = Counting(regel, Checker)+1; int Temp = Counting(regel, Checker); String tempX = regel.substring(4,Temp); int dimX = Integer.parseInt(tempX); Checker = Counting(regel, Checker)+1; int TempStart = Temp + 1; Temp = Counting(regel, Checker); String tempY = regel.substring(TempStart); int dimY = Integer.parseInt(tempY); // ************************* // ** Nieuw bord plaatsen ** // ************************* Bus bus=new Bus(); Figuren verz = new Figuren("dozo2.fig"); int e=verz.getEenheid("grid"); Bord bord=new Bord("Dozo World", dimX*e, dimY*e, bus); int plaatsX; int plaatsY = 0; int x = 0; int y = 0; int[] spelbord; spelbord = new int[dimX*dimY]; // *************************** // ** Plaatsen van de items ** // *************************** for (plaatsY = 0; plaatsY < dimY; plaatsY++) { regel = bi.leesRegel(); for (plaatsX = 0; plaatsX < dimX; plaatsX++) { *switch(regel.charAt(plaatsX)) { * case '.': spelbord[(plaatsY*dimX) + plaatsX] = 0; * * * bord.plaatsFiguur("vloer", verz, plaatsX*e, plaatsY*e); * * * break; * case 'B': spelbord[(plaatsY*dimX) + plaatsX] = 1; * * * bord.plaatsFiguur("doos1", verz, plaatsX*e, plaatsY*e); * * * break; * case 'R': spelbord[(plaatsY*dimX) + plaatsX] = 2; * * * bord.plaatsFiguur("doos2", verz, plaatsX*e, plaatsY*e); * * * break; * case '#': spelbord[(plaatsY*dimX) + plaatsX] = 3; * * * bord.plaatsFiguur("muur", verz, plaatsX*e, plaatsY*e); * * * break; * case '@': spelbord[(plaatsY*dimX) + plaatsX] = 4; * * * bord.plaatsFiguur("mannetje", verz, plaatsX*e, plaatsY*e); * * * x=plaatsX; *y=plaatsY; * * * break; *} } } * * * *bord.toonVeranderingen(); // ********************* // ** Bewegen + duwen ** // ********************* * * * *while (true) { * * * * * *Boodschap boodschap=bus.getBoodschap(); * * * * * *if (boodschap.getType().equals("toetsenbord")) { * * * * * * * *String data=boodschap.getData(); * * * * * * * *if (data.startsWith("!-")) { * *int oldx=x; int oldy=y; * *int object; * *int d; // ** Naar links * *if (data.equals("!-Left") && x>1) { *d=x; *d--; *if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * x--; *} *if (spelbord[(y*dimX)+d] == 1 || spelbord[(y*dimX)+d] == 2) { * object = spelbord[(y*dimX)+d]; * System.out.println("Object = "+ object); * do { * *d--; * } while (spelbord[(y*dimX)+d] == object); * *if (spelbord[(y*dimX)+d] == 0) { * * spelbord[(y*dimX)+d] = object; * * bord.plaatsFiguur("doos"+ object, verz, d*e, y*e); * * bord.plaatsFiguur("vloer", verz, x*e, y*e); * * spelbord[(y*dimX)+x] = 0; * * x--; * * bord.plaatsFiguur("mannetje", verz, x*e, y*e); * * spelbord[(y*dimX)+x] = 4; * } * *} * * *} // ** Naar rechts * *if (data.equals("!-Right") && x<(dimX-1)) { *d=x; *d++; *if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * x++; *} *if (spelbord[(y*dimX)+d] == 1 || spelbord[(y*dimX)+d] == 2) { * object = spelbord[(y*dimX)+d]; * System.out.println("Object = "+ object); * do { * *d++; * } while (spelbord[(y*dimX)+d] == object); * if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+d] = object; * *bord.plaatsFiguur("doos"+ object, verz, d*e, y*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *x++; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } *} * * *} * * * * // ** Naar boven * *if (data.equals("!-Up") && y>1) { *d=y; *d--; *if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * y--; *} *if (spelbord[(d*dimX)+x] == 1 || spelbord[(d*dimX)+x] == 2) { * object = spelbord[(d*dimX)+x]; * System.out.println("Object = "+ object); * do { * *d--; * } while (spelbord[(d*dimX)+x] == object); * if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(d*dimX)+x] = object; * *bord.plaatsFiguur("doos"+ object, verz, x*e, d*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *y--; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } * *} * * *} // ** Naar beneden * *if (data.equals("!-Down") && y<(dimY-1)) { *d=y; *d++; *if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * y++; *} *if (spelbord[(d*dimX)+x] == 1 || spelbord[(d*dimX)+x] == 2) { * object = spelbord[(d*dimX)+x]; * System.out.println("Object = "+ object); * do { * *d++; * } while (spelbord[(d*dimX)+x] == object); * if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(d*dimX)+x] = object; * *bord.plaatsFiguur("doos"+ object, verz, x*e, d*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *y++; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } * *} * * *} * * * *bord.plaatsFiguur("vloer", verz, oldx*e, oldy*e); * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *bord.toonVeranderingen(); // ********************************************* // ** Checken voor dozen die mogen verdwijnen ** *-> Nog aan aan't werken // ********************************************* int g; int h; int doos; int teller = 0; int[] groep; groep = new int[dimX*dimY]; for (doos = 1; doos <=2; doos++) { *for (g=0; g < dimX; g++) { * for (h=0; h < dimY; h++) { * *if (spelbord[(h*dimX)+g] == doos) { * * teller ++; * * groep[teller] = (h*dimX)+g; * *} * *else { * * teller = 0; * *} * *if (teller == 4 && doos == 1) { * * System.out.println("Voldoende dozen 1"); * *} * *if (teller == 3 && doos == 2) { * * System.out.println("Voldoende dozen 2"); * *} * * * } * *} } * * * * * * * *} * * * * * *} * * * *} * *} // ****************************************************************** // ** Tellen tot'n spatie komt (voor de eerste regel van'n wereld) ** // ****************************************************************** public static int Counting(String regel, int Checker) { int counter = regel.length()-1; int StartCount = Checker; for (int c=StartCount; c<=counter; c++) { *char Temp = regel.charAt(c); * if (Temp == ' ') { * * *break; * } * else { * * *Checker ++; * } } return Checker; } } |
||
|
|
10-12-2004, 01:08 PM | #25 | ||
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
|
Can you explain what are you trying to accoplish with each code?
|
||
|
|
10-12-2004, 01:34 PM | #26 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
Code:
import bvp.*; import java.io.*; public class VoorbeeldPijltjes { * *public static void main(String[] args) { Code:
String bestandsnaam; bestandsnaam = "Voorbeeld.txt"; BestandsInvoer bi = new BestandsInvoer (bestandsnaam); String regel = bi.leesRegel(); Code:
// ******************************** // ** De begin-coordinaten lezen ** // ******************************** int Checker = 0; Checker = Counting(regel, Checker)+1; int Temp = Counting(regel, Checker); String tempX = regel.substring(4,Temp); int dimX = Integer.parseInt(tempX); Checker = Counting(regel, Checker)+1; int TempStart = Temp + 1; Temp = Counting(regel, Checker); String tempY = regel.substring(TempStart); int dimY = Integer.parseInt(tempY); Code:
// ****************************************************************** // ** Tellen tot'n spatie komt (voor de eerste regel van'n wereld) ** // ****************************************************************** public static int Counting(String regel, int Checker) { int counter = regel.length()-1; int StartCount = Checker; for (int c=StartCount; c<=counter; c++) { *char Temp = regel.charAt(c); * if (Temp == ' ') { * * *break; * } * else { * * *Checker ++; * } } return Checker; } Code:
// ************************* // ** Nieuw bord plaatsen ** // ************************* Bus bus=new Bus(); Figuren verz = new Figuren("dozo2.fig"); int e=verz.getEenheid("grid"); Bord bord=new Bord("Dozo World", dimX*e, dimY*e, bus); int plaatsX; int plaatsY = 0; int x = 0; int y = 0; int[] spelbord; spelbord = new int[dimX*dimY]; Code:
// *************************** // ** Plaatsen van de items ** // *************************** for (plaatsY = 0; plaatsY < dimY; plaatsY++) { regel = bi.leesRegel(); for (plaatsX = 0; plaatsX < dimX; plaatsX++) { *switch(regel.charAt(plaatsX)) { * case '.': spelbord[(plaatsY*dimX) + plaatsX] = 0; * * * bord.plaatsFiguur("vloer", verz, plaatsX*e, plaatsY*e); * * * break; * case 'B': spelbord[(plaatsY*dimX) + plaatsX] = 1; * * * bord.plaatsFiguur("doos1", verz, plaatsX*e, plaatsY*e); * * * break; * case 'R': spelbord[(plaatsY*dimX) + plaatsX] = 2; * * * bord.plaatsFiguur("doos2", verz, plaatsX*e, plaatsY*e); * * * break; * case '#': spelbord[(plaatsY*dimX) + plaatsX] = 3; * * * bord.plaatsFiguur("muur", verz, plaatsX*e, plaatsY*e); * * * break; * case '@': spelbord[(plaatsY*dimX) + plaatsX] = 4; * * * bord.plaatsFiguur("mannetje", verz, plaatsX*e, plaatsY*e); * * * x=plaatsX; *y=plaatsY; * * * break; *} } } * * * *bord.toonVeranderingen();
You might notice some confusing thing in the array index... this formula: (y*dimX)+x. It's because before, when I just used x*y for the array index, x = 2, y = 5 had the same index as x = 5, y = 2, x = 1, y = 10 and x = 10, y = 1, as example. Too buggy. This formula's kinda the same as Row*maxColumns + Column from the Connect Four assignment (with difference that this matrix's point 0 is at the top left, not the bottom left) Code:
// ********************* // ** Bewegen + duwen ** // ********************* * * * *while (true) { * * * * * *Boodschap boodschap=bus.getBoodschap(); * * * * * *if (boodschap.getType().equals("toetsenbord")) { * * * * * * * *String data=boodschap.getData(); * * * * * * * *if (data.startsWith("!-")) { * *int oldx=x; int oldy=y; * *int object; * *int d; // ** Naar links * *if (data.equals("!-Left") && x>1) { *d=x; *d--; *if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * x--; *} *if (spelbord[(y*dimX)+d] == 1 || spelbord[(y*dimX)+d] == 2) { * object = spelbord[(y*dimX)+d]; * System.out.println("Object = "+ object); * do { * *d--; * } while (spelbord[(y*dimX)+d] == object); * *if (spelbord[(y*dimX)+d] == 0) { * * spelbord[(y*dimX)+d] = object; * * bord.plaatsFiguur("doos"+ object, verz, d*e, y*e); * * bord.plaatsFiguur("vloer", verz, x*e, y*e); * * spelbord[(y*dimX)+x] = 0; * * x--; * * bord.plaatsFiguur("mannetje", verz, x*e, y*e); * * spelbord[(y*dimX)+x] = 4; * } * *} * * *} // ** Naar rechts * *if (data.equals("!-Right") && x<(dimX-1)) { *d=x; *d++; *if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * x++; *} *if (spelbord[(y*dimX)+d] == 1 || spelbord[(y*dimX)+d] == 2) { * object = spelbord[(y*dimX)+d]; * System.out.println("Object = "+ object); * do { * *d++; * } while (spelbord[(y*dimX)+d] == object); * if (spelbord[(y*dimX)+d] == 0) { * *spelbord[(y*dimX)+d] = object; * *bord.plaatsFiguur("doos"+ object, verz, d*e, y*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *x++; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } *} * * *} * * * * // ** Naar boven * *if (data.equals("!-Up") && y>1) { *d=y; *d--; *if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * y--; *} *if (spelbord[(d*dimX)+x] == 1 || spelbord[(d*dimX)+x] == 2) { * object = spelbord[(d*dimX)+x]; * System.out.println("Object = "+ object); * do { * *d--; * } while (spelbord[(d*dimX)+x] == object); * if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(d*dimX)+x] = object; * *bord.plaatsFiguur("doos"+ object, verz, x*e, d*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *y--; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } * *} * * *} // ** Naar beneden * *if (data.equals("!-Down") && y<(dimY-1)) { *d=y; *d++; *if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(y*dimX)+x] = 0; * * * * * * y++; *} *if (spelbord[(d*dimX)+x] == 1 || spelbord[(d*dimX)+x] == 2) { * object = spelbord[(d*dimX)+x]; * System.out.println("Object = "+ object); * do { * *d++; * } while (spelbord[(d*dimX)+x] == object); * if (spelbord[(d*dimX)+x] == 0) { * *spelbord[(d*dimX)+x] = object; * *bord.plaatsFiguur("doos"+ object, verz, x*e, d*e); * *bord.plaatsFiguur("vloer", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 0; * *y++; * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *spelbord[(y*dimX)+x] = 4; * } * *} * * *} * * * *bord.plaatsFiguur("vloer", verz, oldx*e, oldy*e); * *bord.plaatsFiguur("mannetje", verz, x*e, y*e); * *bord.toonVeranderingen(); Code:
// ********************************************* // ** Checken voor dozen die mogen verdwijnen ** *-> Nog aan aan't werken // ********************************************* int g; int h; int doos; int teller = 0; int[] groep; groep = new int[dimX*dimY]; for (doos = 1; doos <=2; doos++) { *for (g=0; g < dimX; g++) { * for (h=0; h < dimY; h++) { * *if (spelbord[(h*dimX)+g] == doos) { * * teller ++; * * groep[teller] = (h*dimX)+g; * *} * *else { * * teller = 0; * *} * *if (teller == 4 && doos == 1) { * * System.out.println("Voldoende dozen 1"); * *} * *if (teller == 3 && doos == 2) { * * System.out.println("Voldoende dozen 2"); * *} * * * } * *} } |
||
|
|
10-12-2004, 01:46 PM | #27 | ||
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
|
The move part has to be done in different way.
You have to have a lot of if statements. You start to move (no mather of direction) 1 - if is floor, move 2. if is not floor - check if is the wall 3. if is wall, don't move 4. if is box, check next space now same procedure (same stuff) with next box 1. if is floor, move 2. if is not floor, check if is the wall 3. if is wall, don't move 4. if is box, check the color 5. if is same color go to next box 6 if is different color color, don't move You can move only in 4 directions, this make it easy! |
||
|
|
10-12-2004, 01:48 PM | #28 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
Uhhhmmm... the moving works smoothly... everything's just fine, except for the winning condition.
|
||
|
|
10-12-2004, 01:49 PM | #29 | ||
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
|
how big is the world?
|
||
|
|
10-12-2004, 02:00 PM | #30 | ||
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
|
It's dimX, dimY big. It should be able to read any world-file. A world-file looks like this:
DIM 10 6 -> Defines the dimensions, in this case x = 10, y = 6 ...######. -> . = floor ..#.....#. -> # = wall .#@.B.R..# -> @ = player #BB..R..R# -> B = Box 1 (or box 2, I don't remember off the top of my head) #R.....B.# -> R = Other type of box ########## Of course, the comments to the right aren't included. It should be able to read worlds of 2x3 dimensions as well as worlds of 1234567890x1234567890 dimensions (which it can... tested that If it's 12345678901, it gives an error) Edit: just tested that world. It's impossible to win. That's what you get for throwing those characters around randomly |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
I need a Java tutorial... | Fubb | Programming | 12 | 13-04-2009 10:26 AM |
Java Software And Winxp Problems | Abi79 | Tech Corner | 13 | 17-08-2006 07:09 PM |
Java/html - Two Questions ... | swiss | Programming | 12 | 12-02-2006 10:57 AM |
How To Use Java Vm In Windows Xp? | The Fifth Horseman | Tech Corner | 19 | 27-07-2005 10:29 PM |
Java Game | Reaperman | Programming | 3 | 23-02-2005 02:27 PM |
|
|
||
  |