Java项目在eclipse中运行但在导出时失败

时间:2014-09-19 06:11:40

标签: java eclipse libgdx

大家好,感谢所有帮助!我终于完成了这个项目,它在eclipse中运行良好,但是当我导出它时,我从堆栈跟踪中得到这个错误,对于如何在体系结构方面进行改进的任何帮助都非常感激。

异常是线程“LWJGL Application”中的异常com.badlogic.gdx.utils.GdxRuntimeExcepti on:com.badlogic.gdx.utils.GdxRuntimeException:找不到文件:assets \ font.fnt

它在eclipe中运行良好但在导出时失败

public class ConnectFourApplication extends Game implements ApplicationListener {
	
	private Screen screen;
	private Game game;
	
	public static void main(String[] args) {
		
		new LwjglApplication(new ConnectFourApplication(), "PennyPop", 1280, 720,
				true);	
	}

	public ConnectFourApplication(){
		game = this;
	}
	
	@Override
	public void create() {
		screen = new MainScreen(game);
		setScreen(screen);
		screen.show();
		
	}
	
	@Override
	public void dispose() {
		screen.hide();
		screen.dispose();
		
	}
	
	/** Clears the screen with a white color */
	private void clearWhite() {
		Gdx.gl.glClearColor(1, 1, 1, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
	}

	@Override
	public void pause() {
		screen.pause();
	}

	@Override
	public void render() {
		clearWhite();
		super.render();
	}

	@Override
	public void resize(int width, int height) {
		screen.resize(width, height);
		
	}

	@Override
	public void resume() {
		screen.resume();
	}

public class MainScreen implements Screen {
	
	private final Stage stage;
	private final SpriteBatch spriteBatch;
	
	//Parameter for drawing the buttons
	private final BitmapFont font;
	private final TextureAtlas buttons; 
	private final Button SFXButton;
	private final Button APIButton;
	private final Button GameButton;
	private final Skin images;
	
	//Parameter for Sound
	private final com.badlogic.gdx.audio.Sound SFXClick;
	
	//Parameter for the api call
	private final String WeatherUrl;
	private final HttpRequest request;
	private final City SanFrancisco;
	
	//The screen to load after the game button is hit
	private Screen gamescreen;
	
	private Game game;
	
	
	
	public MainScreen(Game game) {
		
		 this.game = game;
		
		//Set up our assets
		spriteBatch = new SpriteBatch();
		stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, spriteBatch);
	
		font = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
		         Gdx.files.internal("assets/font.png"), false);
			
		buttons = new TextureAtlas("assets/GameButtons.pack");
		images = new Skin(buttons);
		images.addRegions(buttons);
		SFXButton = new Button(images.getDrawable("sfxButton"));
		SFXButton.setPosition(295, 310);
		APIButton = new Button(images.getDrawable("apiButton"));
		APIButton.setPosition(405, 310);
		GameButton = new Button(images.getDrawable("gameButton"));
		GameButton.setPosition(515, 310);
		SFXClick = Gdx.audio.newSound(Gdx.files.internal("assets/button_click.wav"));
		
		//Add our actors to the stage
		stage.addActor(SFXButton);
		stage.addActor(APIButton);
		stage.addActor(GameButton);
		
		//Set up our Url request to be used when clicking the button
		WeatherUrl = "http://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,US";
		request = new HttpRequest(HttpMethods.GET);
		request.setUrl(WeatherUrl);
		SanFrancisco = new City("Unavailable","Unavailable","0","0"); //init san fran to be displayed before they have clicked the button
		
	}

	@Override
	public void dispose() {
		spriteBatch.dispose();
		stage.dispose();
	}

