forked from hhaslam11/Text-Fighter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hhaslam11#123 from SaurabhKukreja/sk-refactor-TF
Refactor Print commands
- Loading branch information
Showing
6 changed files
with
149 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hotmail.kalebmarc.textfighter.main; | ||
|
||
public class Constants { | ||
|
||
public static final String WELCOME_HEADER = "WELCOME TO TEXT FIGHTER"; | ||
public static final String HEADER = "TEXT FIGHTER"; | ||
public static final String SUB_HEADER = "A Text-Based Fighting Game"; | ||
public static final String STAR_DIVIDER = "********************************************"; | ||
public static final String DASH_DIVIDER = "__________________________________________"; | ||
public static final String EMPTY_SPACE_BOX = ""; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.hotmail.kalebmarc.textfighter.main; | ||
|
||
import java.util.List; | ||
|
||
public class GameUtils { | ||
|
||
/* | ||
* This is a Utility Class for modifying String | ||
*/ | ||
public static void print(String input) { | ||
System.out.print(input); | ||
} | ||
|
||
public static void println(String input) { | ||
print(input + "\n"); | ||
} | ||
|
||
public static void showPopup(String header, String subheader, List<String> message, List<String> inputs) { | ||
Ui.cls(); | ||
println(center(Constants.DASH_DIVIDER)); | ||
if(!header.isEmpty()) { | ||
println(center(header)); | ||
} | ||
|
||
if(!subheader.isEmpty()) { | ||
println(center(subheader)); | ||
println(center(Constants.STAR_DIVIDER)); | ||
} | ||
println(center(Constants.EMPTY_SPACE_BOX)); | ||
|
||
for (int i = 0; i < message.size(); i++) { | ||
println(center(message.get(i))); | ||
} | ||
|
||
println(center(Constants.EMPTY_SPACE_BOX)); | ||
|
||
for (int i = 0; i < inputs.size(); i++) { | ||
int input_num = i + 1; // This addition is because our switch case starts from Case 1 and not Case 0 | ||
String input = input_num + "- " + inputs.get(i); | ||
println(leftAlign(input)); | ||
} | ||
|
||
println(center(Constants.DASH_DIVIDER)); | ||
} | ||
|
||
public static String center(String s) { | ||
return center(s, 45, ' '); | ||
} | ||
public static String leftAlign(String s) { | ||
return leftAlign(s, 45, ' '); | ||
} | ||
|
||
public static String center(String input, int size, char pad) { | ||
if (input == null || size <= input.length()) | ||
return input; | ||
|
||
StringBuilder output = new StringBuilder(size); | ||
output.append("|"); | ||
output.append(String.valueOf(pad).repeat((size - input.length()) / 2)); | ||
output.append(input); | ||
|
||
while (output.length() < size) { | ||
output.append(pad); | ||
} | ||
output.append("|"); | ||
return output.toString(); | ||
} | ||
|
||
public static String leftAlign(String input, int size, char pad) { | ||
if (input == null || size <= input.length()) | ||
return input; | ||
|
||
StringBuilder output = new StringBuilder(size); | ||
output.append("|"); | ||
output.append(String.valueOf(pad).repeat(10)); | ||
output.append(input); | ||
|
||
while (output.length() < size) { | ||
output.append(pad); | ||
} | ||
output.append("|"); | ||
return output.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,38 @@ | ||
package com.hotmail.kalebmarc.textfighter.main; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
class Menu { | ||
|
||
private Menu(){} | ||
public static void load(){ | ||
while(true){ | ||
|
||
Ui.cls(); | ||
//Menu Screen | ||
Ui.println("_____________________________________________"); | ||
Ui.println("| WELCOME TO TEXT FIGHTER |"); | ||
Ui.println("| A Text-Based Fighting Game |"); | ||
Ui.println("|*******************************************|"); | ||
Ui.println("| |"); | ||
Ui.println("| To get started, Type in a number below |"); | ||
Ui.println("| and press enter. |"); | ||
Ui.println("| |"); | ||
Ui.println("| 1) Start Game |"); | ||
Ui.println("| 2) About Game |"); | ||
Ui.println("| 3) Exit |"); | ||
Ui.println("| www.TextFighter.tk |"); | ||
Ui.println("|___________________________________________|"); | ||
|
||
switch (Ui.getValidInt()) { | ||
case 1: | ||
Ui.cls(); | ||
Ui.guiEnabled = false; | ||
Game.start(); | ||
public void load() { | ||
while (true) { | ||
|
||
//Menu Screen | ||
GameUtils.showPopup(Constants.WELCOME_HEADER, | ||
Constants.SUB_HEADER, | ||
asList("To get started, Type in a number below", "and press enter."), | ||
asList("Start Game", "About Game") | ||
); | ||
|
||
switch (Ui.getValidInt()) { | ||
case 1: | ||
Ui.guiEnabled = false; | ||
new Game().start(); | ||
|
||
//Saves the game before exiting | ||
// docschorsch: save() only if player is not program default player amd game had started | ||
if(User.getPlayerDefault()>0 && Game.hadGameStarted()) { | ||
Saves.save(); | ||
} | ||
break; | ||
case 2: | ||
About.view(false); | ||
break; | ||
case 3: | ||
return; | ||
default: | ||
break; | ||
} | ||
}//Loop | ||
}//Method | ||
//Saves the game before exiting | ||
// docschorsch: save() only if player is not program default player amd game had started | ||
if (User.getPlayerDefault() > 0 && Game.hadGameStarted()) { | ||
Saves.save(); | ||
} | ||
break; | ||
case 2: | ||
About.view(false); | ||
break; | ||
case 3: | ||
return; | ||
default: | ||
break; | ||
} | ||
}//Loop | ||
}//Method | ||
}//Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters