LeaderBoard.java

1
package io.github.some_example_name;
2
3
import com.badlogic.gdx.Gdx;
4
import com.badlogic.gdx.Input;
5
import com.badlogic.gdx.Screen;
6
import com.badlogic.gdx.graphics.GL20;
7
import com.badlogic.gdx.graphics.OrthographicCamera;
8
import com.badlogic.gdx.graphics.g2d.BitmapFont;
9
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
10
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
11
12
/**
13
 * <code>LeaderBoard</code> creates a leaderboard screen displaying the top 5 user scores
14
 * scores are retrieved from leaderboard.json using the JSONHandler class
15
 * @see Screen
16
 * @see JSONHandler
17
 */
18
public class LeaderBoard implements Screen {
19
20
    private final MyGame game;
21
    private final int finalScore;
22
    private final String name;
23
24
    private OrthographicCamera camera;
25
    private SpriteBatch batch;
26
    private BitmapFont font;
27
    private GlyphLayout layout;
28
29
    private JSONHandler jsonHandler;
30
    private String[] topScores;
31
32
    /**
33
     * constructor for LeaderBoard which takes the user's name, and the final score
34
     * creates the new screen
35
     * @param game
36
     * @param name
37
     * @param finalScore
38
     */
39
    public LeaderBoard(MyGame game, String name, int finalScore) {
40
        this.game = game;
41
        this.name = name;
42
        this.finalScore = finalScore;
43
44
        camera = new OrthographicCamera();
45 1 1. <init> : removed call to com/badlogic/gdx/graphics/OrthographicCamera::setToOrtho → NO_COVERAGE
        camera.setToOrtho(false, 640, 480);
46
47
        batch = new SpriteBatch();
48
        font = new BitmapFont();
49 1 1. <init> : removed call to com/badlogic/gdx/graphics/g2d/BitmapFont$BitmapFontData::setScale → NO_COVERAGE
        font.getData().setScale(2.5f);
50
51
        layout = new GlyphLayout();
52
    }
53
54
    @Override
55
    public void show() {
56
        jsonHandler = new JSONHandler();
57
58 2 1. show : changed conditional boundary → NO_COVERAGE
2. show : negated conditional → NO_COVERAGE
        if (finalScore > 0) {
59 1 1. show : removed call to io/github/some_example_name/JSONHandler::writeLeaderboard → NO_COVERAGE
            jsonHandler.writeLeaderboard(name, finalScore);
60
        }
61
62
        topScores = jsonHandler.readLeaderboardAsStrings();
63
    }
64
65
    /**
66
     * the <code>render</code> method displays the top 5 scores to the user
67
     * in the format position) name - score
68
     * e.g 1) testuser 430
69
     * @param delta
70
     */
71
    @Override
72
    public void render(float delta) {
73 1 1. render : removed call to com/badlogic/gdx/graphics/GL20::glClearColor → NO_COVERAGE
        Gdx.gl.glClearColor(0.3f, 0.4f, 0.55f, 1f);
74 1 1. render : removed call to com/badlogic/gdx/graphics/GL20::glClear → NO_COVERAGE
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
75
76 1 1. render : removed call to com/badlogic/gdx/graphics/OrthographicCamera::update → NO_COVERAGE
        camera.update();
77 1 1. render : removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::setProjectionMatrix → NO_COVERAGE
        batch.setProjectionMatrix(camera.combined);
78
79 1 1. render : removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::begin → NO_COVERAGE
        batch.begin();
80
81 1 1. render : removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE
        drawCenteredText("Leaderboard", 430);
82
83 1 1. render : negated conditional → NO_COVERAGE
        if (topScores != null) {
84 2 1. render : negated conditional → NO_COVERAGE
2. render : changed conditional boundary → NO_COVERAGE
            for (int i = 0; i < topScores.length; i++) {
85 1 1. render : negated conditional → NO_COVERAGE
                if (topScores[i] != null) {
86 3 1. render : Replaced integer subtraction with addition → NO_COVERAGE
2. render : removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE
3. render : Replaced integer multiplication with division → NO_COVERAGE
                    drawCenteredText(topScores[i], 370 - (i * 40));
87
                }
88
            }
89
        }
90
91 1 1. render : removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE
        drawCenteredText("Your Score: " + finalScore, 150);
92 1 1. render : removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE
        drawCenteredText("Press SPACE to return to menu", 80);
93
94 1 1. render : removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::end → NO_COVERAGE
        batch.end();
95
96 1 1. render : negated conditional → NO_COVERAGE
        if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
97 1 1. render : removed call to io/github/some_example_name/MyGame::setScreen → NO_COVERAGE
            game.setScreen(new MenuScreen(game));
98
        }
99
    }
