嘿,大家都非常感謝所有的幫助!我終於完成了這個項目,它在eclipse中運行良好,但是當我導出它時,我從堆棧跟蹤中得到這個錯誤,對於如何在體系結構方面可以改進的任何幫助都非常感謝。Java項目在ecipse中運行,但在導出時失敗
的例外是在線程異常 「LWJGL應用」 com.badlogic.gdx.utils.GdxRuntimeExcepti 上:com.badlogic.gdx.utils.GdxRuntimeException:未找到文件:資產\ font.fnt
它運行出口
public class ConnectFourApplication extends Game implements ApplicationListener {
\t
\t private Screen screen;
\t private Game game;
\t
\t public static void main(String[] args) {
\t \t
\t \t new LwjglApplication(new ConnectFourApplication(), "PennyPop", 1280, 720,
\t \t \t \t true); \t
\t }
\t public ConnectFourApplication(){
\t \t game = this;
\t }
\t
\t @Override
\t public void create() {
\t \t screen = new MainScreen(game);
\t \t setScreen(screen);
\t \t screen.show();
\t \t
\t }
\t
\t @Override
\t public void dispose() {
\t \t screen.hide();
\t \t screen.dispose();
\t \t
\t }
\t
\t /** Clears the screen with a white color */
\t private void clearWhite() {
\t \t Gdx.gl.glClearColor(1, 1, 1, 1);
\t \t Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
\t }
\t @Override
\t public void pause() {
\t \t screen.pause();
\t }
\t @Override
\t public void render() {
\t \t clearWhite();
\t \t super.render();
\t }
\t @Override
\t public void resize(int width, int height) {
\t \t screen.resize(width, height);
\t \t
\t }
\t @Override
\t public void resume() {
\t \t screen.resume();
\t }
public class MainScreen implements Screen {
\t
\t private final Stage stage;
\t private final SpriteBatch spriteBatch;
\t
\t //Parameter for drawing the buttons
\t private final BitmapFont font;
\t private final TextureAtlas buttons;
\t private final Button SFXButton;
\t private final Button APIButton;
\t private final Button GameButton;
\t private final Skin images;
\t
\t //Parameter for Sound
\t private final com.badlogic.gdx.audio.Sound SFXClick;
\t
\t //Parameter for the api call
\t private final String WeatherUrl;
\t private final HttpRequest request;
\t private final City SanFrancisco;
\t
\t //The screen to load after the game button is hit
\t private Screen gamescreen;
\t
\t private Game game;
\t
\t
\t
\t public MainScreen(Game game) {
\t \t
\t \t this.game = game;
\t \t
\t \t //Set up our assets
\t \t spriteBatch = new SpriteBatch();
\t \t stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, spriteBatch);
\t
\t \t font = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
\t \t Gdx.files.internal("assets/font.png"), false);
\t \t \t
\t \t buttons = new TextureAtlas("assets/GameButtons.pack");
\t \t images = new Skin(buttons);
\t \t images.addRegions(buttons);
\t \t SFXButton = new Button(images.getDrawable("sfxButton"));
\t \t SFXButton.setPosition(295, 310);
\t \t APIButton = new Button(images.getDrawable("apiButton"));
\t \t APIButton.setPosition(405, 310);
\t \t GameButton = new Button(images.getDrawable("gameButton"));
\t \t GameButton.setPosition(515, 310);
\t \t SFXClick = Gdx.audio.newSound(Gdx.files.internal("assets/button_click.wav"));
\t \t
\t \t //Add our actors to the stage
\t \t stage.addActor(SFXButton);
\t \t stage.addActor(APIButton);
\t \t stage.addActor(GameButton);
\t \t
\t \t //Set up our Url request to be used when clicking the button
\t \t WeatherUrl = "http://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,US";
\t \t request = new HttpRequest(HttpMethods.GET);
\t \t request.setUrl(WeatherUrl);
\t \t SanFrancisco = new City("Unavailable","Unavailable","0","0"); //init san fran to be displayed before they have clicked the button
\t \t
\t }
\t @Override
\t public void dispose() {
\t \t spriteBatch.dispose();
\t \t stage.dispose();
\t }
\t @Override
\t public void render(float delta) {
\t \t stage.act(delta);
\t \t stage.draw();
\t \t
\t \t //Begin sprite batch
\t \t spriteBatch.begin();
\t \t
\t \t //Set our on click listeners for our buttons
\t \t if (SFXButton.isPressed())
\t \t \t SFXClick.play();
\t \t
\t \t if(APIButton.isPressed())
\t \t {
\t \t \t CallApi();
\t \t }
\t \t \t
\t \t if(GameButton.isPressed())
\t \t \t LoadGame();
\t \t
\t \t
\t \t //Set font color and render the screen
\t \t font.setColor(Color.RED);
\t \t font.draw(spriteBatch, "PennyPop", 455 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 460 + font.getBounds("PennyPop").height/2);
\t \t
\t \t font.setColor(Color.BLACK);
\t \t font.draw(spriteBatch, "Current Weather", 900 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 460 + font.getBounds("PennyPop").height/2);
\t \t
\t \t font.setColor(Color.LIGHT_GRAY);
\t \t font.draw(spriteBatch, SanFrancisco.Name, 940 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 420 + font.getBounds("PennyPop").height/2);
\t \t
\t \t
\t \t font.setColor(Color.RED);
\t \t font.draw(spriteBatch, SanFrancisco.CurrentCondition, 950 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 300 + font.getBounds("PennyPop").height/2);
\t \t
\t \t
\t \t font.draw(spriteBatch, SanFrancisco.Temperature + " Degrees,", 920 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 270 + font.getBounds("PennyPop").height/2);
\t \t
\t \t font.draw(spriteBatch, SanFrancisco.WindSpeed, 1200 - font.getBounds("PennpyPop").width/2,
\t \t \t \t 270 + font.getBounds("PennyPop").height/2);
\t \t
\t \t
\t \t
\t \t //End or sprite batch
\t \t spriteBatch.end();
\t \t
\t
\t }
\t
\t //Handles calling our API
\t public void CallApi(){
\t \t
\t \t //Sends our stored HTTPRequest object
\t \t Gdx.net.sendHttpRequest(request, new HttpResponseListener() {
\t \t \t @Override
\t \t \t public void handleHttpResponse(HttpResponse httpResponse) {
\t \t \t \t
\t \t \t \t //Uses our private response reader object to give us a the JSON from the api call
\t \t \t \t JSONObject json = HttpResponseReader(httpResponse);
\t \t \t \t
\t \t \t \t //Gets the name of the city
\t \t \t \t SanFrancisco.Name = (String) json.get("name"); \t \t
\t \t \t \t //Parsed through our returned JSON for the weather key
\t \t \t \t JSONArray WeatherArray = (JSONArray) json.get("weather");
\t \t \t \t //Gets the actual weather dictionary
\t \t \t \t JSONObject Weather = (JSONObject) WeatherArray.get(0);
\t \t \t \t //Finally get the value with the key of description and assign it
\t \t \t \t //To the San Fran current conditions field
\t \t \t \t SanFrancisco.CurrentCondition = (String) Weather.get("description");
\t \t \t \t
\t \t \t \t
\t \t \t \t //Gets the actual main dictionary
\t \t \t \t JSONObject main = (JSONObject) json.get("main"); \t \t \t
\t \t \t \t //Finally get the values based on the keys
\t \t \t \t SanFrancisco.Temperature = (String) Double.toString((double) main.get("temp"));
\t \t \t
\t \t \t \t //Finally get the wind speed
\t \t \t \t JSONObject wind = (JSONObject) json.get("wind"); \t
\t \t \t \t SanFrancisco.WindSpeed = (String) Double.toString((double) wind.get("speed"));
\t \t \t \t
\t \t \t }
\t \t \t
@Override
public void failed(Throwable t) {
Gdx.app.log("Failed ", t.getMessage());
}
\t \t });
\t }
\t
\t //When the button game button is clicked should load the connect four game
\t public void LoadGame(){
\t \t
\t \t game.setScreen(new GameScreen(game));
\t \t
\t }
\t
\t
\t
\t //Converts our HttpResponse into a JSON OBject
\t private static JSONObject HttpResponseReader(HttpResponse httpResponse){
\t \t
\t BufferedReader read = new BufferedReader(new InputStreamReader(httpResponse.getResultAsStream()));
StringBuffer result = new StringBuffer();
String line = "";
try {
\t while ((line = read.readLine()) != null) {
\t \t \t result.append(line);
\t \t \t }
\t
\t \t JSONObject json;
\t \t \t try {
\t \t \t \t json = (JSONObject)new JSONParser().parse(result.toString());
\t \t \t \t return json;
\t \t \t } catch (ParseException e) {
\t \t \t \t e.printStackTrace();
\t \t \t }
\t \t
\t \t } catch (IOException e) {
\t \t \t e.printStackTrace();
\t \t }
return null;
\t }
\t @Override
\t public void resize(int width, int height) {
\t \t stage.setViewport(width, height, false);
\t }
\t @Override
\t public void hide() {
\t \t Gdx.input.setInputProcessor(null);
\t }
\t @Override
\t public void show() {
\t \t Gdx.input.setInputProcessor(stage);
\t \t render(0);
\t }
\t @Override
\t public void pause() {
\t \t // Irrelevant on desktop, ignore this
\t }
\t @Override
\t public void resume() {
\t \t // Irrelevant on desktop, ignore this
\t }
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;
\t
//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;
\t
private Game game;
public boolean gameover;
private boolean isready;
private int[][] RowsAndColumns;
private int columnvalue = 538;
public GameScreen(Game game){
\t
\t this.game = game;
\t
\t //Set up our assets
\t gamesprites = new SpriteBatch();
\t gamestage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, gamesprites);
\t
\t //Sets up our font
\t gamefont = new BitmapFont(Gdx.files.internal("assets/font.fnt"),
\t Gdx.files.internal("assets/font.png"), false);
\t
\t pieces = new TextureAtlas("assets/GameButtons.pack");
\t piecesskin = new Skin(pieces);
\t piecesskin.addRegions(pieces);
\t
\t //set up our camera
camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();
\t
\t
//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);
\t //setup the board
SetUpGameBoard(8,4,Color.BLACK);
linestartx = 300;
linestarty = 100;
lineendx = 300;
lineendy = 600;
linexdistance = 100;
lineydistance = 100;
\t
\t //setup the pieces
numberofpiecesperplayer = 60;
\t
\t //initialize anything else we need for the game
\t playersturnstring = "";
\t
\t //start with player one's turn
\t playersturn = 0;
\t //setup or pieces locations as blank
\t playeronepieces = new int[2][numberofpiecesperplayer]; //create two arrays one for x values one for y
\t
\t playeronepieceindex = 0;
\t
\t playertwopieces = new int[2][numberofpiecesperplayer]; //create two arrays one for x values one for y
\t
\t playertwopieceindex = 0;
\t
\t gameover = false;
\t
\t isready = false;
\t
\t linestowin = 4;
\t
\t
}
//Should initialize our game board
public void SetUpGameBoard(int boardsize,int linestowin, Color linecolor){
\t
\t this.boardsize = boardsize;
\t this.linestowin = linestowin;
\t boardlineshape = new ShapeRenderer();
\t boardlineshape.setProjectionMatrix(camera.combined);
\t boardlineshape.setColor(linecolor);
\t
\t //holds the board cells
\t RowsAndColumns = new int[2][(int) boardsize];
}
@Override
public void dispose() {
\t // TODO Auto-generated method stub
}
@Override
public void hide() {
\t Gdx.input.setInputProcessor(null);
}
@Override
public void pause() {
\t // TODO Auto-generated method stub
}
@Override
public void render(float delta) {
\t
\t //set the stage
\t gamestage.act(delta);
\t gamestage.draw();
\t
\t
\t //if the mouse is clicked and the game is not over send us back to the main screen
\t if (Gdx.input.justTouched() && gameover == true){
\t \t
\t \t //if the game is over and the user clicks send us back to the main screen
\t \t game.setScreen(new MainScreen(game)); \t
\t } \t \t
\t
\t
\t if(isready){ \t
\t \t //if the mouse is clicked and the game is not over add a piece to player one
\t \t if (Gdx.input.justTouched() && gameover != true){
\t \t \t \t
\t \t \t AddPiece(Gdx.input.getX(), Gdx.input.getY());
\t \t }
\t }
\t //Draw our board
\t boardlineshape.begin(ShapeType.Line);
\t
\t ///Draw all of the lines for our board
\t DrawBoard(linestartx,linestarty,lineendx,lineendy);
\t
\t boardlineshape.end();
\t //Starts our game sprite batch
\t gamesprites.begin();
\t //Draw all of player ones pieces
\t DrawPlayerOnePieces();
\t
\t //Draw all of player twos pieces
\t DrawPlayerTwoPieces();
\t
\t gamefont.draw(gamesprites, playersturnstring, 515, 650);
\t
\t //End our game sprite batch
\t gamesprites.end();
\t
\t //Lastly check to make sure our the game is not over
\t CheckForGameOver();
\t
\t isready = true;
\t
\t
}
\t
//draw the board
private void DrawBoard(int linestartx, int linestarty, int lineendx, int lineendy){
\t
\t camera.update();
\t boardlineshape.setProjectionMatrix(camera.combined); \t
\t
\t //For each line in our board draw a line
\t for(int i =0; i < boardsize; i++)
\t {
\t \t //first we will draw the vertical lines then we will change to the horizontal lines
\t \t
\t \t boardlineshape.line(linestartx, linestarty,lineendx, lineendy);
\t \t
\t \t //if the x value exceeds a certian amount then change to the horizontal lines
\t \t
\t \t //increment the start x position to draw another line
\t \t linestartx += linexdistance;
\t \t lineendx += lineydistance;
\t \t
\t \t //if the x start is over 1200 we have drawn the last vertical line so switch to th
\t \t //horizontal lines
\t \t if(linestartx > 1000)
\t \t {
\t \t \t
\t \t \t //set our x values and render our horizontal lines
\t \t \t lineendx = linestartx - linexdistance;
\t \t \t linestartx = this.linestartx;
\t \t \t
\t \t \t linestarty = this.linestarty;
\t \t \t lineendy = this.linestarty;
\t \t \t
\t \t \t for(int index =0; index < boardsize -2; index++){
\t \t \t \t
\t \t \t \t //increment the start y position to draw another line
\t \t \t \t boardlineshape.line(linestartx, linestarty,lineendx, lineendy);
\t \t \t \t
\t \t \t \t linestarty += lineydistance;
\t \t \t \t lineendy += lineydistance;
\t \t \t \t
\t \t \t \t
\t \t
\t \t \t }
\t \t }
\t \t
\t }
}
//Draws all the current pieces for player one
private void DrawPlayerOnePieces(){
\t
\t //For all of player one's pieces
\t for(int i = 0; i < playeronepieces[1].length;i++)
\t {
\t \t //of its not an empty piece draw it
\t \t if(playeronepieces[0][i] != 0){
\t \t \t
\t \t \t gamesprites.draw(redtexture, playeronepieces[0][i], playeronepieces[1][i]);
\t \t }
\t \t
\t }
\t
}
//Draws all the current pieces for player two
private void DrawPlayerTwoPieces(){
\t
\t //For all of player two's pieces
\t for(int i = 0; i < playertwopieces[1].length;i++)
\t {
\t \t //of its not an empty piece draw it
\t \t if(playertwopieces[0][i] != 0){
\t \t \t
\t \t \t gamesprites.draw(yellowtexture, playertwopieces[0][i], playertwopieces[1][i]);
\t \t }
\t \t
\t }
\t
}
//Adds a piece to whichever players current turn it is
private void AddPiece(int clickx, int clicky){
\t
\t RestPlayersTurn(playersturn);
\t
\t int computedx = GetComputedX(clickx,linestartx);
\t
\t int computedy = GetComputedY(clicky,linestarty);
\t
\t
\t if(playeronepieceindex != 60)
\t {
\t \t //makes sure they are clicking inside our board and that there is not already a piece on that part of the board
\t \t if(
\t \t \t \t (clickx > linestartx && clickx < linestartx + ((boardsize - 1) * linexdistance))&&
\t \t \t \t (clicky > linestarty && clicky < lineendy)&&
\t \t \t \t (CheckIfPieceExists(computedx,computedy,playeronepieces) == false) &&
\t \t \t \t (CheckIfPieceExists(computedx,computedy,playertwopieces) == false)
\t \t )
\t \t {
\t \t \t if(playersturn == 0)
\t \t \t {
\t \t \t \t playeronepieces[0][playeronepieceindex] = computedx; //set the x value
\t \t \t \t \t \t \t \t \t
\t \t \t \t playeronepieces[1][playeronepieceindex] = 700 - computedy; //set the y value
\t \t \t \t
\t \t \t \t playeronepieceindex++;
\t \t \t \t
\t \t \t \t playersturnstring = "Player Two's turn";
\t \t \t \t
\t \t \t \t gamefont.setColor(Color.YELLOW);
\t \t \t
\t \t \t }
\t \t \t else if(playersturn == 1)
\t \t \t {
\t \t \t \t
\t \t \t \t playertwopieces[0][playertwopieceindex] = computedx; //set the x value
\t \t \t \t
\t \t \t \t playertwopieces[1][playertwopieceindex] = 700 - computedy; //set the y value
\t \t \t \t
\t \t \t \t playertwopieceindex++;
\t \t \t \t playersturnstring = "Player One's turn";
\t \t \t \t
\t \t \t \t gamefont.setColor(Color.RED);
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t //every time we add a piece change the players turn
\t \t \t playersturn++;
\t \t \t
\t \t } \t \t \t
\t }
}
//puts our x value in the center of its cell
public int GetComputedX(int touchx, int linestartx){
\t
\t //compute our x depending on the nearest line
\t int lineendx = linestartx + linexdistance;
\t
\t //for the images width
\t int imagewidth = redtexture.getWidth();
\t
\t for(int i = 0; i < boardsize; i++)
\t {
\t \t //if the touched x is in this range than assign the computed x value to
\t \t //half the cell \t
\t \t if(touchx > linestartx && touchx < lineendx){
\t \t \t
\t \t \t touchx = (lineendx - (linexdistance/2)) - (imagewidth/2);
\t \t \t break;
\t \t } \t
\t \t
\t \t linestartx += linexdistance;
\t \t lineendx += linexdistance;
\t }
\t
\t return touchx;
}
//puts our y value in the center of the cell
public int GetComputedY(int touchy, int linestarty)
{
\t //compute our x depending on the nearest line
\t int lineendy = linestarty + lineydistance;
\t
\t //for the images width
\t int imageheight = redtexture.getHeight();
\t
\t //computer our x depending on the nearest line
\t for(int i =0; i < boardsize; i++)
\t {
\t \t //if the touched x is in this range than assign the computed x value to
\t \t //half the cell \t
\t \t if(touchy > linestarty && touchy < lineendy){
\t \t \t touchy = ((lineendy - (lineydistance/2)) + (imageheight/4));
\t \t \t break;
\t \t }
\t \t
\t \t linestarty += lineydistance;
\t \t lineendy += lineydistance; \t
\t }
\t
\t return touchy;
}
//Sets the next players turn
private void RestPlayersTurn(int playerturn){
\t
\t if(playerturn == 2){
\t \t
\t \t playersturn = 0;
\t \t \t
\t }
\t
}
//check for game over
private void CheckForGameOver(){
\t \t \t
\t //check if player one has a connect four
\t CheckForConnectFourHorizontal();
\t CheckForConnectFourVertical();
\t CheckForConnectFourDiagonal();
\t
}
\t
private void CheckForConnectFourHorizontal(){
\t int rowvalue = 318;
\t
\t int columnvalue = 534;
\t
\t
\t //for each column on the board check the row for a horizontal connect four for player one
\t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t {
\t \t CheckRowForConnectFour(rowvalue,columnvalue,playeronepieces);
\t \t
\t \t rowvalue = 318;
\t \t
\t \t columnvalue = columnvalue - 100;
\t }
\t
rowvalue = 318;
\t
\t columnvalue = 534;
\t
\t
\t
\t //for each column on the board check the row for a horizontal connect four for player two
\t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t {
\t \t CheckRowForConnectFour(rowvalue,columnvalue,playertwopieces);
\t \t
\t \t rowvalue = 318;
\t \t
\t \t columnvalue = columnvalue - 100;
\t }
\t
}
private void CheckForConnectFourVertical(){
\t
\t
\t int rowvalue = 318;
\t
\t int columnvalue = 534;
\t
\t //for each column on the board check the row for a horizontal connect four
\t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t {
\t \t CheckColumnForConnectFour(rowvalue,columnvalue,playeronepieces);
\t \t
\t \t rowvalue = rowvalue + 100 ;
\t \t
\t \t columnvalue = 534;
\t }
\t
\t
\t
\t rowvalue = 318;
\t
\t columnvalue = 534;
\t
\t //for each column on the board check the row for a horizontal connect four
\t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t {
\t \t CheckColumnForConnectFour(rowvalue,columnvalue,playertwopieces);
\t \t
\t \t rowvalue = rowvalue + 100 ;
\t \t
\t \t columnvalue = 534;
\t }
\t
\t
\t
\t
\t
\t
\t
}
private void CheckForConnectFourDiagonal(){
\t
\t
\t int rowvalue = 318;
\t
\t int columnvalue = 534;
\t
\t int originalrowvalue = 318;
\t
\t
\t //finally do this for every column
\t for(int index = 0; index < RowsAndColumns[0].length; index++){
\t \t
\t \t //for each row on the board check the next four diagonal
\t \t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t \t {
\t \t \t CheckDiagonalSegment(rowvalue,columnvalue,playeronepieces);
\t \t
\t \t \t rowvalue = rowvalue + 100;
\t \t }
\t \t
\t \t rowvalue = originalrowvalue;
\t \t columnvalue -= 100;
\t \t
\t }
\t
\t
\t rowvalue = 318;
\t
\t columnvalue = 534;
\t
\t originalrowvalue = 318;
\t
\t
\t //finally do this for every column
\t for(int index = 0; index < RowsAndColumns[0].length; index++){
\t \t
\t \t //for each row on the board check the next four diagonal
\t \t for(int i = 0; i < RowsAndColumns[1].length; i++)
\t \t {
\t \t \t CheckDiagonalSegment(rowvalue,columnvalue,playertwopieces);
\t \t
\t \t \t rowvalue = rowvalue + 100;
\t \t }
\t \t
\t \t rowvalue = originalrowvalue;
\t \t columnvalue -= 100;
\t \t
\t }
\t
\t
}
private void CheckRowForConnectFour(int rowvalue, int columnvalue, int[][] playerpieces){
\t
\t
\t int consecutivepiecesinrow = 0;
\t
\t int nonmatchedpieces = 0;
\t \t \t
\t //for all the rows in this column
\t for(int index = 0; index < playerpieces[0].length; index++){ //go through the row
\t
\t \t //for all of the pieces check to see if one matches this spot on the grid
\t \t for(int i = 0; i < playerpieces[0].length;i++)
\t \t {
\t \t \t //if both of these match this is a cell is occupied by a red peiece
\t \t \t if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue)
\t \t \t {
\t \t \t \t //add to the counter
\t \t \t \t consecutivepiecesinrow++;
\t \t \t \t nonmatchedpieces = 0;
\t \t \t \t break; //we found a piece here so break to the outer loop
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t else{ //if we found one add them to our counter otherwise if none of the items
\t \t \t \t //match then it doesnt exist in this array
\t \t \t \t
\t \t \t \t nonmatchedpieces++; \t
\t \t \t } \t \t \t \t
\t \t }
\t \t
\t \t //if the red player has no piece on this cell
\t \t if(nonmatchedpieces == playerpieces[0].length)
\t \t {
\t \t \t consecutivepiecesinrow = 0;
\t \t \t nonmatchedpieces = 0;
\t \t }
\t \t
\t \t
\t \t //if we hit for matched then end the game
\t \t if(consecutivepiecesinrow == 4){
\t \t \t playersturnstring = "Game Over";
\t \t \t gamefont.setColor(Color.RED);
\t \t \t gameover = true;
\t \t \t
\t \t }
\t \t //check the next cell
\t \t rowvalue += 100;
\t }
\t
}
private void CheckColumnForConnectFour(int rowvalue, int columnvalue, int[][] playerpieces)
{
\t
\t int consecutivepiecesinrow = 0;
\t
\t int nonmatchedpieces = 0;
\t
\t //for all the rows in this column
\t for(int index = 0; index < RowsAndColumns[1].length; index++){ //go through the column
\t
\t \t //for all of the pieces check to see if one matches this spot on the grid
\t \t for(int i = 0; i < playerpieces[1].length;i++)
\t \t {
\t \t \t //if both of these match this is a cell is occupied by a red peiece
\t \t \t if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue)
\t \t \t {
\t \t \t \t //add to the counter
\t \t \t \t consecutivepiecesinrow++;
\t \t \t \t nonmatchedpieces = 0;
\t \t \t \t break; //we found a piece here so break to the outer loop
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t else{ //if we found one add them to our counter otherwise if none of the items
\t \t \t \t //match then it doesnt exist in this array
\t \t \t \t
\t \t \t \t nonmatchedpieces++; \t
\t \t \t } \t \t \t \t
\t \t }
\t \t
\t \t //if the red player has no piece on this cell
\t \t if(nonmatchedpieces == playerpieces[0].length)
\t \t {
\t \t \t consecutivepiecesinrow = 0;
\t \t \t nonmatchedpieces = 0;
\t \t }
\t \t
\t \t
\t \t //if we hit for matched then end the game
\t \t if(consecutivepiecesinrow == 4){
\t \t \t playersturnstring = "Game Over";
\t \t \t gamefont.setColor(Color.RED);
\t \t \t gameover = true;
\t \t \t
\t \t }
\t \t //check the next cell
\t \t columnvalue -= 100;
\t }
\t
\t
\t
\t
}
private void CheckDiagonalSegment(int rowvalue, int columnvalue, int[][] playerpieces){
\t
\t CheckForForwardDiagonal(rowvalue,columnvalue,playerpieces);
\t CheckForBackwardDiagonal(rowvalue,columnvalue,playerpieces);
\t
}
\t
private void CheckForForwardDiagonal(int rowvalue, int columnvalue,int[][] playerpieces){
\t
\t int consecutivepiecesinrow = 0;
\t
\t int nonmatchedpieces = 0;
\t
\t //check for four to the right
\t for(int index = 0; index < RowsAndColumns[0].length; index++){ //for every square in the diagonal
\t
\t \t
\t \t for(int i = 0; i < playeronepieces[0].length;i++) // for every player peice check for a red
\t \t {
\t \t \t
\t \t \t //if both of these match this is a cell is occupied by a red peiece
\t \t \t if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue)
\t \t \t {
\t \t \t \t //add to the counter
\t \t \t \t consecutivepiecesinrow++;
\t \t \t \t nonmatchedpieces = 0;
\t \t \t \t break; //we found a piece here so break to the outer loop
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t else{ //if we found one add them to our counter otherwise if none of the items
\t \t \t \t //match then it doesnt exist in this array
\t \t \t \t
\t \t \t \t nonmatchedpieces++; \t
\t \t \t } \t \t
\t \t }
\t \t
\t \t
\t \t
\t \t //if the red player has no piece on this cell
\t \t if(nonmatchedpieces == playerpieces[0].length)
\t \t {
\t \t \t consecutivepiecesinrow = 0;
\t \t \t nonmatchedpieces = 0;
\t \t }
\t \t
\t \t
\t \t //if we hit for matched then end the game
\t \t if(consecutivepiecesinrow == 4){
\t \t \t playersturnstring = "Game Over";
\t \t \t gamefont.setColor(Color.RED);
\t \t \t gameover = true;
\t \t \t
\t \t }
\t \t
\t \t
\t \t rowvalue += 100;
\t \t columnvalue -= 100;
\t
\t }
\t
\t
}
public void CheckForBackwardDiagonal(int rowvalue, int columnvalue,int[][] playerpieces){
\t
\t
\t int consecutivepiecesinrow = 0;
\t
\t int nonmatchedpieces = 0;
\t
\t //checks the diagonal to the left
\t for(int index = 0; index < RowsAndColumns[0].length; index++){ //for every square in the diagonal
\t
\t \t
\t \t for(int i = 0; i < playerpieces[0].length;i++) // for every player peice check for a red
\t \t {
\t \t \t
\t \t \t //if both of these match this is a cell is occupied by a red peiece
\t \t \t if(playerpieces[0][i] == rowvalue && playerpieces[1][i] == columnvalue)
\t \t \t {
\t \t \t \t //add to the counter
\t \t \t \t consecutivepiecesinrow++;
\t \t \t \t nonmatchedpieces = 0;
\t \t \t \t break; //we found a piece here so break to the outer loop
\t \t \t \t
\t \t \t }
\t \t \t
\t \t \t else{ //if we found one add them to our counter otherwise if none of the items
\t \t \t \t //match then it doesnt exist in this array
\t \t \t \t
\t \t \t \t nonmatchedpieces++; \t
\t \t \t } \t \t
\t \t }
\t \t
\t \t //if the red player has no piece on this cell
\t \t if(nonmatchedpieces == playerpieces[0].length)
\t \t {
\t \t \t consecutivepiecesinrow = 0;
\t \t \t nonmatchedpieces = 0;
\t \t }
\t \t
\t \t
\t \t //if we hit for matched then end the game
\t \t if(consecutivepiecesinrow == 4){
\t \t \t playersturnstring = "Game Over";
\t \t \t gamefont.setColor(Color.RED);
\t \t \t gameover = true;
\t \t \t
\t \t }
\t \t
\t \t rowvalue -= 100;
\t \t columnvalue -= 100;
\t }
\t
}
//checks if a piece is already in this position on the board
public boolean CheckIfPieceExists(int row,int column,int[][] playerpieces){
\t
\t //for all of the pieces check to see if one matches this spot on the grid
\t for(int i = 0; i < playerpieces[0].length;i++)
\t {
\t \t //if both of these match this is a cell is occupied by a red peiece
\t \t if(playerpieces[0][i] == row && playerpieces[1][i] == column)
\t \t {
\t \t \t //there is already a piece here
\t \t \t return true;
\t \t } \t \t \t \t \t
\t }
\t return false;
\t
}
@Override
public void resize(int arg0, int arg1) {
\t // TODO Auto-generated method stub
}
@Override
public void resume() {
\t // TODO Auto-generated method stub
}
@Override
public void show() {
\t //set the processor to the new screen
\t Gdx.input.setInputProcessor(gamestage);
\t //render our game screen
\t render(0);
}
我在哪裏可以找到錯誤消息? – 2014-09-19 06:15:07
對不起,只是編輯它應該顯示在頂部的錯誤消息現在 – 2014-09-19 06:17:09