Repository navigation
Expand file tree
/
Copy pathChifumi.java
More file actions
80 lines (64 loc) · 2.07 KB
/
Copy pathChifumi.java
File metadata and controls
80 lines (64 loc) · 2.07 KB
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
74
75
76
77
78
import java.util.Scanner;
public class Chifumi {
int humanScore = 0;
int botScore = 0;
String rock = "pierre";
String paper = "papier";
String scissors = "ciseaux";
int round = 3;
int playerInput = 0;
// rounds + scanner
public void roundStart () {
Scanner input = new Scanner(System.in);
String humanChoice = null;
String botChoice = null;
while (playerInput < 3) {
System.out.println("Fait ton choix entre pierre, papier ou ciseaux ");
System.out.print("P1 choisi: ");
humanChoice = input.nextLine();
// Affiche le texte saisit par l'utilisateur
System.out.println(humanChoice);
// p2
System.out.print("P2 choisi: ");
botChoice = input.nextLine();
System.out.println(botChoice);
playerInput++;
if (humanChoice.equals(rock) && botChoice.equals(scissors) || humanChoice.equals(paper) && botChoice.equals(rock) || humanChoice.equals(scissors) && botChoice.equals(paper)) {
this.humanScore++;
this.round--;
System.out.println("human win");
return;
}
if (humanChoice.equals(botChoice)) {
this.round--;
System.out.println("Draw");
} else {
this.round--;
this.botScore++;
System.out.println("bot wins");
}
}
}
// score
public void victoryScore () {
System.out.println(humanScore+" " +"vs"+ " " +botScore);
}
// final score
public String totalScore() {
if (this.humanScore > this.botScore) {
return "Human win the game !";
}
if (this.humanScore < this.botScore) {
return "Bot win the game!";
} else {
return "Draw game";
}
}
public void startGame() {
while (this.round > 0) {
this.roundStart();
this.victoryScore();
}
System.out.println("Game's finish" + " "+this.totalScore());
}
}