我正在尝试使用 Jackson 的 ObjectMapper 将以下 Player 对象编写为 String。
package models.Game;
import models.Game.Enums.SnowballState;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import java.util.ArrayList;
import java.util.List;
public class Player {
private Circle circle;
private String name;
private Color color;
private int points = 0;
public int getLives() {
return lives;
}
private int lives = 3;
private List<Snowball> snowballs;
private Circle oldCircle;
private int stepSize = 10;
public Player(String name, Color color) {
this.name = name;
circle = new Circle();
oldCircle = new Circle();
this.color = color;
snowballs = new ArrayList<>();
snowballs.add(new Snowball(this));
snowballs.add(new Snowball(this));
snowballs.add(new Snowball(this));
}
public Player() {
}
private void removeLife() {
this.lives--;
}
public int getHit() {
removeLife();
return getLives();
}
public int shotSuccess() {
points+= 50;
return points;
}
public int getSnowballAmount() {
int balls = 0;
for (Snowball ball : snowballs) {
if (ball.getState() == SnowballState.CREATED) {
balls++;
}
}
return balls;
}
public List<Snowball> getSnowballs() {
return snowballs;
}
public Snowball getNextSnowball() {
for (Snowball ball : snowballs) {
if (ball.getState() == SnowballState.CREATED) {
return ball;
}
}
return null;
}
public void createSnowball() {
if (getSnowballAmount() < 3) {
snowballs.add(new Snowball(this));
}
}
public Color getColor() {
return this.color;
}
public Circle getCircle() {
return this.circle;
}
public void moveLeft() {
saveOld();
circle.setTranslateX(circle.getTranslateX() - stepSize);
}
public void moveRight() {
saveOld();
circle.setTranslateX(circle.getTranslateX() + stepSize);
}
慕田峪7331174
米琪卡哇伊
繁星淼淼
随时随地看视频慕课网APP
相关分类