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;
}
}
|