	@Override
	public void render(float delta) {
		stage.act(delta);
		stage.draw();
		
		//Begin sprite batch
		spriteBatch.begin();
		

		//Set our on click listeners for our buttons
		if (SFXButton.isPressed())
			SFXClick.play();
		
		if(APIButton.isPressed())
		{
			CallApi();
		}
			
		if(GameButton.isPressed())
			LoadGame();
		
		
		//Set font color and render the screen
		font.setColor(Color.RED);
		font.draw(spriteBatch, "PennyPop", 455 - font.getBounds("PennpyPop").width/2,
				460 + font.getBounds("PennyPop").height/2);
		
		font.setColor(Color.BLACK);
		font.draw(spriteBatch, "Current Weather", 900 - font.getBounds("PennpyPop").width/2,
				460 + font.getBounds("PennyPop").height/2);
		
		font.setColor(Color.LIGHT_GRAY);
		font.draw(spriteBatch, SanFrancisco.Name, 940 - font.getBounds("PennpyPop").width/2,
				420 + font.getBounds("PennyPop").height/2);
		
		
		font.setColor(Color.RED);
		font.draw(spriteBatch, SanFrancisco.CurrentCondition, 950 - font.getBounds("PennpyPop").width/2,
				300 + font.getBounds("PennyPop").height/2);
		
		
		font.draw(spriteBatch, SanFrancisco.Temperature + " Degrees,", 920 - font.getBounds("PennpyPop").width/2,
				270 + font.getBounds("PennyPop").height/2);
		
		font.draw(spriteBatch, SanFrancisco.WindSpeed, 1200 - font.getBounds("PennpyPop").width/2,
				270 + font.getBounds("PennyPop").height/2);
		
		
		
		//End or sprite batch
		spriteBatch.end();
		
	
	}
	
