/*広告*/
/*ブロックパズルの作り方 中間ソース1*/
import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.animation.AnimationTimer; import javafx.scene.image.Image; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.paint.Color; public class B_PMain extends Application{ private B_PThread b_pthread; public static void main(String args[]){ launch(args); } @Override public void start(Stage stage){ stage.setTitle("BLOCK PUZZLE"); Pane pane = new Pane(); Scene scene = new Scene(pane); stage.setScene(scene); Canvas canvas = new Canvas(640,480); GraphicsContext gc = canvas.getGraphicsContext2D(); pane.getChildren().add(canvas); b_pthread = new B_PThread(gc); b_pthread.start(); stage.show(); } } class B_PThread extends AnimationTimer{ private GraphicsContext gc; private final int DRAW_POSITION_X = 0; private final int DRAW_POSITION_Y = 20; private final int BLOCK_HEIGHT = 4; private final int BLOCK_WIDTH = 4; private final int STAGE_HEIGHT = 23; private final int STAGE_WIDTH = 18; private final int DRAW_BLOCK_WIDTH = 20; private int block[][] = new int[BLOCK_HEIGHT][BLOCK_WIDTH]; private int stage[][] = new int[STAGE_HEIGHT][STAGE_WIDTH]; private int blocks[][] = { {0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0} }; private int block_x; private int block_y; private float block_y_count; private Image img; B_PThread(GraphicsContext gc){ this.gc = gc; Font theFont = Font.font("Serif",FontWeight.BOLD,25); gc.setFont(theFont); my_init_var(); } @Override public void handle(long time){ gc.clearRect(0,0,640,480); my_make_block(); my_draw_back(); my_draw_variable(); my_draw_block(); my_draw_stage(); } void my_init_var(){ for(int i=0;i<STAGE_HEIGHT;i++){ for(int j=0;j<STAGE_WIDTH;j++){ stage[i][0] = 9; stage[i][1] = 9; stage[i][2] = 9; stage[20][j] = 9; stage[21][j] = 9; stage[22][j] = 9; stage[i][15] = 9; stage[i][16] = 9; stage[i][17] = 9; } } block_x = 7; block_y = 0; block_y_count = 0; img = new Image("back_img.jpg"); } void my_make_block(){ for(int y=0;y<BLOCK_HEIGHT;y++){ for(int x=0;x<BLOCK_WIDTH;x++){ block[y][x] = blocks[y][x]; } } } void my_draw_back(){ gc.drawImage(img,0,0); } void my_draw_variable(){ gc.setFill(Color.WHITE); gc.fillText("block_x = " + block_x,400,400); gc.fillText("block_y = " + block_y,400,420); gc.fillText("block_y_count = " + block_y_count,400,440); } void my_draw_block(){ for(int y=0;y<BLOCK_HEIGHT;y++){ for(int x=0;x<BLOCK_WIDTH;x++){ if(block[y][x] == 1){gc.setFill(Color.RED); gc.fillText("■",block_x * DRAW_BLOCK_WIDTH + x * DRAW_BLOCK_WIDTH, DRAW_POSITION_Y + block_y_count + y * DRAW_BLOCK_WIDTH);} } } } void my_draw_stage(){ for(int y=0;y<STAGE_HEIGHT;y++){ for(int x=0;x<STAGE_WIDTH;x++){ if(stage[y][x] == 1){gc.setFill(Color.RED); gc.fillText("■",x * DRAW_BLOCK_WIDTH,DRAW_POSITION_Y + y * DRAW_BLOCK_WIDTH);} else if(stage[y][x] == 9){gc.setFill(Color.WHITE); gc.fillText("■",x * DRAW_BLOCK_WIDTH,DRAW_POSITION_Y + y * DRAW_BLOCK_WIDTH);} } } } }/*Copyright 2016 K.N/petitetech.com*/
/*広告*/