当前位置: 首页 > news >正文

深圳专业做网站专业全国建筑企业资质查询平台下载

深圳专业做网站专业,全国建筑企业资质查询平台下载,北京国贸网站建设公司,搜索引擎排名优化seo规则 1.方块会从上方缓慢下落#xff0c;玩家可以通过键盘上的上下左右键来控制方块。 2.方块移到区域最下方或是着地到其他方块上无法移动时#xff0c;就会固定在该处#xff0c;而新的方块出现在区域上方开始落下。 3.当区域中某一列横向格子全部由方块填满#xff0c;…规则 1.方块会从上方缓慢下落玩家可以通过键盘上的上下左右键来控制方块。 2.方块移到区域最下方或是着地到其他方块上无法移动时就会固定在该处而新的方块出现在区域上方开始落下。 3.当区域中某一列横向格子全部由方块填满则该列会消失并成为玩家的得分。同时删除的列数越多得分指数上升。 4.当固定的方块堆到区域最上方而无法消除层数时或者大于游戏区域时则游戏结束。 代码目录  实现代码 import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException;//俄罗斯方块主类 public class Tetris extends JPanel {static int ROW 18;static int COL 9;//声明正在下落的方块private Tetromino currentOne Tetromino.randomOne();//声明将要下落的方块private Tetromino nextOne Tetromino.randomOne();//声明游戏主区域private Cell[][] wall new Cell[ROW][COL];//声明单元格像素为48像素private static final int CELL_SIZE 48;//游戏分数池int[] scores_pool {0, 1, 2, 5, 10};//游戏总分private int totalScore 0;//游戏消除总行数private int totalLine 0;//游戏的状态游戏中游戏暂停游戏结束private static final int PLAYING 0;private static final int PAUSE 1;private static final int GAMEOVER 2;//声明变量来存放当前游戏状态private int game_state;//数组显示当前游戏状态String[] show_state {P[暂停],C[继续],R[重开]};//静态载入图片public static BufferedImage I;public static BufferedImage J;public static BufferedImage L;public static BufferedImage O;public static BufferedImage S;public static BufferedImage T;public static BufferedImage Z;public static BufferedImage backImage;static {try {I ImageIO.read(new File(images/I.png));J ImageIO.read(new File(images/J.png));L ImageIO.read(new File(images/L.png));O ImageIO.read(new File(images/O.png));S ImageIO.read(new File(images/S.png));T ImageIO.read(new File(images/T.png));Z ImageIO.read(new File(images/Z.png));backImage ImageIO.read(new File(images/background.png));} catch (IOException e) {e.printStackTrace();}}Overridepublic void paint(Graphics g) {g.drawImage(backImage,0,0,null);//平移坐标轴g.translate(22,15);//绘制游戏主区域paintWall(g);//绘制正在下落的四方格paintCurrentOne(g);//绘制下一个下落的四方格paintNextOne(g);//绘制游戏得分paintScore(g);//绘制游戏当前状态paintState(g);}//start 方法用于调用游戏操作逻辑并监听键盘和描述游戏主要逻辑public void start() {game_state PLAYING;KeyListener listener new KeyAdapter() {Overridepublic void keyPressed(KeyEvent e) {int code e.getKeyCode();switch (code) {case KeyEvent.VK_DOWN: //↓sortDropAction(); //下落一格break;case KeyEvent.VK_LEFT://←moveLeftAction(); //左移一格break;case KeyEvent.VK_RIGHT: //→moveRightAction(); //右移一格break;case KeyEvent.VK_UP://↑rotateRightAction();//顺时针旋转break;case KeyEvent.VK_SPACE://空格handDropAction();//瞬间下落break;case KeyEvent.VK_P: //p//判断游戏是否在运行,没有才能暂停if (game_state PLAYING) {game_state PAUSE;}break;case KeyEvent.VK_C://游戏暂停后才能继续if (game_state PAUSE) {game_state PLAYING;}break;case KeyEvent.VK_R://重新开始游戏把游戏状态变为正在游戏game_state PLAYING;//界面清空wall new Cell[ROW][COL];currentOne Tetromino.randomOne();nextOne Tetromino.randomOne();//数据清空totalLine 0;totalScore 0;break;}}};//把俄罗斯方块窗口设置为焦点this.addKeyListener(listener);this.requestFocus();while(true){//判断当前游戏状态在游戏中时每隔0.5秒下落if(game_state PLAYING){try {Thread.sleep(700);} catch (InterruptedException e) {e.printStackTrace();}//判断能否下落if(canDrop()){currentOne.softDrop();}else{//嵌入到墙中landToWall();//判断能否消行destroyLine();//判断游戏是否结束if(isGameOver()){game_state GAMEOVER;}else{currentOne nextOne;nextOne Tetromino.randomOne();}}}//重新绘制repaint();}}//顺时针旋转public void rotateRightAction() {currentOne.rotateRight();//判断是否越界或者重合否则恢复原来的状态if (outOfBounds() || coincide()) {currentOne.rotateLeft();}}//瞬间下落public void handDropAction() {while (canDrop()) {currentOne.softDrop();}//把四方格嵌入墙中landToWall();//判断能否销行destroyLine();//判断游戏是否结束if (isGameOver()) {game_state GAMEOVER;} else {//继续生成四方格currentOne nextOne;nextOne Tetromino.randomOne();}}//按键一次四方格下落一个public void sortDropAction() {//判断能否下落if (canDrop()) {//当前四方格下落一格currentOne.softDrop();} else {//把四方格嵌入墙中landToWall();//判断能否销行destroyLine();//判断游戏是否结束if (isGameOver()) {game_state GAMEOVER;} else {//继续生成四方格currentOne nextOne;nextOne Tetromino.randomOne();}}}//把四方格嵌入墙中private void landToWall() {Cell[] cells currentOne.cells;for (Cell cell : cells) {int row cell.getRow();int col cell.getCol();wall[row][col] cell;}}//判断四方格能否下落public boolean canDrop() {Cell[] cells currentOne.cells;for (Cell cell : cells) {int row cell.getRow();int col cell.getCol();//判断能否全部到达底部if (row wall.length - 1) {return false;} else if(wall[row 1][col] ! null) { //判断该位置是否有方块return false;}}return true;}//创建销行方法public void destroyLine() {//统计当前形参行数int line 0;Cell[] cells currentOne.cells;for (Cell cell : cells) {int row cell.getRow();//判断当前行是否满if (isFullLine(row)) {line;//将消除行以上的方块下落到对应行数for (int i row; i 0; i--) {System.arraycopy(wall[i - 1],0,wall[i],0,wall[0].length);}//重新创造第一行wall[0] new Cell[9];}}//更新分数totalScore scores_pool[line];//更新消除行数totalLine line;}//判断当前行是否满,满返回true没有满返回falsepublic boolean isFullLine(int row) {Cell[] cells wall[row];for (Cell cell : cells) {if (cell null) {return false;}}return true;}//判断游戏是否结束,结束返回true继续返回falsepublic boolean isGameOver() {Cell[] cells nextOne.cells;for (Cell cell : cells) {int row cell.getRow();int col cell.getCol();if (wall[row][col] ! null) {return true;}}return false;}//按键←触发左移public void moveLeftAction() {currentOne.moveLeft();//判断是否越界或者重合如果是则右移恢复原来的状态不是则左移if (outOfBounds() || coincide()) {currentOne.moveRight();}}//按键→触发右移public void moveRightAction() {currentOne.moveRight();//判断是否越界或者重合如果是则左移恢复原来的状态不是则右移if (outOfBounds() || coincide()) {currentOne.moveLeft();}}//判断方块是否重合,重合返回true没有返回falsepublic boolean coincide() {Cell[] cells currentOne.cells;for (Cell cell : cells) {int col cell.getCol();int row cell.getRow();if (wall[row][col] ! null) {return true;}}return false;}//判断方块是否出界,出界返回true没有则返回falsepublic boolean outOfBounds() {Cell[] cells currentOne.cells;for (Cell cell : cells) {int col cell.getCol();int row cell.getRow();if (col 0 || col COL - 1 || row 0 || row ROW - 1) {return true;}}return false;}//绘制游戏当前状态private void paintState(Graphics g) {if (game_state PLAYING) {g.drawString(show_state[0],500,660);} else if (game_state PAUSE) {g.drawString(show_state[1],500,660);} else if (game_state GAMEOVER) {g.drawString(show_state[2],500,660);g.setColor(Color.red);g.setFont(new Font(Font.SANS_SERIF,Font.BOLD,60));g.drawString(GAMEOVER!,30,400);}}//绘制游戏得分private void paintScore(Graphics g) {g.setFont(new Font(Font.SANS_SERIF,Font.BOLD,40));g.drawString(得分 totalScore,500,248);g.drawString(行数 totalLine,500,440);}//绘制下一个下落的四方格private void paintNextOne(Graphics g) {Cell[] cells nextOne.cells;for (Cell cell : cells) {int x cell.getCol() * CELL_SIZE 370;int y cell.getRow() * CELL_SIZE 25;g.drawImage(cell.getImage(),x,y,null);}}//绘制正在下落的四方格private void paintCurrentOne(Graphics g) {Cell[] cells currentOne.cells;for (Cell cell : cells) {int x cell.getCol() * CELL_SIZE;int y cell.getRow() * CELL_SIZE;g.drawImage(cell.getImage(),x,y,null);}}//绘制游戏主区域private void paintWall(Graphics g) {for (int i 0; i wall.length; i) {for (int j 0; j wall[i].length; j) {int x j * CELL_SIZE;int y i * CELL_SIZE;Cell cell wall[i][j];//判断当前单元格是否有小方格如果无则绘制矩形否则将小方块嵌到墙中if (cell null) {g.drawRect(x,y,CELL_SIZE,CELL_SIZE);} else {g.drawImage(cell.getImage(),x,y,null);}}}}public static void main(String[] args) {//创建窗口对象JFrame frame new JFrame(俄罗斯方块);//创建游戏窗口(即面板)Tetris panel new Tetris();//把面板嵌入到窗口中frame.add(panel);//设置可见frame.setVisible(true);//设置窗口尺寸frame.setSize(810,940);//设置窗口居中frame.setLocationRelativeTo(null);//设置窗口关闭时程序中止frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//游戏逻辑封装在方法中panel.start();} }/*** 描述四方格父类* 属性Cell[]数组用于创建4个小方块* 方法左移一格右移一格下移一格变形(等会写)*/public class Tetromino {protected Cell[] cells new Cell[4];//编写旋转状态protected State[] states;//声明旋转次数protected int count 10000;//编写顺时针旋转四方格方法public void rotateRight() {if (states.length 0) {return;}//旋转次数加1count;//获取当前状态State s states[count % states.length];Cell cell cells[0];int row cell.getRow();int col cell.getCol();//变形cells[1].setRow(row s.row1);cells[1].setCol(col s.col1);cells[2].setRow(row s.row2);cells[2].setCol(col s.col2);cells[3].setRow(row s.row3);cells[3].setCol(col s.col3);}//逆时针旋转四方格方法public void rotateLeft() {//旋转次数加1count--;//获取当前状态State s states[count % states.length];Cell cell cells[0];int row cell.getRow();int col cell.getCol();//变形cells[1].setRow(row s.row1);cells[1].setCol(col s.col1);cells[2].setRow(row s.row2);cells[2].setCol(col s.col2);cells[3].setRow(row s.row3);cells[3].setCol(col s.col3);}/**描述四方格旋转状态的内部类* 属性记录四方格的相对位置*/class State {int row0,col0,row1,col1,row2,col2,row3,col3;public State(){}public State(int row0, int col0, int row1, int col1, int row2, int col2, int row3, int col3) {this.row0 row0;this.col0 col0;this.row1 row1;this.col1 col1;this.row2 row2;this.col2 col2;this.row3 row3;this.col3 col3;}public int getRow0() {return row0;}public void setRow0(int row0) {this.row0 row0;}public int getRow1() {return row1;}public void setRow1(int row1) {this.row1 row1;}public int getRow2() {return row2;}public void setRow2(int row2) {this.row2 row2;}public int getRow3() {return row3;}public void setRow3(int row3) {this.row3 row3;}public int getCol0() {return col0;}public void setCol0(int col0) {this.col0 col0;}public int getCol1() {return col1;}public void setCol1(int col1) {this.col1 col1;}public int getCol2() {return col2;}public void setCol2(int col2) {this.col2 col2;}public int getCol3() {return col3;}public void setCol3(int col3) {this.col3 col3;}}//左移public void moveLeft() {for (Cell cell : cells) {cell.left();}}//右移public void moveRight() {for (Cell cell : cells) {cell.right();}}//下移public void softDrop() {for (Cell cell : cells) {cell.drop();}}//随机生成四方格public static Tetromino randomOne() {int num (int)(Math.random() * 7);Tetromino tetromino null;switch (num) {case 0 :tetromino new I();break;case 1 :tetromino new J();break;case 2 :tetromino new L();break;case 3 :tetromino new O();break;case 4 :tetromino new S();break;case 5 :tetromino new T();break;case 6 :tetromino new Z();break;}return tetromino;} }游戏界面
http://www.w-s-a.com/news/811659/

相关文章:

  • 工业和信息化部网站备案系统查询市场调研表模板
  • 网站流量转化线下推广活动有哪些
  • 030159网站建设与维护宝安网站公司
  • 个人网站备案网站内容做gif表情包网站
  • 湖南省建设厅城乡建设网站怎么建立一个网站网址
  • 图书馆网站建设的规章制度免费个人主页注册
  • 表格网站源码wordpress更换网站域名
  • 芜湖做网站多少钱做公司的网站的需求有哪些
  • 玉溪网站建设制作凌风wordpress百度云
  • 专业建网站价格门户网站建设 请示
  • 安徽省省博物馆网站建设佛山公司网站设计
  • 温州专业营销网站公司网络建设规划
  • 做模型常说的d站是什么网站wordpress 繁體
  • 给网站做h5缓存机制获取小程序api
  • 网站开发文档东莞市建设网站首页
  • 公共空间设计网站企业门户网站建设教程
  • 网站建设公司 深圳镇江建设质量监督站网站
  • 网站底部版权怎么做软广告经典案例
  • 网站收录突然全部没有了东莞网站建设公司电话
  • 境外企业网站推广免费ppt元素
  • 2018网站建设行业广东网站seo
  • 网站后台加密云服务器2008做网站
  • dw制作一个环保网站模板下载吉安网站建设收费
  • 深圳珠宝网站设计北京高端网站建设优势
  • 合肥企业制作网站wordpress创建网站
  • 织梦网站开发兼职wordpress 中间截取缩略图
  • 南通制作网站旅游搭建网站
  • 专业做商铺的网站个人网页html模板完整代码
  • 什么网站做美食最好最专业关键词推广是什么意思
  • 自助建设网站软件网站导航网站可以做吗