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
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Rush Hour Android app
* Copyright (C) 2015 Randy Wanga, Jos Craaijo, Camil Staps
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
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;
}
}
|