Book.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.graphics.Texture;
6
import com.badlogic.gdx.graphics.g2d.BitmapFont;
7
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
8
import com.badlogic.gdx.math.Vector2;
9
10
/**
11
 * <code> Book </code> is an interactable game object, that acts as the
12
 * positive game event by allowing the player to find a "sweet treat"
13
 * giving a temporary speed boost.
14
 */
15
public class Book {
16
17
    private Texture bookTexture;
18
    private Vector2 position;
19
    private BitmapFont font;
20
21
    private final MyGame game;
22
    private final GameScreen gameScreen;
23
    private final BookLogic logic;
24
25
    /**
26
     * Constructor for <code> Book </code>, with a set of coordinates.
27
     *
28
     * @param x Horizontal position for book to spawn in.
29
     * @param y Vertical position for book to spawn in.
30
     */
31
    public Book(float x, float y, MyGame game, GameScreen gameScreen) {
32
        this.game = game;
33
        this.gameScreen = gameScreen;
34
35
        this.bookTexture = new Texture("Book.png");
36
        this.position = new Vector2(x, y);
37
        this.font = new BitmapFont();
38
39
        this.logic = new BookLogic(5f);
40
    }
41
42
    /**
43
     * Update attributes of book, and handle interaction logic.
44
     *
45
     * @param player Player character.
46
     * @param delta Time elapsed since last frame.
47
     */
48
    public void update(Player player, float delta) {
49 1 1. update : negated conditional → NO_COVERAGE
        if (!logic.isSearched()
50 1 1. update : negated conditional → NO_COVERAGE
            && Gdx.input.isKeyJustPressed(Input.Keys.E)
51 2 1. update : negated conditional → NO_COVERAGE
2. update : changed conditional boundary → NO_COVERAGE
            && player.getPosition().dst(position) < 50f) {
52
53 1 1. update : removed call to io/github/some_example_name/BookLogic::search → NO_COVERAGE
            logic.search();
54 1 1. update : removed call to io/github/some_example_name/MyGame::setScreen → NO_COVERAGE
            game.setScreen(new QuizScreen(game, gameScreen));
55
        }
56
57 1 1. update : removed call to io/github/some_example_name/BookLogic::update → NO_COVERAGE
        logic.update(delta);
58
    }
59
60
    /**
61
     * Convenience method to draw the book sprite.
62
     *
63
     * @param batch SpriteBatch used by application to render all sprites.
64
     */
65
    public void render(SpriteBatch batch) {
66 1 1. render : negated conditional → NO_COVERAGE
        if (!logic.isSearched()) {
67 1 1. render : removed call to com/badlogic/gdx/graphics/g2d/SpriteBatch::draw → NO_COVERAGE
            batch.draw(bookTexture, position.x, position.y, 15, 15);
68
        }
69
    }
70
71
    /**
72
     * Dispose textures and fonts.
73
     */
74
    public void dispose() {
75 1 1. dispose : removed call to com/badlogic/gdx/graphics/Texture::dispose → NO_COVERAGE
        bookTexture.dispose();
76 1 1. dispose : removed call to com/badlogic/gdx/graphics/g2d/BitmapFont::dispose → NO_COVERAGE
        font.dispose();
77
    }
78
}
79

Mutations

49

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

50

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

51

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

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

53

1.1
Location : update
Killed by : none
removed call to io/github/some_example_name/BookLogic::search → NO_COVERAGE

54

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

57

1.1
Location : update
Killed by : none
removed call to io/github/some_example_name/BookLogic::update → NO_COVERAGE

66

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

67

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

75

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

76

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