|
| 1 | + |
1 | 2 | package game;
|
2 | 3 |
|
3 | 4 | import java.awt.*;
|
4 | 5 | import java.util.ArrayList;
|
5 | 6 | import java.util.Random;
|
6 | 7 |
|
7 | 8 | /**
|
| 9 | + * |
8 | 10 | * Controller.java
|
9 | 11 | * Controleur
|
10 | 12 | * Génère les obstacles et powerups
|
11 | 13 | */
|
12 |
| -class Controller { |
13 |
| - |
14 |
| - public final ArrayList<Rectangle> columns = new ArrayList<>(); |
15 |
| - private final Random rand = new Random(); |
16 |
| - |
| 14 | +public class Controller { |
| 15 | + |
| 16 | + Game game; |
| 17 | + |
| 18 | + public ArrayList<Rectangle> columns = new ArrayList<>(); |
| 19 | + public Random random = new Random(); |
| 20 | + |
17 | 21 | public Controller() {
|
18 | 22 | }
|
19 |
| - |
20 |
| - public void addColumn(boolean start) { |
| 23 | + |
| 24 | + public void addColumn(int level) { |
| 25 | + //int space = 300; |
21 | 26 | int width = 10;
|
22 |
| - int height = 10 + rand.nextInt(80); |
23 |
| - |
24 |
| - int r_height = Runner.HEIGHT - height - (start ? 140 : 120); |
25 |
| - int r_width = start ? Runner.WIDTH + width + columns.size() * 900 : columns.get(columns.size() - 1).x + 600; |
26 |
| - |
27 |
| - columns.add(new Rectangle(r_width, r_height, width, height)); |
28 |
| - |
| 27 | + int height = 10; |
| 28 | + |
| 29 | + int rWidth = 10; |
| 30 | + |
| 31 | + // une chance sur deux d'obtenir un trou sous la colonne |
| 32 | + int hole = random.nextBoolean() ? 20 : 0; |
| 33 | + |
| 34 | + switch (level) { |
| 35 | + case 0: |
| 36 | + height = 10 + random.nextInt(40); |
| 37 | + rWidth = Runner.WIDTH + width + columns.size() * 900; |
| 38 | + break; |
| 39 | + case 1: |
| 40 | + height = 10 + random.nextInt(60); |
| 41 | + rWidth = columns.get(columns.size()-1).x + 600; |
| 42 | + break; |
| 43 | + case 2: |
| 44 | + height = 10 + random.nextInt(80); |
| 45 | + rWidth = columns.get(columns.size()-1).x + 600; |
| 46 | + break; |
| 47 | + case 3: |
| 48 | + height = 10 + random.nextInt(100); |
| 49 | + rWidth = columns.get(columns.size()-1).x + 600; |
| 50 | + break; |
| 51 | + case 4: |
| 52 | + height = 10 + random.nextInt(120); |
| 53 | + rWidth = columns.get(columns.size()-1).x + 600; |
| 54 | + break; |
| 55 | + } |
| 56 | + |
| 57 | + int rHeight = Runner.HEIGHT - height - 120 - hole; |
| 58 | + columns.add(new Rectangle(rWidth, rHeight, width, height)); |
29 | 59 | }
|
30 |
| - |
| 60 | + |
31 | 61 | public void paintColumn(Graphics g, Rectangle column) {
|
32 | 62 | g.setColor(Color.green.darker());
|
33 | 63 | g.fillRect(column.x, column.y, column.width, column.height);
|
|
0 commit comments