java - can't properly dynamically load and set up game state -


all right, complicated question, let's try start so, i'm sure many of have played game, show buttons identification of save file, , when press it, retrieve save state file , start playing want implement similar simple rpg(think simplified fire emblem, if you're played it). set jpanel buttons actioncommand "load , play save file", , code try use in actionlistener execute functionality rpggame jpanel relevant characters, cursor, etc, , setgame method helps set (using button text try retrieve particular file) using +".dat" try serialized state

else if (e.getactioncommand().equals("load , play saved file")) {     jbutton source = (jbutton)(e.getsource());     try {         newgame = loadchapterstate(source.gettext() + ".dat");         newgame.setupgame();         //newgame.setcursor(newgame.cursor);         cardlayout layout = (cardlayout)(overallgame.getlayout());         layout.show(overallgame, game);         //requestfocusinwindow         newgame.requestfocus /*inwindow*/ (true);          dummyframe.repaint();     } catch (ioexception ex) {         joptionpane.showmessagedialog(dummyframe, "darn it!", "error in retrieval", joptionpane.error_message);         //ex.printstacktrace();     }​ 

this code loadchapterstate(game-state loading) method

​       public static rpggame loadchapterstate(string file) throws ioexception {         objectinputstream ois = null;         rpggame gamedata = null;         try {             ois = new objectinputstream(new fileinputstream(file));             gamedata = (rpggame) ois.readobject();             gamedata.setcursor(gamedata.cursor);         } catch (ioexception ex) {             system.out.println("sorry, there error reaching file");             system.out.println("you not able play state");             //ex.printstacktrace();         } {             ois.close();             return gamedata;         }     } 

what confuses me when run this, image of game map perfectly, can't move cursor input keylistener, despite resetting in loading method above setcursor method(i had trouble earlier when getting old copy of game map).

now, have save state loaded later in main method here this.

system.out.println("would create file?");  try {      newgame = loadchapterstate("stuff.dat");      newgame.setupgame();  } catch (ioexception e) {      e.printstacktrace();  }   //finally constructs master panel can flip between main menu , running game  overallgame = new jpanel(new cardlayout());  overallgame.add(mainmenupanel, main_menu);  overallgame.add(newgame, game);  overallgame.add(creditpanel, credits);  overallgame.add(chapterstartmenupanel, chapterstart);  overallgame.add(showsavefilespanel, save_files);​ 

(this 1 can work cursor perfectly, combination of part of actionlistener , next bit after assigning listener jbutton "start" actioncommmand)

if (e.getactioncommand().equals("start")) {     //dummyframe.add(newgame);     //mainmenupanel=null;     cardlayout layout = (cardlayout)(overallgame.getlayout()); //retrieves overall layout     layout.show(overallgame, game); //uses switch main game panel     newgame.requestfocus(true); //need redirect focus game rather original main menu     dummyframe.repaint(); }​ 

if requested, i'll show rpggame class. guess want is, how can cursor working "load , play save fie" command? help!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -