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

Commit 9b9dd87

Browse files
LevFlavienLevFlavien
authored andcommitted
"final" commit
2 parents fb518f0 + e5d04f1 commit 9b9dd87

File tree

8 files changed

+56
-33
lines changed

8 files changed

+56
-33
lines changed

src/game/Controller.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
public class Controller {
1515

16-
Game game;
17-
1816
public ArrayList<Rectangle> columns = new ArrayList<>();
1917
public Random random = new Random();
2018

src/game/Game.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Game() {
3333
public void run() {
3434
int speed = 10;
3535
System.out.println("Game.run()");
36-
36+
3737
while (Runner.state == Runner.STATE.GAME) {
3838
ticks++;
3939

@@ -47,7 +47,7 @@ public void run() {
4747
}
4848

4949
// incrémente le niveau tout les 500 ticks
50-
if (ticks % 250 == 0) {
50+
if (ticks % 500 == 0) {
5151
level++;
5252
speed = (int)round(speed * 1.2);
5353
}
@@ -76,18 +76,19 @@ public void run() {
7676
}
7777
}
7878

79-
// stoppe player au niveau du sol
80-
if (player.y >= Runner.HEIGHT - 160 || player.y < 0) {
79+
// stoppe player au niveau du sol en fonction de sa position
80+
if ((player.y >= Runner.HEIGHT - 160 || player.y < 0) && !player.crouched) {
8181
player.y = Runner.HEIGHT - 160;
82-
}
83-
84-
// réinitialise le double saut quand player atterit
85-
if (player.y == 440) {
82+
player.jumping = 0;
83+
} else if ((player.y >= Runner.HEIGHT - 140 || player.y < 0) && player.crouched) {
84+
player.y = Runner.HEIGHT - 140;
8685
player.jumping = 0;
8786
}
88-
System.out.println(player.y);
89-
// actualise le rendu
90-
Runner.renderer.repaint();
87+
88+
// actualise le rendu tout les deux ticks
89+
if (ticks % 2 == 0) {
90+
Runner.renderer.repaint();
91+
}
9192

9293
try {
9394
Thread.sleep(20);
@@ -142,9 +143,11 @@ public void mousePressed(MouseEvent e) {
142143
switch (Runner.state) {
143144
case GAME:
144145
System.out.println(Runner.state);
145-
if (e.getButton() == 1) { // si clic droit
146+
// si clic gauche
147+
if (e.getButton() == 1) {
146148
player.jump();
147-
} else {
149+
player.uncrouch();
150+
} else if (player.jumping == 0) {
148151
player.crouch();
149152
}
150153
break;
@@ -155,5 +158,16 @@ public void mousePressed(MouseEvent e) {
155158
break;
156159
}
157160
}
161+
162+
public void mouseReleased(MouseEvent e) {
163+
// si clic droit pendant l'état de jeu
164+
if (e.getButton() == 3 && player.crouched) {
165+
player.crouch();
166+
}
167+
}
168+
169+
public void mouseClicked(MouseEvent e) {
170+
System.out.println("a");
171+
}
158172

159173
}

src/game/HighScore.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
class HighScore {
66

77
private static final File scoreFile = new File("score.txt");
8-
9-
public static int getHighScore() {
8+
9+
// Récupère le score présent dans le fichier score.txt
10+
public static int getHighScore() {
1011
int currentHighScore = 0;
1112

1213
if (!scoreFile.exists()) {
@@ -32,7 +33,8 @@ public static int getHighScore() {
3233

3334
return currentHighScore;
3435
}
35-
36+
37+
//
3638
public static void setHighScore(int score) {
3739
if (score > getHighScore()) {
3840
System.out.println("NEW HIGHSCORE" + score + getHighScore());

src/game/Menu.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Menu {
1010

1111
public static final Rectangle playButton = new Rectangle(Runner.WIDTH / 2, 200, 140, 50);
12-
public static final Rectangle hiscoreButton = new Rectangle(Runner.WIDTH / 2, 300, 140, 50);
12+
public static final Rectangle highscoreButton = new Rectangle(Runner.WIDTH / 2, 300, 140, 50);
1313
public static final Rectangle quitButton = new Rectangle(Runner.WIDTH / 2, 400, 140, 50);
1414

1515
public void render(Graphics g) {
@@ -24,14 +24,14 @@ public void render(Graphics g) {
2424
g2d.setColor(Color.blue);
2525
g.setFont(fnt0.deriveFont(38f));
2626
g.drawString("Play", playButton.x + 10, playButton.y + 40);
27-
g.drawString("Score", hiscoreButton.x + 10, hiscoreButton.y + 40);
27+
g.drawString("Score", highscoreButton.x + 10, highscoreButton.y + 40);
2828
g.drawString("Quit", quitButton.x + 10, quitButton.y + 40);
2929
g2d.draw(playButton);
30-
g2d.draw(hiscoreButton);
30+
g2d.draw(highscoreButton);
3131
g2d.draw(quitButton);
3232
}
3333

3434
public void displayScores() {
35-
JOptionPane.showMessageDialog(null, "Le score le plus haut est actuellement " + HighScore.getHighScore());
35+
JOptionPane.showMessageDialog(null, "Le score le plus haut est actuellement\n" + HighScore.getHighScore());
3636
}
3737
}

src/game/MouseInput.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class MouseInput implements MouseListener {
1313
public void mousePressed(MouseEvent e) {
1414
if (Runner.state == Runner.STATE.MENU) {
1515
System.out.println(Runner.state);
16-
16+
System.out.println(e.getButton());
1717
int x = e.getX() - 3;
1818
int y = e.getY() - 22;
1919

2020
//play
2121
if (Menu.playButton.contains(x, y)) {
2222
Runner.state = Runner.STATE.GAME;
2323
Runner.start();
24-
} else if (Menu.hiscoreButton.contains(x, y)) {
24+
} else if (Menu.highscoreButton.contains(x, y)) {
2525
Runner.menu.displayScores();
2626
} else if (Menu.quitButton.contains(x, y)) {
2727
Runner.quit();
@@ -34,6 +34,7 @@ public void mousePressed(MouseEvent e) {
3434

3535
@Override
3636
public void mouseReleased(MouseEvent e) {
37+
Runner.game.mouseReleased(e);
3738
}
3839

3940
@Override

src/game/Player.java

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

2929
// fait se baisser player
3030
public void crouch() {
31-
crouched = true;
32-
this.height -= 20;
33-
this.y += 20;
34-
//this.ymotion -= 10;
35-
System.out.println("CROUCHED : " + height);
31+
if (!crouched) {
32+
this.height -= 20;
33+
this.y = 460;
34+
System.out.println("CROUCHED : " + height);
35+
this.crouched = true;
36+
} else {
37+
uncrouch();
38+
}
3639
}
37-
40+
41+
public void uncrouch() {
42+
if (crouched) {
43+
this.crouched = false;
44+
this.height += 20;
45+
this.y = 440;
46+
}
47+
}
48+
3849
}

src/game/Renderer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ protected void paintComponent(Graphics g) {
2121
case MENU:
2222
Runner.menu.render(g);
2323
break;
24-
case HISCORE:
25-
break;
2624
}
2725

2826
}

src/game/Runner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public static void main(String[] args) {
5050

5151
public enum STATE {
5252
MENU,
53-
HISCORE,
5453
GAME,
5554
OVER
5655
}

0 commit comments

Comments
 (0)