	//Handles calling our API
	public void CallApi(){
		
		//Sends our stored HTTPRequest object
		 Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
			@Override
			public void handleHttpResponse(HttpResponse httpResponse) {
				
				//Uses our private response reader object to give us a the JSON from the api call
				JSONObject json =  HttpResponseReader(httpResponse);
				
				//Gets the name of the city
				SanFrancisco.Name = (String) json.get("name");		

				//Parsed through our returned JSON for the weather key
				JSONArray WeatherArray = (JSONArray) json.get("weather");
				//Gets the actual weather dictionary 
				JSONObject Weather = (JSONObject) WeatherArray.get(0);
				//Finally get the value with the key of description and assign it 
				//To the San Fran current conditions field
				SanFrancisco.CurrentCondition = (String) Weather.get("description");
				

				
				//Gets the actual main dictionary 
				JSONObject main = (JSONObject) json.get("main");			
				//Finally get the values based on the keys
				SanFrancisco.Temperature = (String) Double.toString((double) main.get("temp"));
			
				//Finally get the wind speed
				JSONObject wind = (JSONObject) json.get("wind");	
				SanFrancisco.WindSpeed = (String) Double.toString((double) wind.get("speed"));
				                 
			}
			
            @Override
            public void failed(Throwable t) {
                Gdx.app.log("Failed ", t.getMessage());
                 
            }
		 });
	}
	
	//When the button game button is clicked should load the connect four game
	public void LoadGame(){
		
		game.setScreen(new GameScreen(game));
		
	}
	
	
	
	//Converts our HttpResponse into a JSON OBject
	private static JSONObject HttpResponseReader(HttpResponse httpResponse){
		
	    BufferedReader read = new BufferedReader(new InputStreamReader(httpResponse.getResultAsStream()));  
        StringBuffer result = new StringBuffer();
        String line = "";
        
        try {
      	  while ((line = read.readLine()) != null) {
			      result.append(line);
			  }
      	  
      	  	  JSONObject json;
			try {
				json = (JSONObject)new JSONParser().parse(result.toString());
				return json;
			} catch (ParseException e) {
				e.printStackTrace();
			}
      	  	
		} catch (IOException e) {
			e.printStackTrace();
		}
        
        return null;

	}

	@Override
	public void resize(int width, int height) {
		stage.setViewport(width, height, false);
	}

	@Override
	public void hide() {
		Gdx.input.setInputProcessor(null);
	}

	@Override
	public void show() {
		Gdx.input.setInputProcessor(stage);
		render(0);
	}

	@Override
	public void pause() {
		// Irrelevant on desktop, ignore this
	}

	@Override
	public void resume() {
		// Irrelevant on desktop, ignore this
	}
 public class GameScreen  implements Screen {

//Our stage and sprites
private final Stage gamestage;
private final SpriteBatch gamesprites;


//Parameter for drawing the pieces
private final BitmapFont gamefont;
private final TextureAtlas pieces; 
private final Skin piecesskin;

//this will be the sprite and texture for our red connect four buttons
private Texture redtexture;
private Sprite redsprite;

//this will be the sprite and texture for our red connect four buttons
private Texture yellowtexture;
private Sprite yellowsprite;
	
//Setup the board
//renders the line
private ShapeRenderer boardlineshape;

//setup the line locations
private int linestartx;
private int linestarty;
private int lineendx;
private int lineendy;
private int linexdistance;
private int lineydistance;

//for this game we will define a board size as the amount of lines the board should contain
private double boardsize;

//Lines required to win
private int linestowin;
private String playersturnstring;
private OrthographicCamera camera;

//Holds all the parameters for our players

//Keeps track of who's turn it is, if 0 player one if 1 player two  
private int playersturn;

//Holds the location of all of player ones pieces
//Needs to be two Dimensional to hold x and y values
private int[][] playeronepieces;

private int playeronepieceindex;

//Holds the location of all of player twos pieces
//Needs to be two Dimensional to hold x and y values
private int[][] playertwopieces;

private int playertwopieceindex;

//make the number of pieces per player variable so it can be changed for the future
private int numberofpiecesperplayer;
	
private Game game;

public boolean gameover;

private boolean isready;

private int[][] RowsAndColumns;


private int columnvalue = 538;



public GameScreen(Game game){
	
	 this.game = game;
	
	//Set up our assets
	gamesprites = new SpriteBatch();
	gamestage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, gamesprites);
	
	//Sets up our font
	gamefont = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
	         Gdx.files.internal("assets/font.png"), false);
	
	pieces = new TextureAtlas("assets/GameButtons.pack");
	piecesskin = new Skin(pieces);
	piecesskin.addRegions(pieces);
	
	//set up our camera
    camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.update();
	
	
    //sets up our red connect four piece
    redtexture = new Texture(Gdx.files.internal("assets/red.png"));
    redsprite = new Sprite(redtexture);
    
    
    //sets up our yellow connect four piece
    yellowtexture = new Texture(Gdx.files.internal("assets/yellow.png"));
    yellowsprite = new Sprite(yellowtexture);
    
	//setup the board
    SetUpGameBoard(8,4,Color.BLACK);
    
    linestartx = 300;
    linestarty = 100;
    lineendx = 300;
    lineendy = 600;
    linexdistance = 100;
    lineydistance = 100;
    
	
	//setup the pieces
    numberofpiecesperplayer = 60;
	
	//initialize anything else we need for the game
	playersturnstring = "";
	
	//start with player one's turn
	playersturn = 0;

	//setup or pieces locations as blank 
	playeronepieces = new int[2][numberofpiecesperplayer]; //create two arrays one for x values one for y
	
	playeronepieceindex = 0;
	
	playertwopieces = new int[2][numberofpiecesperplayer]; //create two arrays one for x values one for y
	
	playertwopieceindex = 0;
	

	gameover = false;
	
	isready = false;
	
	linestowin = 4;
	

	
}

//Should initialize our game board 
public void SetUpGameBoard(int boardsize,int linestowin, Color linecolor){
	
	this.boardsize = boardsize;
	this.linestowin = linestowin;
	boardlineshape = new ShapeRenderer();
	boardlineshape.setProjectionMatrix(camera.combined);
	boardlineshape.setColor(linecolor);
	
	//holds the board cells
	RowsAndColumns = new int[2][(int) boardsize];

}


@Override
public void dispose() {
	// TODO Auto-generated method stub

}

@Override
public void hide() {
	Gdx.input.setInputProcessor(null);

}

@Override
public void pause() {
	// TODO Auto-generated method stub

}

@Override
public void render(float delta) {
	
	//set the stage
	gamestage.act(delta);
	gamestage.draw();
	
	
	//if the mouse is clicked and the game is not over send us back to the main screen
	if (Gdx.input.justTouched() && gameover == true){
		
		//if the game is over and the user clicks send us back to the main screen
		game.setScreen(new MainScreen(game));	
	}		
	
	
	if(isready){	
		//if the mouse is clicked and the game is not over add a piece to player one
		if (Gdx.input.justTouched() && gameover != true){
				
			AddPiece(Gdx.input.getX(), Gdx.input.getY());
		}
	}

	//Draw our board 
	boardlineshape.begin(ShapeType.Line);
	
	///Draw all of the lines for our board
	DrawBoard(linestartx,linestarty,lineendx,lineendy);
	
	boardlineshape.end();

	//Starts our game sprite batch
	gamesprites.begin();

	//Draw all of player ones pieces
	DrawPlayerOnePieces();
	
	//Draw all of player twos pieces
	DrawPlayerTwoPieces();
	
	gamefont.draw(gamesprites, playersturnstring, 515, 650);
	
	//End our game sprite batch
	gamesprites.end();
	
	//Lastly check to make sure our the game is not over
	CheckForGameOver();
	
	isready = true;
	
	
}
	
//draw the board 
private void DrawBoard(int linestartx, int linestarty, int lineendx, int lineendy){
	
	camera.update();
	boardlineshape.setProjectionMatrix(camera.combined);	
	
	//For each line in our board draw a line 
	for(int i =0; i < boardsize; i++)
	{
		//first we will draw the vertical lines then we will change to the horizontal lines
		
		boardlineshape.line(linestartx, linestarty,lineendx, lineendy);
		
		//if the x value exceeds a certian amount then change to the horizontal lines
		
		//increment the start x position to draw another line
		linestartx += linexdistance;
		lineendx += lineydistance;
		
		//if the x start is over 1200 we have drawn the last vertical line so switch to th
		//horizontal lines
		if(linestartx > 1000)
		{
			
			//set our x values and render our horizontal lines
			lineendx = linestartx - linexdistance;
			linestartx = this.linestartx;
			
			linestarty = this.linestarty;
			lineendy = this.linestarty;
			
			for(int index =0; index < boardsize -2; index++){
				
				//increment the start y position to draw another line
				boardlineshape.line(linestartx, linestarty,lineendx, lineendy);
				
				linestarty += lineydistance;
				lineendy += lineydistance;
				
				
		
			}
		}
		
	}
}


//Draws all the current pieces for player one
private void DrawPlayerOnePieces(){
	
	//For all of player one's pieces
	for(int i = 0; i < playeronepieces[1].length;i++)
	{
		//of its not an empty piece draw it 
		if(playeronepieces[0][i] != 0){
			
			gamesprites.draw(redtexture, playeronepieces[0][i], playeronepieces[1][i]);
		}
		
	}
	
}

//Draws all the current pieces for player two
private void DrawPlayerTwoPieces(){
	
	//For all of player two's pieces
	for(int i = 0; i < playertwopieces[1].length;i++)
	{
		//of its not an empty piece draw it 
		if(playertwopieces[0][i] != 0){
			
			gamesprites.draw(yellowtexture, playertwopieces[0][i], playertwopieces[1][i]);
		}
		
	}
	
}

//Adds a piece to whichever players current turn it is
private void AddPiece(int clickx, int clicky){
	
	RestPlayersTurn(playersturn);
	
	int computedx = GetComputedX(clickx,linestartx);
	
	int computedy = GetComputedY(clicky,linestarty);
	
	
	if(playeronepieceindex != 60)
	{
		//makes sure they are clicking inside our board and that there is not already a piece on that part of the board
		if(
				(clickx > linestartx && clickx < linestartx + ((boardsize - 1) * linexdistance))&& 
				(clicky > linestarty && clicky < lineendy)&& 
				(CheckIfPieceExists(computedx,computedy,playeronepieces) == false) &&
				(CheckIfPieceExists(computedx,computedy,playertwopieces) == false) 
		  )
		{
			if(playersturn == 0)
			{
				playeronepieces[0][playeronepieceindex] = computedx; //set the x value
									
				playeronepieces[1][playeronepieceindex] = 700 - computedy; //set the y value
				
				playeronepieceindex++;
				
				playersturnstring = "Player Two's turn";
				
				gamefont.setColor(Color.YELLOW);
			
			}
			else if(playersturn == 1)
			{
				
				playertwopieces[0][playertwopieceindex] = computedx; //set the x value
				
				playertwopieces[1][playertwopieceindex] = 700 - computedy; //set the y value
				
				playertwopieceindex++;

				playersturnstring = "Player One's turn";
				
				gamefont.setColor(Color.RED);
				
			}
			
			//every time we add a piece change the players turn
			playersturn++;
			
		}			
	}

}


