Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Random;
- import java.util.Scanner;
- public class GenTest {
- static final int SIZE_X = 15; // 41 for file
- static final int SIZE_Z = 10; // 34
- static boolean[][] generated = new boolean[SIZE_Z][SIZE_X];
- static boolean[][] decoratedFlag = new boolean[SIZE_Z][SIZE_X];
- static boolean[][] decorated = new boolean[SIZE_Z * 2][SIZE_X * 2];
- static boolean[][] processed = new boolean[SIZE_Z][SIZE_X];
- public static void main(String[] args) throws InterruptedException, FileNotFoundException {
- // Scanner in = new Scanner(new FileInputStream("C:\\Users\\javaponyportable\\Documents\\Программы\\Разработка\\Eclipse\\ForgeMods\\run\\log.log"));
- // int dx = 14, dz = 0;
- Scanner in = new Scanner(System.in);
- Random random = new Random(in.nextLong());
- List<Point> points = new ArrayList<>((SIZE_X - 2) * (SIZE_Z - 2));
- for (int x = 1; x < SIZE_X - 1; ++x) {
- for (int z = 1; z < SIZE_Z - 1; ++z) {
- points.add(new Point(x, z));
- }
- }
- Collections.shuffle(points, random);
- while (!points.isEmpty()) {
- // while (in.hasNext()) {
- // int x = dx + in.nextInt();
- // int z = dz + in.nextInt();
- // minecraft(x, z);
- Point pnt = points.remove(points.size() - 1);
- minecraft(pnt.x, pnt.y);
- render();
- System.out.println("-----------------------------------");
- Thread.sleep(250);
- }
- }
- private static void minecraft(int x, int z) {
- generated[z][x] = true;
- for (int dx = -1; dx < 2; ++dx) {
- for (int dz = -1; dz < 2; ++dz) {
- tryDecorate(x + dx, z + dz);
- }
- }
- }
- private static void tryDecorate(int x, int z) {
- if (decoratedFlag[z][x]) {
- return;
- }
- for (int dx = 0; dx < 2; ++dx) {
- for (int dz = 0; dz < 2; ++dz) {
- if (!generated[z + dz][x + dx]) {
- return;
- }
- }
- }
- decoratedFlag[z][x] = true;
- mg(x, z);
- decorated[z*2+1][x*2+1] = true;
- decorated[z*2+2][x*2+1] = true;
- decorated[z*2+1][x*2+2] = true;
- decorated[z*2+2][x*2+2] = true;
- }
- private static void mg(int x, int z) {
- for (int dx = 0; dx <= 1; ++dx) {
- for (int dz = 0; dz <= 1; ++dz) {
- if (isChunkReady(x + dx, z + dz)) {
- processed[z + dz][x + dx] = true;
- }
- }
- }
- }
- private static boolean isChunkReady(int x, int z) {
- for (int dx = -1; dx <= 0; ++dx) {
- for (int dz = -1; dz <= 0; ++dz) {
- if (!generated[z + dz][x + dx] || !decoratedFlag[z + dz][x + dx]) {
- return false;
- }
- }
- }
- return true;
- }
- private static void render() {
- StringBuilder sb = new StringBuilder();
- for (int z = 0; z < SIZE_Z * 3; ++z) {
- if (z % 3 == 2) {
- sb.append('\n');
- continue;
- }
- for (int x = 0; x < SIZE_X * 3; ++x) {
- char c = '·';
- if (x % 3 == 2) {
- c = ' ';
- } else if (generated[z / 3][x / 3]) {
- if (decorated[z / 3 * 2 + z % 3][x / 3 * 2 + x % 3]) {
- if (processed[z / 3][x / 3]) {
- c = '█';
- } else {
- c = '▓';
- }
- } else {
- if (processed[z / 3][x / 3]) {
- c = '@';
- } else {
- c = '░';
- }
- }
- } else if (processed[z / 3][x / 3]) {
- c = '!';
- }
- sb.append(c).append(c);
- }
- sb.append('\n');
- }
- System.out.print(sb.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment