| 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.InputAdapter; | |
| 6 | import com.badlogic.gdx.Screen; | |
| 7 | import com.badlogic.gdx.graphics.GL20; | |
| 8 | import com.badlogic.gdx.graphics.OrthographicCamera; | |
| 9 | import com.badlogic.gdx.graphics.g2d.BitmapFont; | |
| 10 | import com.badlogic.gdx.graphics.g2d.GlyphLayout; | |
| 11 | import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
| 12 | ||
| 13 | public class WinScreen implements Screen { | |
| 14 | ||
| 15 | private final MyGame game; | |
| 16 | ||
| 17 | private OrthographicCamera camera; | |
| 18 | private SpriteBatch batch; | |
| 19 | private BitmapFont font; | |
| 20 | private GlyphLayout layout; | |
| 21 | ||
| 22 | private WinScreenLogic winScreenLogic; | |
| 23 | ||
| 24 | private int finalScore; | |
| 25 | private int timeRemaining; | |
| 26 | private int timesCaught; | |
| 27 | ||
| 28 | public WinScreen(MyGame game, int finalScore, int timeRemaining, int timesCaught) { | |
| 29 | this.game = game; | |
| 30 | this.finalScore = finalScore; | |
| 31 | this.timeRemaining = timeRemaining; | |
| 32 | this.timesCaught = timesCaught; | |
| 33 | ||
| 34 | camera = new OrthographicCamera(); | |
| 35 | camera.setToOrtho(false, 640, 480); | |
| 36 | ||
| 37 | batch = new SpriteBatch(); | |
| 38 | font = new BitmapFont(); | |
| 39 | font.getData().setScale(2.5f); | |
| 40 | ||
| 41 | layout = new GlyphLayout(); | |
| 42 | ||
| 43 | // Initialise logic handler for WinScreen | |
| 44 | winScreenLogic = new WinScreenLogic(); | |
| 45 | ||
| 46 | Gdx.input.setInputProcessor(new InputAdapter() { | |
| 47 | @Override | |
| 48 | public boolean keyTyped(char character) { | |
| 49 | // Pass character input to logic | |
| 50 |
1
1. keyTyped : removed call to io/github/some_example_name/WinScreenLogic::processKeyTyped → NO_COVERAGE |
winScreenLogic.processKeyTyped(character); |
| 51 |
1
1. keyTyped : replaced boolean return with false for io/github/some_example_name/WinScreen$1::keyTyped → NO_COVERAGE |
return true; |
| 52 | } | |
| 53 | }); | |
| 54 | } | |
| 55 | ||
| 56 | @Override | |
| 57 | public void render(float delta) { | |
| 58 | Gdx.gl.glClearColor(0.1f, 0.3f, 0.1f, 1); | |
| 59 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
| 60 | ||
| 61 | camera.update(); | |
| 62 | batch.setProjectionMatrix(camera.combined); | |
| 63 | ||
| 64 | // Update the cursor and logic | |
| 65 | winScreenLogic.update(delta); | |
| 66 | ||
| 67 | batch.begin(); | |
| 68 | ||
| 69 | // Title | |
| 70 | drawCenteredText("You Win!", 400); | |
| 71 | ||
| 72 | // Scores | |
| 73 | drawCenteredText("Final Score: " + finalScore, 340); | |
| 74 | drawCenteredText("Dean Penalty: " + (timesCaught * 5), 300); | |
| 75 | ||
| 76 | // Name entry | |
| 77 | drawCenteredText("Enter your name:", 240); | |
| 78 | ||
| 79 | String displayText = winScreenLogic.getName(); | |
| 80 | ||
| 81 | // If the name is not confirmed, show the cursor | |
| 82 | if (!winScreenLogic.isNameConfirmed() && winScreenLogic.isCursorVisible()) { | |
| 83 | displayText += "|"; // Add cursor if visible | |
| 84 | } | |
| 85 | drawCenteredText(displayText, 200); | |
| 86 | ||
| 87 | // Instructions | |
| 88 | if (winScreenLogic.isNameConfirmed()) { | |
| 89 | drawCenteredText("Press L to view Leaderboard", 140); | |
| 90 | drawCenteredText("Press SPACE to return to menu", 100); | |
| 91 | } else { | |
| 92 | drawCenteredText("Press ENTER to confirm name", 140); | |
| 93 | } | |
| 94 | ||
| 95 | batch.end(); | |
| 96 | ||
| 97 | if (winScreenLogic.isNameConfirmed()) { | |
| 98 | if (Gdx.input.isKeyJustPressed(Input.Keys.L)) { | |
| 99 | Gdx.input.setInputProcessor(null); | |
| 100 | game.setScreen(new LeaderBoard(game, winScreenLogic.getName(), finalScore)); | |
| 101 | } | |
| 102 | ||
| 103 | if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { | |
| 104 | Gdx.input.setInputProcessor(null); | |
| 105 | game.setScreen(new MenuScreen(game)); | |
| 106 | } | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | private void drawCenteredText(String text, float y) { | |
| 111 | layout.setText(font, text); | |
| 112 | float x = (camera.viewportWidth - layout.width) / 2f; | |
| 113 | font.draw(batch, layout, x, y); | |
| 114 | } | |
| 115 | ||
| 116 | @Override | |
| 117 | public void dispose() { | |
| 118 | batch.dispose(); | |
| 119 | font.dispose(); | |
| 120 | } | |
| 121 | ||
| 122 | @Override public void show() {} | |
| 123 | @Override public void resize(int width, int height) {} | |
| 124 | @Override public void pause() {} | |
| 125 | @Override public void resume() {} | |
| 126 | @Override public void hide() {} | |
| 127 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 51 |
1.1 |