Created
November 11, 2015 04:00
-
-
Save rbrick/c653a5bf1e3f4cfe14a7 to your computer and use it in GitHub Desktop.
Something that does something that i think looks cool
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
public class Hello { | |
public static void main(String[] args) { | |
Grid grid = new Grid(9); | |
int fixedGridSize = grid.getSize() - 1; | |
for (int i = 0; i < grid.getSize(); i++) { | |
grid.set(i, i, 1); | |
grid.set(i, fixedGridSize - i, 1); | |
grid.set(4, i, 1); | |
grid.set(i, 4, 1); | |
} | |
grid.printGrid(); | |
} | |
public static class Grid { | |
private int size; | |
private int[][] grid; | |
public Grid(int size) { | |
this.grid = new int[size][size]; | |
this.size = size; | |
populate(); | |
} | |
private void populate() { | |
for (int y = 0; y < grid.length; y++) { | |
for(int x = 0; x < grid.length; x++) { | |
grid[y][x] = -1; | |
} | |
} | |
} | |
public boolean isSet(int x, int y) { | |
return grid[y][x] != -1; | |
} | |
public void set(int x, int y, int value) { | |
grid[y][x] = value; | |
} | |
public void printGrid() { | |
for (int y = 0; y < grid.length; y++) { | |
String line = ""; | |
int[] atY = grid[y]; | |
for (int x : atY) { | |
if (x != -1) { | |
line += "*"; | |
} else { | |
line += " "; | |
} | |
} | |
System.out.println(line); | |
} | |
} | |
public int getSize() { | |
return this.size; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment