From 8a8bfe908e3056e87af0a627daa1ff1c67b194c5 Mon Sep 17 00:00:00 2001 From: Brady James Garvin <bgarvin@cse.unl.edu> Date: Wed, 12 Oct 2016 11:11:42 -0500 Subject: [PATCH] Added code to support logging. --- tetris/logs/tetris.log | 0 .../java/edu/unl/cse/soft160/tetris/Tetris.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tetris/logs/tetris.log diff --git a/tetris/logs/tetris.log b/tetris/logs/tetris.log new file mode 100644 index 0000000..e69de29 diff --git a/tetris/src/main/java/edu/unl/cse/soft160/tetris/Tetris.java b/tetris/src/main/java/edu/unl/cse/soft160/tetris/Tetris.java index ead888f..1da45a5 100644 --- a/tetris/src/main/java/edu/unl/cse/soft160/tetris/Tetris.java +++ b/tetris/src/main/java/edu/unl/cse/soft160/tetris/Tetris.java @@ -10,10 +10,26 @@ import javax.swing.JFrame; import java.awt.event.KeyEvent; 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 { 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) { int result = value % modulus; return result < 0 ? result + modulus : result; @@ -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), 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[][][][] SHAPES = { { // O -- GitLab