aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
blob: 9285306d555147394feb9ce564b1e94374a2b2c9 (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
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)
    {
        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;
    }
}