Skip to content

Commit f80d4d3

Browse files
committed
Fixed an issue with player names
When you press cancel in the select username window then the game would crash Slightly formated some code.
1 parent fa55aa8 commit f80d4d3

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/com/redomar/game/menu/Menu.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ private void render() {
112112
if (isGameOver()) {
113113
g.drawString("GAME OVER... What will you do now?", 35, 30);
114114
} else {
115-
String name = (Game.getJdata_UserName().length() >= 1) ? WordUtils.capitalizeFully(Game.getJdata_UserName()).toString() : "Player";
115+
String name = (Game.getJdata_UserName().length() >= 1) ? WordUtils
116+
.capitalizeFully(Game.getJdata_UserName()).toString()
117+
: "Player";
116118
g.drawString("Welcome to JavaGame " + name, 35, 30);
117119
}
118120
g.drawLine(10, (HEIGHT * 3), 10, 10);
@@ -188,41 +190,44 @@ public static void play() {
188190
splash.setProgress(92, "Aquring data: Multiplayer");
189191
Thread.sleep(125);
190192
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
191-
String multiMsg = "Sorry but multiplayer has been disabled on this version.\nIf you would like multiplayer checkout Alpha 1.6";
192-
JOptionPane.showMessageDialog(Game.getGame(), multiMsg, "Multiplayer Warning", JOptionPane.WARNING_MESSAGE);
193-
//Game.setJdata_Host(JOptionPane.showConfirmDialog(Game.getGame(), "Do you want to be the HOST?"));
193+
String multiMsg = "Sorry but multiplayer has been disabled on this version.\nIf you would like multiplayer checkout Alpha 1.6";
194+
JOptionPane.showMessageDialog(Game.getGame(), multiMsg,
195+
"Multiplayer Warning", JOptionPane.WARNING_MESSAGE);
196+
// Game.setJdata_Host(JOptionPane.showConfirmDialog(Game.getGame(),
197+
// "Do you want to be the HOST?"));
194198
Game.setJdata_Host(1);
195-
if (Game.getJdata_Host() != 1) { //Game.getJdata_Host() == 1
199+
if (Game.getJdata_Host() != 1) { // Game.getJdata_Host() == 1
196200
Game.setJdata_IP(JOptionPane.showInputDialog(Game.getGame(),
197201
"Enter the name \nleave blank for local"));
198202
}
199203
Thread.sleep(125);
200204
splash.setProgress(94, "Aquring data: Username");
205+
String s = JOptionPane.showInputDialog(Game.getGame(),
206+
"Enter a name");
207+
if (s != null) {
208+
Game.setJdata_UserName(s);
209+
}
201210
Thread.sleep(125);
202-
splash.setProgress(95, "Initalizing as Server:Host");
203-
Game.setJdata_UserName(JOptionPane.showInputDialog(Game.getGame(),
204-
"Enter a name"));
205-
Thread.sleep(250);
206211
splash.setProgress(96, "Collecting Player Data");
207-
Object[] options = { "African", "Caucasian"};
212+
Object[] options = { "African", "Caucasian" };
208213
int n = JOptionPane.showOptionDialog(frame,
209-
"Choose a race for the charater to be",
210-
"Choose a race", JOptionPane.YES_NO_OPTION,
211-
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
212-
if(n == 0){
214+
"Choose a race for the charater to be", "Choose a race",
215+
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
216+
null, options, options[0]);
217+
if (n == 0) {
213218
Game.setAternateColsR(true);
214-
}else{
219+
} else {
215220
Game.setAternateColsR(false);
216221
}
217222
Thread.sleep(250);
218-
Object[] options1 = { "Orange", "Black"};
223+
Object[] options1 = { "Orange", "Black" };
219224
int n1 = JOptionPane.showOptionDialog(frame,
220225
"Which Colour do you want the shirt to be?",
221226
"Choose a shirt Colour", JOptionPane.YES_NO_OPTION,
222227
JOptionPane.QUESTION_MESSAGE, null, options1, options1[0]);
223-
if(n1 == 0){
228+
if (n1 == 0) {
224229
Game.setAternateColsS(true);
225-
}else{
230+
} else {
226231
Game.setAternateColsS(false);
227232
}
228233
splash.setProgress(97, "Connecting as" + Game.getJdata_UserName());

0 commit comments

Comments
 (0)