import java.util.Scanner; import java.util.Set; import java.util.HashSet; public class Main { public static void main(String[] args) throws Exception { Set ps = new HashSet<>(); ps.add(new Point(0, 1)); ps.add(new Point(1, 0)); ps.add(new Point(1, -1)); ps.add(new Point(0, -1)); ps.add(new Point(-1, -1)); Environment e = new Environment(ps); GameOfLife gol = new GameOfLife(e); gol.setThreadCount(4); display(new Point(0, 0), gol.getEnv()); boolean[] stopper = new boolean[] { false }; new Thread(() -> { new Scanner(System.in).nextLine(); stopper[0] = true; }).start(); while (!stopper[0]) { gol.step(); display(new Point(0, 0), gol.getEnv()); Thread.sleep(1000); } // gol.close(); } private static final int VIEW_SIZE = 10; private static void display(Point center, Environment e) { System.out.println(); for (int i = -VIEW_SIZE; i < +VIEW_SIZE; ++i) { System.out.print("|"); for (int j = -VIEW_SIZE; j < +VIEW_SIZE; ++j) { if (e.getPoints().contains(center.translate(i, j))) { System.out.print("O"); } else { System.out.print(" "); } } System.out.println("|"); } for (int i = -VIEW_SIZE; i < +VIEW_SIZE + 2; ++i) { System.out.print("-"); } } }