100
101
    /**
102
     * <code>drawCenteredText</code> draws text centered horizontally on screen
103
     * @param String text
104
     * @param float y
105
     */
106
    private void drawCenteredText(String text, float y) {
107 1 1. drawCenteredText : removed call to com/badlogic/gdx/graphics/g2d/GlyphLayout::setText → NO_COVERAGE
        layout.setText(font, text);
108 2 1. drawCenteredText : Replaced float subtraction with addition → NO_COVERAGE
2. drawCenteredText : Replaced float division with multiplication → NO_COVERAGE
        float x = (camera.viewportWidth - layout.width) / 2f;
109 1 1. drawCenteredText : removed call to com/badlogic/gdx/graphics/g2d/BitmapFont::draw → NO_COVERAGE
        font.draw(batch, layout, x, y);
110
    }
111
112
    @Override
113
    public void dispose() {
114 1 1. dispose : removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::dispose → NO_COVERAGE
        batch.dispose();
115 1 1. dispose : removed call to com/badlogic/gdx/graphics/g2d/BitmapFont::dispose → NO_COVERAGE
        font.dispose();
116
    }
117
118
    @Override public void resize(int width, int height) {}
119
    @Override public void pause() {}
120
    @Override public void resume() {}
121
    @Override public void hide() {}
122
}

Mutations

45

1.1
Location : <init>
Killed by : none
removed call to com/badlogic/gdx/graphics/OrthographicCamera::setToOrtho → NO_COVERAGE

49

1.1
Location : <init>
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/BitmapFont$BitmapFontData::setScale → NO_COVERAGE

58

1.1
Location : show
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : show
Killed by : none
negated conditional → NO_COVERAGE

59

1.1
Location : show
Killed by : none
removed call to io/github/some_example_name/JSONHandler::writeLeaderboard → NO_COVERAGE

73

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/GL20::glClearColor → NO_COVERAGE

74

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/GL20::glClear → NO_COVERAGE

76

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/OrthographicCamera::update → NO_COVERAGE

77

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::setProjectionMatrix → NO_COVERAGE

79

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::begin → NO_COVERAGE

81

1.1
Location : render
Killed by : none
removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE

83

1.1
Location : render
Killed by : none
negated conditional → NO_COVERAGE

84

1.1
Location : render
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : render
Killed by : none
changed conditional boundary → NO_COVERAGE

85

1.1
Location : render
Killed by : none
negated conditional → NO_COVERAGE

86

1.1
Location : render
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

2.2
Location : render
Killed by : none
removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE

3.3
Location : render
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

91

1.1
Location : render
Killed by : none
removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE

92

1.1
Location : render
Killed by : none
removed call to io/github/some_example_name/LeaderBoard::drawCenteredText → NO_COVERAGE

94

1.1
Location : render
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::end → NO_COVERAGE

96

1.1
Location : render
Killed by : none
negated conditional → NO_COVERAGE

97

1.1
Location : render
Killed by : none
removed call to io/github/some_example_name/MyGame::setScreen → NO_COVERAGE

107

1.1
Location : drawCenteredText
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/GlyphLayout::setText → NO_COVERAGE

108

1.1
Location : drawCenteredText
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

2.2
Location : drawCenteredText
Killed by : none
Replaced float division with multiplication → NO_COVERAGE

109

1.1
Location : drawCenteredText
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/BitmapFont::draw → NO_COVERAGE

114

1.1
Location : dispose
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::dispose → NO_COVERAGE

115

1.1
Location : dispose
Killed by : none
removed call to com/badlogic/gdx/graphics/g2d/BitmapFont::dispose → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.15.0