Skip to content
Snippets Groups Projects
Commit 8a8bfe90 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Added code to support logging.

parent b63aed0c
Branches
No related tags found
No related merge requests found
...@@ -10,10 +10,26 @@ import javax.swing.JFrame; ...@@ -10,10 +10,26 @@ import javax.swing.JFrame;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class Tetris extends JFrame { public class Tetris extends JFrame {
private static final long serialVersionUID = -6851893161385783635L; private static final long serialVersionUID = -6851893161385783635L;
protected static void log(String message) {
try {
Files.write(Paths.get("logs/tetris.log"), (message + "\n").getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
} catch (IOException exception) {
exception.printStackTrace();
}
}
protected static void log(String moveName, int shape) {
log("Attempted move failed: " + moveName + " on shape " + shape + " (\"" + SHAPE_NAMES[shape] + "\")");
}
protected static int mod(int value, int modulus) { protected static int mod(int value, int modulus) {
int result = value % modulus; int result = value % modulus;
return result < 0 ? result + modulus : result; return result < 0 ? result + modulus : result;
...@@ -44,6 +60,7 @@ public class Tetris extends JFrame { ...@@ -44,6 +60,7 @@ public class Tetris extends JFrame {
protected static final Color[] COLORS = { new Color(0, 0, 204), new Color(142, 0, 204), new Color(204, 204, 0), protected static final Color[] COLORS = { new Color(0, 0, 204), new Color(142, 0, 204), new Color(204, 204, 0),
new Color(204, 0, 204), new Color(0, 204, 204), new Color(0, 204, 0), new Color(204, 0, 0), }; new Color(204, 0, 204), new Color(0, 204, 204), new Color(0, 204, 0), new Color(204, 0, 0), };
protected static final String[] SHAPE_NAMES = { "O", "L", "J", "S", "Z", "T", "I", };
protected static final int[] SHAPE_WIDTHS = { 2, 3, 3, 3, 3, 3, 4, }; protected static final int[] SHAPE_WIDTHS = { 2, 3, 3, 3, 3, 3, 4, };
protected static final int[][][][] SHAPES = { protected static final int[][][][] SHAPES = {
{ // O { // O
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment