aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
blob: c92c96b37124c7c0f5537b6551bb99cb3d55b491 (plain) (blame)
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
package com.camilstaps.rushhour;

import android.graphics.Color;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

/**
 * Created by Jos on 23-4-2015.
 */
public class BoardLoader {
    public BoardLoader()
    {}

    public Board loadBoard(InputStream file)
    {
        /*
        Level formaat:
        1 regel: Aantal auto's

        voor iedere auto:
        x1 y1 x2 y2 op een regel.
        r g b op een regel.
         */
        Scanner scan = new Scanner(file);

        Board board = new Board();

        int numCars = scan.nextInt();
        scan.nextLine();

        for(int carN = 0; carN < numCars; carN++)
        {
            int x1 = scan.nextInt();
            int y1 = scan.nextInt();
            int x2 = scan.nextInt();
            int y2 = scan.nextInt();
            scan.nextLine();

            int r = scan.nextInt();
            int g = scan.nextInt();
            int b = scan.nextInt();

            Car c = new Car(new Coordinate(x1, y1), new Coordinate(x2, y2), Color.rgb(r, g, b));
            board.add(c);

            if(scan.hasNext()) scan.nextLine();
        }

        return board;
    }
}