Hi
I am making a sokoban game following the tutorial by ChicoTutoProg on youtube.
He says that he forgot to add the function ChargerLevel() in the constructor. the problem is that I added the method chargerlevel() but but my program is not running as it should be. can someone please guide me to what may be the problem.
I've attached the file that I am working on.
Capture3.JPGCapture1.JPG
ps: in capture1, the game should look like that.
capture 2 is my code, where I added the method chargerlevel();
capture 3 is what my game looks like
package marioSokobanGame; 02 03 import java.awt.Color; 04 import java.awt.Font; 05 import java.awt.Frame; 06 import java.awt.Graphics; 07 import java.awt.Graphics2D; 08 import java.awt.Rectangle; 09 import java.awt.event.KeyEvent; 10 import java.awt.event.KeyListener; 11 import java.io.FileReader; 12 import java.util.ArrayList; 13 14 import javax.swing.JPanel; 15 16 import marioSokoban.MenuFrame; 17 18 public class GameBoard extends JPanel implements KeyListener{ 19 20 String Game[][] = new String[12][12]; 21 int Level = 1; 22 private static ArrayList<Mur> Murs; 23 private static ArrayList<Objectif> Objectifs; 24 private static ArrayList<Caisse> Caisses; 25 Mur mur; 26 Mario mario; 27 Objectif objectif; 28 Caisse caisse; 29 Font levelFont = new Font("SansSherif", Font.BOLD, 30); 30 FileReader fr; 31 Frame Gframe; 32 33 34 public void ChargerLevel(){ 35 try{ 36 fr = new FileReader("Maps/level" + Level + ".level"); 37 int x = 0, y = 0, i =0; 38 39 Murs = new ArrayList<Mur>(); 40 Caisses = new ArrayList<Caisse>(); 41 Objectifs = new ArrayList<Objectif>(); 42 43 while ((i = fr.read()) != -1){ 44 char strImg = (char) i; 45 46 if (strImg == '0'){ 47 Game[x][y] = "MUR"; 48 mur = new Mur(x*34,y*34); 49 Murs.add(mur); 50 51 } 52 else if (strImg == '1'){ 53 Game[x][y] = "MARIO"; 54 mario = new Mario(x*34,y*34); 55 } 56 else if (strImg == '2'){ 57 Game[x][y] = "CAISSE"; 58 caisse = new Caisse(x*34,y*34); 59 Caisses.add(caisse); 60 } 61 else if (strImg == '3'){ 62 Game[x][y] = "OBJECTIF"; 63 objectif = new Objectif(x*34,y*34); 64 Objectifs.add(objectif); 65 } 66 else if (strImg == ' '){ 67 Game[x][y] = null; 68 } 69 70 else if (strImg == '\r'|| strImg == '\n'){ 71 x--; 72 } 73 if(x==11){ 74 y++; 75 x =0; 76 } 77 else{ 78 x++; 79 } 80 81 } 82 } 83 84 catch (Exception ex){} 85 repaint(); 86 87 }