Commit f5706d1f authored by Qi LI's avatar Qi LI
Browse files

litte clean up

parent 31c3053e
package jeu;
public class Frame {
public int firstLance = 0;
public int secondLance = 0;
private int frameScore = 0;
public void setFirstLance(int score) {
this.firstLance = score;
this.frameScore = score;
}
public void setSecondLance(int score) {
this.secondLance = score;
this.frameScore += score;
}
public boolean isStrike() {
return firstLance == 10;
}
public boolean isSpare() {
return !this.isStrike() && (firstLance + secondLance) == 10;
}
public int getScore() {
return frameScore;
}
public void addBonus(int bonus) {
this.frameScore += bonus;
}
}
package jeu;
import java.util.ArrayList;
import java.util.List;
public class Score {
//private ArrayList<int[][]> scoreTable;
private ArrayList<Frame[]> scoreTable;
public Score(int joueurNb) {
this.scoreTable = new ArrayList<Frame[]>();
for (int i = 0; i < joueurNb; ++i) {
scoreTable.add(new Frame[10]);
}
}
public Score (List<Joueur> joueurs) {
int nbJoueurs = joueurs.size();
this.scoreTable = new ArrayList<Frame[]>();
while (scoreTable.size() <= nbJoueurs) {
scoreTable.add(new Frame[10]);
}
}
public int getScore (int indexJoueur, int frameNb) {
return scoreTable.get(indexJoueur)[frameNb].getScore();
}
public void updateFrame(int indexJoueur, int frameNb, Frame frame) {
scoreTable.get(indexJoueur)[frameNb] = frame;
}
// the frame of frameNb tour is finished
public void updateScore(int indexJoueur, int frameNb) {
if (frameNb == 0) return;
Frame frame = scoreTable.get(indexJoueur)[frameNb];
Frame lastFrame = scoreTable.get(indexJoueur)[frameNb - 1];
if (lastFrame.isSpare())
lastFrame.addBonus(frame.firstLance);
else if (lastFrame.isStrike() && !frame.isStrike())
lastFrame.addBonus(frame.firstLance + frame.secondLance);
else;
if (frameNb <= 1) return;
Frame beforeLastFrame = scoreTable.get(indexJoueur)[frameNb - 2];
if (beforeLastFrame.isStrike() && lastFrame.isStrike())
beforeLastFrame.addBonus(lastFrame.firstLance + frame.firstLance);
else;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment