如何对libgdx类进行junit测试有pictures和pictures按钮

avwztpqn  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(198)

菜单类

package com.gdx.game.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.gdx.game.HuntersGame;

public class InfoScreen implements Screen {

    HuntersGame game;
    Texture background,backBefore,backAfter,textInfo;
    /**
     * Constructor, Links the Game instance
     * @param game the Game instance provided by the GameScreen, contains the sprite batch
     *             which is essential for rendering
     */
    public InfoScreen(HuntersGame game){
        this.game = game;
        //play button as image
        backBefore = new Texture("backBefore.png");
        backAfter = new Texture("backAfter.png");
        //text
        textInfo = new Texture("info.png");
        //background
        background = new Texture("grass-info.jpg");
    }

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        //positions of back button
        int xb= backBefore.getWidth();
        int yb= backBefore.getHeight();
        //positions of the mouse
        int x=Gdx.input.getX(),y=Gdx.input.getY();

        //start batch
        game.batch.begin();
        game.batch.draw(background,0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        game.batch.draw(textInfo,0,-30,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        //start script for touch and click by mouse

        if(x>=0 && x<=backBefore.getWidth() && y>=0 && y<=backBefore.getHeight()){
            game.batch.draw(backAfter,0,Gdx.graphics.getHeight()-backBefore.getHeight());
            if(Gdx.input.isTouched()){
                this.dispose();
                game.setScreen(new MenuScreen(game));
            }
        }else{
            game.batch.draw(backBefore,0,Gdx.graphics.getHeight()-backBefore.getHeight());
        }

        game.batch.end();
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}

我想为这个类做一个测试,我不知道怎么做,我试图导入mockito作为每一个其他代码,但没有与我一起工作,我尝试了6个小时没有结果,因为我不知道如何mockito工作,搜索太多没有好处,我只想为该类的一个例子,然后我会尝试做高级的例子,谢谢你在高级ps:对于我使用的图像,你可以使用任何图像来检查代码,而对于huntergame类则是关闭的

package com.gdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.gdx.game.screens.GameScreen;
import com.gdx.game.screens.MenuScreen;

public class HuntersGame extends Game {
    public SpriteBatch batch;

    @Override
    public void create () {
        batch = new SpriteBatch();
        this.setScreen(new MenuScreen((this)));
    }

    @Override
    public void dispose () {
        batch.dispose();
    }
}
[the info class looks like][1]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题