Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Commit fb518f0

Browse files
PouletPoulet
authored andcommitted
amélioré la génération des colonnes : difficulté progressive, trou
1 parent 4e449db commit fb518f0

File tree

4 files changed

+64
-24
lines changed

4 files changed

+64
-24
lines changed

src/game/Controller.java

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,63 @@
1+
12
package game;
23

34
import java.awt.*;
45
import java.util.ArrayList;
56
import java.util.Random;
67

78
/**
9+
*
810
* Controller.java
911
* Controleur
1012
* Génère les obstacles et powerups
1113
*/
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+
1721
public Controller() {
1822
}
19-
20-
public void addColumn(boolean start) {
23+
24+
public void addColumn(int level) {
25+
//int space = 300;
2126
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));
2959
}
30-
60+
3161
public void paintColumn(Graphics g, Rectangle column) {
3262
g.setColor(Color.green.darker());
3363
g.fillRect(column.x, column.y, column.width, column.height);

src/game/Game.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.*;
44
import java.awt.event.MouseEvent;
5+
import static java.lang.Math.round;
56
import java.util.logging.Level;
67
import java.util.logging.Logger;
78

@@ -15,6 +16,7 @@ class Game implements Runnable {
1516
private final Player player;
1617
private int ticks;
1718
private int score;
19+
private int level = 0;
1820

1921
public Game() {
2022

@@ -23,7 +25,7 @@ public Game() {
2325
score = 0;
2426

2527
for (int i = 0; i < 5; i++) {
26-
c.addColumn(true);
28+
c.addColumn(0);
2729
}
2830
}
2931

@@ -43,16 +45,22 @@ public void run() {
4345
if (ticks % 2 == 0 && player.ymotion < 15) {
4446
player.ymotion += 2;
4547
}
46-
48+
49+
// incrémente le niveau tout les 500 ticks
50+
if (ticks % 250 == 0) {
51+
level++;
52+
speed = (int)round(speed * 1.2);
53+
}
54+
4755
for (int i = 0; i < c.columns.size(); i++) {
4856
Rectangle column = c.columns.get(i);
4957

5058
if (column.x + column.width < 0) {
5159
c.columns.remove(column);
52-
c.addColumn(false);
60+
c.addColumn(1);
5361

5462
if (column.y == 0) {
55-
c.addColumn(false);
63+
c.addColumn(1);
5664
}
5765
}
5866
}
@@ -124,6 +132,9 @@ void render(Graphics g) {
124132
}
125133
String scoreString = "Score : " + score;
126134
g.drawString(scoreString, 20, Runner.HEIGHT - 50);
135+
136+
String levelString = "Level : " + level;
137+
g.drawString(levelString, Runner.WIDTH - 250, Runner.HEIGHT - 50);
127138
}
128139

129140
public void mousePressed(MouseEvent e) {

src/game/Player.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public void jump() {
2828

2929
// fait se baisser player
3030
public void crouch() {
31-
/*this.height -= 20;
31+
crouched = true;
32+
this.height -= 20;
3233
this.y += 20;
33-
System.out.println("CROUCHED : " + height);*/
34+
//this.ymotion -= 10;
35+
System.out.println("CROUCHED : " + height);
3436
}
3537

3638
}

src/game/Renderer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ protected void paintComponent(Graphics g) {
1717
case GAME:
1818
case OVER:
1919
Runner.game.render(g);
20-
System.out.println("rendered game/over");
2120
break;
2221
case MENU:
2322
Runner.menu.render(g);
24-
System.out.println("menu");
2523
break;
2624
case HISCORE:
2725
break;
2826
}
2927

3028
}
3129

32-
3330
}

0 commit comments

Comments
 (0)