//puts our x value in the center of its cell
public int GetComputedX(int touchx, int linestartx){
	
	//compute our x depending on the nearest line
	int lineendx = linestartx + linexdistance;
	
	//for the images width
	int imagewidth = redtexture.getWidth();
	
	for(int i = 0; i < boardsize; i++)
	{
		//if the touched x is in this range than assign the computed x value to
		//half the cell	
		if(touchx > linestartx && touchx < lineendx){
			
			touchx = (lineendx - (linexdistance/2)) - (imagewidth/2);
			break;
		}	
		
		linestartx += linexdistance;
		lineendx += linexdistance;
	}
	
	return touchx;
}


//puts our y value in the center of the cell
public int GetComputedY(int touchy, int linestarty)
{
	//compute our x depending on the nearest line
	int lineendy = linestarty + lineydistance;
	
	//for the images width
	int imageheight = redtexture.getHeight();
	
	//computer our x depending on the nearest line
	for(int i =0; i < boardsize; i++)
	{
		//if the touched x is in this range than assign the computed x value to
		//half the cell	
		if(touchy > linestarty && touchy < lineendy){
			touchy = ((lineendy - (lineydistance/2)) + (imageheight/4));
			break;
		}
		
		linestarty += lineydistance;
		lineendy += lineydistance;	
	}
	
	return touchy;
}

//Sets the next players turn
private void RestPlayersTurn(int playerturn){
	
	if(playerturn == 2){
		
		playersturn = 0;
			
	}
	
}


//check for game over
private void CheckForGameOver(){
			
	//check if player one has a connect four 
	CheckForConnectFourHorizontal();
	CheckForConnectFourVertical();
	CheckForConnectFourDiagonal();
	
}

	
private void CheckForConnectFourHorizontal(){

	int rowvalue = 318;
	
	int columnvalue = 534;
	
	
	//for each column on the board check the row for a horizontal connect four for player one
	for(int i = 0; i < RowsAndColumns[1].length; i++)
	{
		CheckRowForConnectFour(rowvalue,columnvalue,playeronepieces);
		
		rowvalue = 318;
		
		columnvalue = columnvalue - 100;
	}
	
        rowvalue = 318;
	 
	    columnvalue = 534;
	
	
	
	//for each column on the board check the row for a horizontal connect four for player two
	for(int i = 0; i < RowsAndColumns[1].length; i++)
	{
		CheckRowForConnectFour(rowvalue,columnvalue,playertwopieces);
		
		rowvalue = 318;
		
		columnvalue = columnvalue - 100;
	}
	

}

private void CheckForConnectFourVertical(){
	
	
	int rowvalue = 318;
	
	int columnvalue = 534;
	
	//for each column on the board check the row for a horizontal connect four
	for(int i = 0; i < RowsAndColumns[1].length; i++)
	{
		CheckColumnForConnectFour(rowvalue,columnvalue,playeronepieces);
		
		rowvalue = rowvalue + 100 ;
		
		columnvalue = 534;
	}
	
	
	
	rowvalue = 318;
	
	columnvalue = 534;
	
	//for each column on the board check the row for a horizontal connect four
	for(int i = 0; i < RowsAndColumns[1].length; i++)
	{
		CheckColumnForConnectFour(rowvalue,columnvalue,playertwopieces);
		
		rowvalue = rowvalue + 100 ;
		
		columnvalue = 534;
	}
	
	
	
	
	
	
	
}

private void CheckForConnectFourDiagonal(){
	
	
	int rowvalue = 318;
	
	int columnvalue = 534;
	
	int originalrowvalue = 318;
	
	
	//finally do this for every column
	for(int index = 0; index < RowsAndColumns[0].length; index++ ){
		
		//for each row on the board check the next four diagonal 
		for(int i = 0; i < RowsAndColumns[1].length; i++)
		{
			CheckDiagonalSegment(rowvalue,columnvalue,playeronepieces);
		
			rowvalue = rowvalue + 100;
		}
		
		rowvalue = originalrowvalue;
		columnvalue -= 100;
		
	}
	
	
	rowvalue = 318;
	
	columnvalue = 534;
	
	originalrowvalue = 318;
	
	
	//finally do this for every column
	for(int index = 0; index < RowsAndColumns[0].length; index++ ){
		
		//for each row on the board check the next four diagonal 
		for(int i = 0; i < RowsAndColumns[1].length; i++)
		{
			CheckDiagonalSegment(rowvalue,columnvalue,playertwopieces);
		
			rowvalue = rowvalue + 100;
		}
		
		rowvalue = originalrowvalue;
		columnvalue -= 100;
		
	}
	
	

}



private void CheckRowForConnectFour(int rowvalue, int columnvalue, int[][] playerpieces){
	
	
	int consecutivepiecesinrow = 0;
	
	int nonmatchedpieces = 0;
			
	//for all the rows in this column 
	for(int index = 0; index < playerpieces[0].length; index++){ //go through the row
	
		//for all of the pieces check to see if one matches this spot on the grid
		for(int i = 0; i < playerpieces[0].length;i++)
		{
			//if both of these match this is a cell is occupied by a red peiece
			if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue )
			{
				//add to the counter
				consecutivepiecesinrow++;
				nonmatchedpieces = 0;
				break; //we found a piece here so break to the outer loop
				
			}
			
			else{ //if we found one add them to our counter otherwise if none of the items
				//match then it doesnt exist in this array
				
				nonmatchedpieces++;	
			}				
		}
		
		//if the red player has no piece on this cell
		if(nonmatchedpieces == playerpieces[0].length)
		{
			consecutivepiecesinrow = 0;
			nonmatchedpieces = 0;
		}
		
		
		//if we hit for matched then end the game
		if(consecutivepiecesinrow == 4){
			playersturnstring = "Game Over";
			gamefont.setColor(Color.RED);
			gameover = true;
			
		}

		//check the next cell
		rowvalue += 100;

	}
	
}

private void CheckColumnForConnectFour( int rowvalue, int columnvalue, int[][] playerpieces)
{
	
	int consecutivepiecesinrow = 0;
	
	int nonmatchedpieces = 0;
	
	//for all the rows in this column 
	for(int index = 0; index < RowsAndColumns[1].length; index++){ //go through the column
	
		//for all of the pieces check to see if one matches this spot on the grid
		for(int i = 0; i < playerpieces[1].length;i++)
		{
			//if both of these match this is a cell is occupied by a red peiece
			if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue )
			{
				//add to the counter
				consecutivepiecesinrow++;
				nonmatchedpieces = 0;
				break; //we found a piece here so break to the outer loop
				
			}
			
			else{ //if we found one add them to our counter otherwise if none of the items
				//match then it doesnt exist in this array
				
				nonmatchedpieces++;	
			}				
		}
		
		//if the red player has no piece on this cell
		if(nonmatchedpieces == playerpieces[0].length)
		{
			consecutivepiecesinrow = 0;
			nonmatchedpieces = 0;
		}
		
		
		//if we hit for matched then end the game
		if(consecutivepiecesinrow == 4){
			playersturnstring = "Game Over";
			gamefont.setColor(Color.RED);
			gameover = true;
			
		}

		//check the next cell
		columnvalue -= 100;

	}
	
	
	
	
}

private void CheckDiagonalSegment(int rowvalue, int columnvalue, int[][] playerpieces){
	
	CheckForForwardDiagonal(rowvalue,columnvalue,playerpieces);
	CheckForBackwardDiagonal(rowvalue,columnvalue,playerpieces);
	
}
	
private void CheckForForwardDiagonal(int rowvalue, int columnvalue,int[][] playerpieces){
	
	int consecutivepiecesinrow = 0;
	
	int nonmatchedpieces = 0;

	
	//check for four to the right
	for(int index = 0; index < RowsAndColumns[0].length; index++){ //for every square in the diagonal
	
		
		for(int i = 0; i < playeronepieces[0].length;i++) // for every player peice check for a red
		{
			
			//if both of these match this is a cell is occupied by a red peiece
			if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue )
			{
				//add to the counter
				consecutivepiecesinrow++;
				nonmatchedpieces = 0;
				break; //we found a piece here so break to the outer loop
				
			}
			
			else{ //if we found one add them to our counter otherwise if none of the items
				//match then it doesnt exist in this array
				
				nonmatchedpieces++;	
			}		
		}
		
		

		
		//if the red player has no piece on this cell 
		if(nonmatchedpieces == playerpieces[0].length)
		{
			consecutivepiecesinrow = 0;
			nonmatchedpieces = 0;
		}
		
		
		//if we hit for matched then end the game
		if(consecutivepiecesinrow == 4){
			playersturnstring = "Game Over";
			gamefont.setColor(Color.RED);
			gameover = true;
			
		}
		
		
		rowvalue += 100;
		columnvalue -= 100;
	
	}
	
	
}

public void CheckForBackwardDiagonal(int rowvalue, int columnvalue,int[][] playerpieces){
	
	
	int consecutivepiecesinrow = 0;
	
	int nonmatchedpieces = 0;

	
	//checks the diagonal to the left
	for(int index = 0; index < RowsAndColumns[0].length; index++){ //for every square in the diagonal
	
		
		for(int i = 0; i < playerpieces[0].length;i++) // for every player peice check for a red
		{
			
			//if both of these match this is a cell is occupied by a red peiece
			if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue )
			{
				//add to the counter
				consecutivepiecesinrow++;
				nonmatchedpieces = 0;
				break; //we found a piece here so break to the outer loop
				
			}
			
			else{ //if we found one add them to our counter otherwise if none of the items
				//match then it doesnt exist in this array
				
				nonmatchedpieces++;	
			}		
		}
		
		//if the red player has no piece on this cell 
		if(nonmatchedpieces == playerpieces[0].length)
		{
			consecutivepiecesinrow = 0;
			nonmatchedpieces = 0;
		}
		
		
		//if we hit for matched then end the game
		if(consecutivepiecesinrow == 4){
			playersturnstring = "Game Over";
			gamefont.setColor(Color.RED);
			gameover = true;
			
		}
		
		rowvalue -= 100;
		columnvalue -= 100;
	}
	
}



//checks if a piece is already in this position on the board
public boolean CheckIfPieceExists(int row,int column,int[][] playerpieces){
	
	//for all of the pieces check to see if one matches this spot on the grid
	for(int i = 0; i < playerpieces[0].length;i++)
	{
		//if both of these match this is a cell is occupied by a red peiece
		if(playerpieces[0][i] == row && playerpieces[1][i] == column )
		{
			//there is already a piece here
			return true;
		}					
	}
	return false;
	
}


@Override
public void resize(int arg0, int arg1) {
	// TODO Auto-generated method stub

}

@Override
public void resume() {
	// TODO Auto-generated method stub

}

@Override
public void show() {
	//set the processor to the new screen
	Gdx.input.setInputProcessor(gamestage);
	//render our game screen
	render(0);

}

2 个答案:

答案 0 :(得分:2)

问题与该行有关

font = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
             Gdx.files.internal("assets/font.png"), false);

从eclipse工作区启动应用程序时,文件搜索补丁(和类路径)的处理方式不同。

您安装的应用程序中不会导出(或不存在)字体。

1) 尝试将文件路径打印到控制台或调试应用程序。我假设文件根是不同的。

2) 字体未正确导出,必须添加到build.properties

答案 1 :(得分:0)

  

它在eclipe中运行良好但在导出时失败

正确的导出方式是:

  

档案 - &gt;出口 - &gt; Java - &gt; Runnable JAR文件。

务必检查:

  

将所需的库打包到Generated JAR中。

这样,您的资产将打包在jar中,并找到字体。