Skip to content

Commit

Permalink
Added a crash screen and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
aehmttw committed Jul 9, 2018
1 parent 5dcdbb1 commit 6350bbb
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 287 deletions.
1 change: 0 additions & 1 deletion src/tanks/EnemyTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public EnemyTank(double x, double y, int size, Color color, double angle, ShootA
if (Math.random() < 0.5)
this.idlePhase = RotationPhase.counterClockwise;

this.coinValue = 10;
this.angle = angle;

this.liveBulletMax = 5;
Expand Down
29 changes: 24 additions & 5 deletions src/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public class Game

public static boolean bulletLocked = false;

public enum Menu {none, paused, title, options, interlevel}
public enum Menu {none, paused, title, options, interlevel, crashed}

public static String crashMessage = "Yay! The game hasn't crashed yet!";

public static Menu menu = Menu.title;

Expand All @@ -66,6 +68,7 @@ public enum Menu {none, paused, title, options, interlevel}
public static final String directoryPath = "/.tanks.d";
public static final String logPath = directoryPath + "/logfile.txt";
public static final String registryPath = directoryPath + "/tank-registry.txt";
public static String homedir;

public static ArrayList<Registry.DefaultTankEntry> defaultTanks = new ArrayList<Registry.DefaultTankEntry>();

Expand All @@ -85,22 +88,27 @@ public static void initScript()
defaultTanks.add(new Registry.DefaultTankEntry(EnemyTankBlack.class, "black", 1.0 / 10));
defaultTanks.add(new Registry.DefaultTankEntry(EnemyTankPink.class, "pink", 1.0 / 15));

String homedir = System.getProperty("user.home");
homedir = System.getProperty("user.home");
if (!Files.exists(Paths.get(homedir + directoryPath)))
{
new File (homedir + directoryPath).mkdir();
new File(homedir + directoryPath).mkdir();
try
{
new File (homedir + logPath).createNewFile();
Game.logger = new PrintStream (new FileOutputStream (homedir + logPath, true));
new File(homedir + logPath).createNewFile();
Game.logger = new PrintStream(new FileOutputStream (homedir + logPath, true));
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}

if (!Files.exists(Paths.get(homedir + registryPath)))
{
Registry.initRegistry(homedir);
}

try
{
Game.logger = new PrintStream(new FileOutputStream (homedir + logPath, true));
Expand Down Expand Up @@ -173,6 +181,17 @@ public static void exit()
System.gc();
}

public static void exitToCrash()
{
Game.paused = true;
obstacles.clear();
belowEffects.clear();
movables.clear();
effects.clear();
System.gc();
menu = Menu.crashed;
}

public static void exitToTitle()
{
Game.tiles = new Color[28][18];
Expand Down
Loading

0 comments on commit 6350bbb

Please sign in to comment.