ERLEDIGT
NEIN
NEIN
ANTWORTEN
12
12
ZUGRIFFE
1018
1018
EMPFEHLEN
-
hallo zusammen
bin immer noch mit meinen labyrinth beschäftigt funktioniert bis jetzt einwandfrei nur muss ich jetzt noch die mauern aktivieren...
das labyrinth wird in ein 2d array geladen und mit ascii zeichen gefüllt die spielfigur und das ziel sind auch ascii zeichen die spielfigur darf nicht durch die ascii mauern laufen weiß aber nicht wie ich das machen soll
ich poste euch mal den kompletten quelltext vielleicht weiß ja einer von euch eine lösung würde mich freuen
Main
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package Schule; public class Main { /** * @param args */ public static void main(String[] args) { Labyrinth lab= new Labyrinth(); lab.generiere(); lab.setzespielfigur(); lab.setzeziel(); lab.zeichneFeld(); lab.bewegespielfigur(); } }
Labyrinth Klasse
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
package Schule; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Random; public class Labyrinth{ private static Random zufallszahl = new Random(); private static int ergebnis; private static int[] [] array = new int[10][40]; private static int x; private static int y; private static int beenden = 0; private static String input; private static int k; private static int j; private static int u; private static int i; private static int kory; private static int korx; private static int a; private static int s; //Generiere Spielfeld--------------------------------------- public void zeichneFeld(){ for(k=0; k<10; k++){ for(j=0; j<40; j++){ System.out.print((char)array[k][j]); } System.out.println(); } } //Generiere Labyrinth--------------------------------------- public void generiere(){ System.out.println("Spielfeld"); for( i=0; i<10; i++){ for( u=0; u<40; u++){ ergebnis=Math.abs(zufallszahl.nextInt() % 4)+ 1; if(ergebnis==1) array[i][u]= 35; if(ergebnis==2||ergebnis==3||ergebnis==4) array[i][u]= 160; for(kory = 0; kory<=39;kory++){ array[0][kory]=35; array[9][kory]=35; } for(korx = 0; korx<=9;korx++){ array[korx][0]=35; array[korx][39]=35; } } } } //Generiere Spielfigur------------------------------------------------------ public void setzespielfigur(){ x=Math.abs(zufallszahl.nextInt()%10)+1; y=Math.abs(zufallszahl.nextInt()%10)+1; array[x][y]=169; } //Generiere Ziel------------------------------------------------------------ public void setzeziel(){ array[8][26]=90; } //Generiere Steuerung------------------------------------------------------- public void bewegespielfigur() { InputStreamReader isr = new InputStreamReader ( System.in ); BufferedReader stdin = new BufferedReader ( isr ); while(beenden==0){ try { input = stdin.readLine(); } catch (IOException e) { e.printStackTrace(); } //Taste zum nach oben laufen----------------------------------------- if(input.equals("w")){ array[x][y]=32; x=x-1; array[x][y]=169; if(array[x][y]== (char)35){ x=x+1; } for(int i=0; i<=8; i++){ System.out.println(); } for(k=0; k<10; k++){ for(j=0; j<40; j++){ System.out.print((char)array[k][j]); } System.out.println(); } System.out.println("X"+x+"Y"+y); if(x==8&&y==26){ System.out.println("Sie haben Gewonnen!\n Drücken Sie e zum Beenden! "); System.out.println("X"+x+"Y"+y); } for(kory = 0; kory<=26;kory++){ if(x==0&&y==kory){ array[x][y]=160; x=x+1; } } array[x][y]=169; } //Taste zum links laufen-------------------------------------------- else if(input.equals("a")){ array[x][y]=160; y=y-1; array[x][y]=169; for(int i=0; i<=8; i++){ System.out.println(); } for(k=0; k<10; k++){ for(j=0; j<40; j++){ System.out.print((char)array[k][j]); } System.out.println(); } System.out.println("X"+x+"Y"+y); if(x==8&&y==26){ System.out.println("Sie haben Gewonnen!\n Drücken Sie e zum Beenden! "); System.out.println("X"+x+"Y"+y); } for(int korx = 0; korx<=10;korx++){ if(x==korx&&y==0){ array[x][y]=160; y=y+1; } } } //Taste zum runter laufen----------------------------------------------------------- else if(input.equals("s")){ array[x][y]=160; x=x+1; array[x][y]=169; for(int i=0; i<=8; i++){ System.out.println(); } for(k=0; k<10; k++){ for(j=0; j<40; j++){ System.out.print((char)array[k][j]); } System.out.println(); } System.out.println("X"+x+"Y"+y); if(x==8&&y==26){ System.out.println("Sie haben Gewonnen!\n Drücken Sie e zum Beenden! "); System.out.println("X"+x+"Y"+y); } for(kory = 0; kory<=26;kory++){ if(x==9&&y==kory){ array[x][y]=160; x=x-1; } } } //Taste zum rechts laufen--------------------------------------------------------- else if(input.equals("d")){ array[x][y]=160; y=y+1; array[x][y]=169; for(int i=0; i<=8; i++){ System.out.println(); } for(k=0; k<10; k++){ for(j=0; j<40; j++){ System.out.print((char)array[k][j]); } System.out.println(); } System.out.println("X"+x+"Y"+y); if(x==8&&y==26){ System.out.println("Sie haben Gewonnen!\n Drücken Sie e zum Beenden! "); } for(int korx = 0; korx<=10;korx++){ if(x==korx&&y==39){ array[x][y]=160; y=y-1; } } } //Taste für Ende------------------------------------------------------------------------ else if(input.equals("e")){ System.out.println("ende"); beenden = beenden + 1; } } } }
freue mich über eure antworten
mfg tameck
-
04.12.07 09:59 #2
Wo ist jetzt die Frage? Wenn es darum geht dass man nicht durch Mauern kann, dann ist das ganz einfach:
Wenn deine Figur z.b. auf Feld 5 (mal nur X Achse) steht und du drückst links, dann will deine Figur ja auf Feld 4. Also frägst du vorher ab, ob da (Feld 4) eine Mauer ist. Wenn ja, dann soll die Figur ihre Position behalten."... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
-
genau das ist mir klar nur bekomme ich diese abfrage einfach nicht hin wenn du in meinen anderen beitrag schaust char wert in 2d array siehst du wie ich es schon versucht habe
gruß tameck
-
04.12.07 10:07 #4
Gut, sagen wir mal eine Mauer ist bei dir "#" eine Raute:
Code :1 2 3 4 5 6 7 8
switch(Richtung){ case links: { if(array[<jetzige X Position> - 1][jetzige Y Position] == "#"){ System.out.println("Hier ist eine Mauer"); }else{ <Hier deine Bewegung hin> } }
Ist jetzt mal ein Pseudocode."... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
-
hey danke funktioniert fast
habs jetzt so gemacht
Code :1 2 3 4 5 6
if(array[x-1][y]== (char)35){ System.out.println("hier mauer"); array[x][y]=160; x=x+1; array[x][y]=169; }
nur erkennt er manchmal en leerzeichen als mauer
-
Warum machst du was wenn dort an der Stelle ine Mauer ist?!
-
04.12.07 10:46 #7
@mimij85
Hab ich ihm vorgeschlagen, damit er besser sieht ob es funktioniert.
@tameck
Versuchs mal mit 'equals("#")'. Warum machst du eigentlich?Code :1
(char)35
"... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
-
ich zeichne die spielfigur eine koordinate zurück
x=x+1;
weil sonst läuft die da doch immernoch druch
-
Also wenn du die die Forwaertstaste drueckst, und dort ist ne Mauer, laesst du sie zuruecklaufen?
Die muss doch dann einfach gar nichts machen?
@Matze
Du hast ihm aber in das "else" geschrieben "hier die Bewegung hin" und net in das "if"
-
04.12.07 10:51 #10
Der Teil ist wircklich sinnlos. Du solltest erst Prüfen und dann eventuell gehen.
"... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
-
und wie sage ich ihr das wenn da ne mauer kommt das die spielfigur in diese richtung nicht weiterlaufen kann ?
-
04.12.07 10:54 #12
@mimij
Ob mans jetzt so macht oder umgedreht ist doch erstmal egal."... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
-
04.12.07 10:55 #13
Das erzähl ich dir doch die ganze Zeit. Prüfe ob da ne Mauer ist. Wenn ja, dann führe keine Bewegung aus und wenn da keine ist, dann führe die Bewegung aus
"... Jeder von uns ist Kunst... gezeichnet vom Leben" (Casper)
"Sir?, we're sorrounded!"
"Excellent, we can attack in any direction"
Ähnliche Themen
-
Labyrinth-Problem
Von iAZ im Forum Algorithmen & Datenstrukturen mit JavaAntworten: 14Letzter Beitrag: 25.04.10, 20:57 -
labyrinth
Von tameck im Forum JavaAntworten: 7Letzter Beitrag: 21.11.07, 14:19 -
Automatisch Labyrinth erstellen
Von pb_sergio im Forum Coders TalkAntworten: 1Letzter Beitrag: 05.06.07, 20:58 -
Labyrinth - Komplett abfahren
Von Discman im Forum JavaAntworten: 7Letzter Beitrag: 17.10.05, 18:34 -
bester Weg aus einem Labyrinth!
Von dapor im Forum JavaAntworten: 1Letzter Beitrag: 25.02.05, 15:32





Zitieren
Login





