疯狂摩托撞墙,是一个穿墙一个撞墙电影还是卡墙

QWQ投稿:5粉丝:30未经作者授权 禁止转载
看过该视频的还喜欢miniOFF《好看》依托百度技术,精准推荐优质短视频内容,懂你所好,量身打造最适合你的短视频客户端!当前位置: >>
达内学习心得:和TTS 有所不同的贪吃蛇 能穿墙而不是撞墙
达内学习心得:和 TTS 有所不同的贪吃蛇 能穿墙而不是撞墙参赛人:陈彬豪 获得奖项:三等奖 内容: 第一步,就是先把单个格子的属性创建出来 public class Cell { static int indexRow = 10000;//这个参数是上下穿墙用的,为了保证不用完,要尽可能的 大 static int indexCol = 10000;//这个参数是左右穿墙用的,为了保证不用完,要尽可能的大 public Cell(){//对于父类,无参数构造器不一定用到,应该习惯的写上 } public Cell(int x, int y, int color) { super(); this.row = this.col = this.color = } //各属性的 get set 方法 public int getColor() { } public void setColor(int color) { this.color = } public int getRow() { } public void setRow(int x) { this.row = } public int getCol() { } public void setCol(int y) { this.col = } /**向 X 轴负正向走*/ public void left(){ row = (indexRow+(--row))%40;/*这就是穿墙的关键,40 是贪吃蛇墙的长,%40 就 能使蛇走不出墙,注意! !(--row)不能写成(row--) */ } /**向 X 轴负方向走*/ public void right(){ row= (indexRow+(++row))%40; } /**向 Y 轴负方向走*/ public void up(){ col = (indexCol+(--col))%40; } /**向 Y 轴正方向走*/ public void down(){ col = (indexCol+(++col))%40; } public String toString(){ return row+&,&+ } }第二步,对蛇身的构造,以及蛇运动的方法import java.util.A public class Body extends Cell{ /**蛇身的颜色*/ public static final int BADY_COLOR = 0x66 /** 身体 */ public Cell[] /**头*/ protected C public Body(){ bodys = new Cell[5]; head = new Cell(4,10,BADY_COLOR); bodys[0] = bodys[1] = new Cell(3,10,BADY_COLOR); bodys[2] = new Cell(2,10,BADY_COLOR); bodys[3] = new Cell(1,10,BADY_COLOR); bodys[4] = new Cell(0,10,BADY_COLOR); } /**绝对左移*/ public Cell[] moveLeft() { worm Worm = new worm(); //当前蛇身的长度 int length = Worm.getBodyCellsLength(); //对蛇身数组的扩容 bodys = Arrays.copyOf(bodys, length); for(i = length-1;i&0;i--){ if(bodys[i]==null){//如果吃了食物就会扩容,扩容的新元素为 null bodys[i]=new Cell(); } bodys[i].col=bodys[i-1]. bodys[i].row=bodys[i-1]. } head.left(); } /**绝对左移*/ public Cell[] moveRight() { worm Worm = new worm(); int length = Worm.getBodyCellsLength(); bodys = Arrays.copyOf(bodys, length); for(i = length-1;i&0;i--){ if(bodys[i]==null){ bodys[i]=new Cell(); } bodys[i].setCol(bodys[i-1].col); bodys[i].setRow(bodys[i-1].row); } head.right(); } /**绝对上移*/ public Cell[] goUp() { worm Worm = new worm(); int length = Worm.getBodyCellsLength(); bodys = Arrays.copyOf(bodys, length); for(i = length-1;i&0;i--){ if(bodys[i]==null){ bodys[i]=new Cell(); } bodys[i].col=bodys[i-1]. bodys[i].row=bodys[i-1]. } head.up(); } /**绝对下移*/ public Cell[] goDown() { worm Worm = new worm(); int length = Worm.getBodyCellsLength(); bodys = Arrays.copyOf(bodys, length); for(i = length-1;i&0;i--){ if(bodys[i]==null){ bodys[i]=new Cell(); } bodys[i].col=bodys[i-1]. bodys[i].row=bodys[i-1]. } head.down(); }public Cell[] getBody(){ }public String toString(){ return Arrays.toString(bodys); } }第三步绘制动作方法和绘图 import java.awt.C import java.awt.F import java.awt.G import java.awt.I import java.awt.LayoutM import java.awt.event.KeyE import java.awt.event.KeyL import java.awt.image.ImageO import java.util.A import java.util.R import java.util.T import java.util.TimerT import javax.swing.ImageI import javax.swing.JB import javax.swing.JF import javax.swing.JL import javax.swing.JP public class worm extends JPanel { public static final int ROWS = 40; public static final int COLS = 40; private Cell[][] wall = new Cell[ROWS][COLS]; /** 每一格的大小规格 */ public static final int CELL_SIZE = 10; /** 与边框的距离 */ public static final int ADD = 20; public static final int BG_COLOR = 0xc3d5 /** 背景色 */ public static final int FONT_COLOR = 0 /** 边框线条颜色 */ public static final int BORDER_COLOR = 0x667799; /** 食物的颜色 */ public static final int FOOD_COLOR = 0xff0000; /** 蛇身的颜色 */ public static final int BADY_COLOR = 0x66 /** 是否吃到的判定 */ public static boolean eat = /** 正在向绝对上走 */ public static boolean goingUp = /** 正在向绝对下走 */ public static boolean goingDwon = /** 正在向绝对右走 */ public static boolean moveingRight = /** 正在向绝对左走 */ public static boolean moveingLeft = /**游戏结束*/ public static boolean gameOver = /**暂停判定*/ public static boolean pause = /**速度*/ pub /**分数*/ pub /** 食物 */ public static C /** 吃到食物前一格时的最后一格 */ public Cell tempB public T public static B /** 蛇身 */ public static Cell[] bodyC public static JFrame frame = new JFrame(&贪吃蛇&); public static worm panel = new worm(null); // ------------------------------------开始--------------------------------- public worm(LayoutManager layout){ super(layout); } public worm(){ } public static void main(String[] args) { Random ra = new Random(); /** 食物 */ food = new Cell(ra.nextInt(ROWS), ra.nextInt(COLS), FOOD_COLOR); frame.setSize((COLS +7) * CELL_SIZE-20, (ROWS+8) * CELL_SIZE + 90); frame.setResizable(false);//禁止窗口缩放 frame.setLocationRelativeTo(null);// 窗口居中//null 是窗口的相对位置,没有就是居 中 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭窗口就关闭 软件 frame.add(panel);// 窗口中添加面板 frame.setVisible(true);// 显示窗口panel.action();} /** 动作流程 */ private void action() { startAction(); this.requestFocus();// 为当前面板请求获得输入焦点,this 对象就获得了输入焦点, 以后任何的键盘输入目标就是这个面板 this.addKeyListener(new KeyListener() {// 添加键盘监听, public void keyPressed(KeyEvent e) {// 按键按下去 System.out.println(&type:& + e.getKeyCode()); int key = e.getKeyCode(); if(gameOver!= true){ switch (key) { case 'A': if(goingUp||goingDwon){ moveLeftAction(); pause= }
case 'D': if(goingUp || goingDwon){ moveRightAction(); pause= } case 'W': if(moveingRight || moveingLeft){ goUpAction(); pause= } case 'S': if(moveingLeft || moveingRight){ goDwonAction(); pause= } case KeyEvent.VK_SPACE: if(pause==false){ pauseAction(); pause= } } repaint(); } if(key==KeyEvent.VK_Q){ gameOver= pause= timer.cancel(); repaint(); } if(gameOver){ if(key==KeyEvent.VK_ENTER){ startAction(); } } /**ESC 退出系统*/ if(key==KeyEvent.VK_ESCAPE){ System.exit(0); } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); }// 按键松开 public void keyTyped(KeyEvent e) { int key = e.getKeyCode(); if(key=='T'){ System.exit(0); } }// 按键按一下 }); } /**开始流程*/ public void startAction(){ gameOver = pause = score = 0; level(); body = new Body(); bodyCells = body. newFood(); moveingRight = timer = new Timer(); timer.schedule(new TimerTask() { public void run() { TempBody(bodyCells); bodyCells = body.moveRight(); level(); gameOverAction(); bodyCells = grow(bodyCells, food, tempBody); repaint(); } }, 500, speed); repaint(); } /**结束流程*/ public void gameOverAction() { if (gameOver()) { System.out.println(&gameOver&); timer.cancel(); } } private void pauseAction() { timer.cancel(); pause = } /** 向上走流程 */ private void goUpAction() { timer.cancel(); goingUp = goingDwon = moveingRight = moveingLeft = level(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { TempBody(bodyCells); bodyCells = body.goUp(); gameOverAction(); bodyCells = grow(bodyCells, food, tempBody); repaint(); } }, 0, speed); } /** 向下走流程 */ private void goDwonAction() { timer.cancel(); goingUp = goingDwon = moveingRight = moveingLeft = level(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { TempBody(bodyCells); bodyCells = body.goDown(); gameOverAction(); bodyCells = grow(bodyCells, food, tempBody); repaint(); } }, 0, speed); } /** 向左走流程 */ private void moveLeftAction() { timer.cancel(); goingUp = goingDwon = moveingRight = moveingLeft = level(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { TempBody(bodyCells); bodyCells = body.moveLeft(); gameOverAction(); bodyCells = grow(bodyCells, food, tempBody); repaint(); } }, 0, speed); } /** 想右走流程 */ private void moveRightAction() { timer.cancel(); goingUp = goingDwon = moveingRight = moveingLeft = level(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { TempBody(bodyCells); bodyCells = body.moveRight(); gameOverAction(); bodyCells = grow(bodyCells, food, tempBody); repaint(); } }, 0, speed); } /** 吃到食物前一格时的最后一格 */ public void TempBody(Cell[] bodyCells) { tempBody = new Cell(bodyCells[bodyCells.length - 1].row, bodyCells[bodyCells.length - 1].col, bodyCells[bodyCells.length - 1].color); } /** 增加 1 格 tempBody:吃到食物前一格时的最后一格 */ public Cell[] grow(Cell[] bodyCells, Cell food, Cell tempBody) { if (eatFood(bodyCells[0], food)) { bodyCells = Arrays.copyOf(bodyCells, bodyCells.length + 1); bodyCells[bodyCells.length - 1] = tempB score = (bodyCells.length-5)*10; newFood(); return bodyC } return bodyC } /** 判断是否吃到食物 */ public static boolean eatFood(Cell head, Cell food) { eat = food.row == head.row && food.col == head. } /** 刷新食物 */ public void newFood() { if (eat) { Random ra = new Random(); /** 食物 */ food = new Cell(ra.nextInt(20), ra.nextInt(20), FOOD_COLOR); for(Cell cell: bodyCells){ if(food.row==cell.row && food.col== cell.col){ newFood(); } } eat = } } private void level(){ int index = 100; int scoreIndex = speed=200; if(scoreIndex&=index){ speed-=50; scoreIndex-= } if(scoreIndex&=index){ speed-=50; scoreIndex-= index=50; } if(scoreIndex&=index){ speed-=50; scoreIndex-= index=100; } if(scoreIndex&=index){ speed-=10; scoreIndex-= } } /** 游戏结束判定 */ private boolean gameOver() { for (int i = 1; i & bodyCells. i++) { gameOver = bodyCells[0].row == bodyCells[i].row && bodyCells[0].col == bodyCells[i]. if (gameOver == true) { return gameO } } return gameO } public int getBodyCellsLength() { return bodyCells. } public worm getworm(){ worm we = new worm(); } // ------------------------------------------------------------------------------------------/** JPanel 类利用 paint (图画) 方法绘制界面, 子类重写 paint 方法可以修改绘图逻辑 */ public void paint(Graphics g) { paintBackBorder(g); //paintWall(g);//绘制墙的格子,方便蛇的运动,但玩的时候最好注释掉,这要更美 观 paintBody(g); paintFood(g); paintScore(g); paintTetrisBorder(g); } /** 填充背景 */ private void paintBackBorder(Graphics g) { g.setColor(new Color(0x000000)); g.fillRect(ADD, ADD+CELL_SIZE * 10, CELL_SIZE * ROWS, CELL_SIZE * COLS); g.setColor(new Color(0xc3d5ea)); g.fillRect(ADD, ADD, CELL_SIZE *ROWS, CELL_SIZE * 10); } /** 绘制墙 */ private void paintWall(Graphics g) { for (int row = 0; row & ROWS; row++) { for (int col = 0; col & COLS; col++) { Cell cell = wall[row][col]; // 墙的格子 g.setColor(new Color(BORDER_COLOR)); g.drawRect(ADD +col * CELL_SIZE, ADD+10*CELL_SIZE+row * CELL_SIZE, CELL_SIZE); } } } /** 绘制食物 */ private void paintFood(Graphics g) { int row = food.getRow(); int col = food.getCol(); g.setColor(new Color(food.getColor())); g.fill3DRect(ADD + row * CELL_SIZE, ADD + col * CELL_SIZE+CELL_SIZE * 10, CELL_SIZE, CELL_SIZE, true); g.setColor(new Color(0xffffff)); g.draw3DRect(ADD + row * CELL_SIZE, ADD + col * CELL_SIZE+CELL_SIZE *// // CELL_SIZE, // 10, CELL_SIZE, CELL_SIZE, true); } /** 绘制蛇身 */ private void paintBody(Graphics g) { for (Cell cell : bodyCells) { int row = cell.getRow(); int col = cell.getCol(); g.setColor(new Color(0x66ccff)); g.fill3DRect(ADD + row * CELL_SIZE, ADD + col * CELL_SIZE+CELL_SIZE * 10, CELL_SIZE, CELL_SIZE, true); g.setColor(new Color(0xffffff)); g.draw3DRect(ADD + row * CELL_SIZE, CELL_SIZE+CELL_SIZE * 10, CELL_SIZE, CELL_SIZE, true); } } /** 绘制文字 */ private void paintScore(Graphics g) { Font font = new Font(getFont().getName(), Font.BOLD, 35); String str = &SCORE : & + g.setColor(new Color(FONT_COLOR)); g.setFont(font); g.drawString(str, 13 * CELL_SIZE, 7 * CELL_SIZE); str = &[SPACE]PAUSE&; font = new Font(getFont().getName(), Font.BOLD, 20); g.setFont(font); g.drawString(str, 4 * CELL_SIZE, 11 * CELL_SIZE); str = &[Q]QUIT&; g.drawString(str, 25 * CELL_SIZE, 11 * CELL_SIZE); if(pause){ font = new Font(getFont().getName(), Font.BOLD, 100); g.setFont(font); str = &PAUSE&; g.drawString(str, 6 * CELL_SIZE, 35 * CELL_SIZE); } if(gameOver){ font = new Font(getFont().getName(), Font.BOLD, 60); g.setFont(font); str = &GAME OVER &; g.drawString(str, 4 * CELL_SIZE, 25 * CELL_SIZE);ADD+col* font = new Font(getFont().getName(), Font.BOLD, 20); g.setFont(font); str = &YOUR SCORE &; g.drawString(str, 16 * CELL_SIZE, 30 * CELL_SIZE); font = new Font(getFont().getName(), Font.BOLD, 100); g.setFont(font); str = scoreString(score); g.drawString(str, 6 * CELL_SIZE, 40 * CELL_SIZE); str = &[ENTER] START &; font = new Font(getFont().getName(), Font.BOLD, 40); g.setFont(font); g.drawString(str, 7 * CELL_SIZE, 45* CELL_SIZE); } } /** 绘制边框 */ private void paintTetrisBorder(Graphics g) { g.setColor(new Color(BORDER_COLOR));// 绘制边线 g.drawRect(ADD, ADD+CELL_SIZE * 10, CELL_SIZE * COLS, CELL_SIZE * ROWS); g.drawRect(ADD, ADD, CELL_SIZE*COLS, CELL_SIZE* 10); } private String scoreString(int score){ String str= &&+ for(int i=0;i&3-(str.length())/2;i++){ if(str.length()%2==0){ str+=& &; } if(str.length()%2!=0){ str=& &+ } } } }以上就是完整的代码, 亲测能用, 复制粘贴就用运行, 基本上都有注释, 看注释就能明白了, 写程序加注释是很好的习惯, 不然不只是用的人不知道说什么, 写到后面很可能连自己都不 知哪个方法是干什么的! ! ! 写这篇东西纯属学习上的交流,给多少分就随意把,本人觉得征文的这个系统太坑爹了,进 来了居然不打分不给走(x.x)
All rights reserved Powered by
www.tceic.com
copyright &copyright 。文档资料库内容来自网络,如有侵犯请联系客服。王者荣耀:谁说有位移就能够穿墙,这三个英雄的位移技能日常撞墙王者荣耀:谁说有位移就能够穿墙,这三个英雄的位移技能日常撞墙游戏老斯鸡百家号王者荣耀里面地图有着墙壁的阻挠,这让许多拥有位移的英雄能够穿墙进行追击或者穿墙逃脱,但是有那么一些英雄即使拥有着位移技能,也不能够穿墙,这一设定怕是让这些英雄欲哭无泪.那么有哪些英雄遭到这样的尴尬场面呢?第三名—苏烈苏烈作为一名坦克战士英雄,有着自己的被动复活效果以及二技能的位移技能.但是由于定位是坦克类的保护型英雄,所以苏烈的二技能只要能够将突进的敌人隔离开就行了,对于能否穿墙的效果并没有很大的差距,所以即使苏烈的位移技能即使不能够穿墙也足以发挥作用.第二名—刘备刘备虽然跟苏烈同样定义为是战士,但是与苏烈不同的是,他需要帮助团队提供伤害以及前期刘备的作战力很强,所以配合上自己的位移技能能够配合己方的队友进行野区的反野,但是由于位移技能不能够穿墙这样就很好的抑制住了刘备在前期过于强势的效果,所以刘备的这个位移技能不能够穿墙很好的保护了游戏前期的平衡性.第一名—铠铠这个位移技能不能够穿墙是影响最大的,铠虽然定位是战士,但是需要出攻击装所以铠的抗性不高,在失去了大招的保护效果下,铠跟脆皮的法师射手英雄差距不大,而且伤害也不及他们高,所以这个位移技能不能够穿墙是让铠最尴尬的.所以这样的无法穿墙位移技能让铠的玩家对于团队的进场时机非常讲究.不知道你们觉得哪个英雄的位移技能无法穿墙影响是最大的.本文仅代表作者观点,不代表百度立场。系作者授权百家号发表,未经许可不得转载。游戏老斯鸡百家号最近更新:简介:每日最新资讯,为你打造专属游戏攻略!作者最新文章相关文章}

我要回帖

更多关于 外墙穿墙套管防水施工 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信