aboutsummaryrefslogtreecommitdiff
path: root/Занимательное программирование/4/3_recursive/src/main/java/net/caraus/labyrinth/Main.java
blob: 2ef6adc200306bd0ce0cbb11661959cf110eb3ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package net.caraus.labyrinth;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.Color;
import static com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.utils.ScreenUtils;

import java.io.BufferedReader;
import java.io.IOException;

/** {@link com.badlogic.gdx.ApplicationListener} implementation shared by all platforms. */
public class Main extends ApplicationAdapter {
    private ShapeRenderer shape;
    private Maze maze;
    private RecursiveSolve solver;

    @Override
    public void create() {
        shape = new ShapeRenderer();

        FileHandle file = Gdx.files.internal("sample.txt");

        try {
            this.maze = new Maze(file.reader("utf-8"));
        } catch (IOException e) {
        }
        this.solver = new RecursiveSolve(this.maze, new Point(0, 0), new Point(this.maze.width() - 1, 0));
        this.solver.start();
    }

    @Override
    public void render() {
        ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f);

        this.shape.begin(ShapeType.Line);

        this.shape.setColor(Color.RED);
        this.maze.draw(this.shape);

        this.shape.setColor(Color.GREEN);
        this.solver.draw(this.shape);

        /* this.elapsedTime += Gdx.graphics.getDeltaTime();
        if (this.elapsedTime > 1.0f) {
            if (this.solver.solve() != Solution.CONTINUE) {
                this.elapsedTime = Float.NEGATIVE_INFINITY;
            } else {
                this.elapsedTime -= 1.0f;
            }
        } */

        this.shape.end();
    }

    @Override
    public void dispose() {
        this.shape.dispose();
    }
}