In the Team class, getScore (normal getter) is giving me an error and, I don't know how to fix it. The whole program is not working. Maybe I didn't add the score properly? I have 5 classes and two are giving me alot of errors that I can't figure out
Team:
public class Team {
private String name;
private Player player1;
private Player player2;
private Player player3;
public Team(String name, Player p1, Player p2, Player p3) {
this.name = name;
player1 = p1;
player2 = p2;
player3 = p3;
}
public Player choosePlayerRandomly() {
double ranGen = Math.random();
if (ranGen > 0 && ranGen < .33) {
return player1;
} else if (ranGen > .33 && ranGen < .66) {
return player2;
} else {
return player3;
}
}
public int getScore() {
return score;
}
public void incrementTeamScore(int points) {
//score += points;
//dice = new Dice(2 * (level() - 1) + 6);
player1.incrementScore(points);
player2.incrementScore(points);
player3.incrementScore(points);
}
public String summary() {
String teamName = "Team " + name + "/n";
String won = "/twon " + getWonFights() + "times, " + "team score "
+ getScore();
String pl1 = "/n/t/tplayer 1: " + player1.getName() + ", level: "
+ player1.level() + ", score: " + player1.getScore();
String pl2 = "/n/t/tplayer 2: " + player2.getName() + ", level: "
+ player2.level() + ", score: " + player2.getScore();
String pl3 = "/n/t/tplayer 3: " + player3.getName() + ", level: "
+ player3.level() + ", score: " + player3.getScore();
return teamName + won + pl1 + pl2 + pl3;
}
public int getWonFights() {
return player1.getWonFightCount() + player2.getWonFightCount()
+ player3.getWonFightCount();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Player getPlayer1() {
return player1;
}
public void setPlayer1(Player player1) {
this.player1 = player1;
}
public Player getPlayer2() {
return player2;
}
public void setPlayer2(Player player2) {
this.player2 = player2;
}
public Player getPlayer3() {
return player3;
}
public void setPlayer3(Player player3) {
this.player3 = player3;
}
}'
Game class:
'public class Game {
private Team team1;
private Team team2;
private int round=0;
public Game(String team1Name, String team2Name, Player p1, Player p2, Player p3, Player p4, Player p5, Player p6){
team1 = new Team(team1Name,p1,p2,p3);
team2 = new Team(team2Name,p4,p5,p6);
}
public void play(int turns){
Team won = playTurn();
if (won==null){
String tie= "Turn " + round +": was a tie!";
}
else{
String turn= "Turn "+ round+ ": Team" +won+" wins!";
}
if (round==turns){
String end = "There were "+ turns+ " played. Here is a summary: " + "/n"+ team1.summary()+ "/n"+ team2.summary();
}
round++;}
public Team playTurn(){
Team tie=null;
Player t1= team1.choosePlayerRandomly();
Player t2 = team2.choosePlayerRandomly();
int roll1= t1.rollDice();
int roll2= t2.rollDice();
if (roll1>roll2){
t1.incrementWonFights();
t1.incrementFights();
t1.incrementScore(250);
t2.incrementFights();
return team1;
}
else if(roll2>roll1){
t2.incrementWonFights();
t2.incrementFights();
t2.incrementScore(250);
t1.incrementFights();
return team2;
}
else{
return tie;
}}}`
Player:
public class Player {
private int score;
private String name;
private Dice dice;
private int fightCount;
private int wonFightCount;
public Player(String name) {
this.name = name;
this.score = 0;
this.dice = new Dice(6);
}
public void incrementScore(int points) {
score = score+points;
int levelCheck=level();
if (levelCheck==2){
dice = new Dice(8);
}
else if(levelCheck==3){
dice = new Dice(10);
}
else if (levelCheck==4){
dice=new Dice(12);}
}
public int level() {
int level = 0;
if (score < 1000) {
return 1;
}
if (score > 1000 && score < 4999) {
return 2;
}
if (score > 5000 && score < 9999) {
return 3;
}
if (score > 10000) {
return 4;
}
return level;
}
public int rollDice() {
return dice.roll(1);
}
public void incrementWonFights() {
wonFightCount++;
}
public void incrementFights() {
fightCount++;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Dice getDice() {
return dice;
}
public void setDice(Dice dice) {
this.dice = dice;
}
public int getFightCount() {
return fightCount;
}
public void setFightCount(int fightCount) {
this.fightCount = fightCount;
}
public int getWonFightCount() {
return wonFightCount;
}
public void setWonFightCount(int wonFightCount) {
this.wonFightCount = wonFightCount;
}
}
Dice:
public class Dice {
private int sides;
public Dice(int s){
if(s<2) s = 6;
this.sides = s;
}
public Dice(){
this(6);
}
public int roll(int times){
int score = 0;
if (times>0){
for(int i = 0; i < times; i++){
score += (int) (sides*Math.random() + 1);
}
}
return score;
}
}
Aucun commentaire:
Enregistrer un commentaire