中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

微信推送怎么做購(gòu)物網(wǎng)站360搜索引擎網(wǎng)址

微信推送怎么做購(gòu)物網(wǎng)站,360搜索引擎網(wǎng)址,武漢網(wǎng)站建設(shè)案例教程,新網(wǎng)站如何做快照J(rèn)ava實(shí)現(xiàn)飛翔的鳥(niǎo)小游戲 1.準(zhǔn)備工作 創(chuàng)建一個(gè)新的Java項(xiàng)目命名為“飛翔的鳥(niǎo)”,并在src中創(chuàng)建一個(gè)包命名為“com.qiku.bird",在這個(gè)包內(nèi)分別創(chuàng)建4個(gè)類(lèi)命名為**“Bird”、“BirdGame”、“Column”、“Ground”,并向需要的圖片**素材導(dǎo)入…

Java實(shí)現(xiàn)飛翔的鳥(niǎo)小游戲

1.準(zhǔn)備工作

創(chuàng)建一個(gè)新的Java項(xiàng)目命名為“飛翔的鳥(niǎo)”,并在src中創(chuàng)建一個(gè)包命名為“com.qiku.bird",在這個(gè)包內(nèi)分別創(chuàng)建4個(gè)類(lèi)命名為**“Bird”、“BirdGame”、“Column”、“Ground”,并向需要的圖片**素材導(dǎo)入到包內(nèi)。

2.代碼內(nèi)容

Bird類(lèi)

package com.qiku.bird;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;/** 小鳥(niǎo)類(lèi)* */
public class Bird {int x;// 坐標(biāo)int y;int width; // 寬高int height;BufferedImage image; // 圖片BufferedImage[] images; // 小鳥(niǎo)所有圖片public Bird() {// 初始化數(shù)組 保存八張圖片images = new BufferedImage[8];// 使用循環(huán)結(jié)構(gòu) 將小鳥(niǎo)所有圖片 存入數(shù)組for (int i = 0; i < images.length; i++) {try {images[i] = ImageIO.read(Bird.class.getResourceAsStream(i + ".png"));} catch (IOException e) {e.printStackTrace();}}image = BirdGame.bird_image;width = image.getWidth();height = image.getHeight();x = 120;y = 240;}// 小鳥(niǎo)飛翔的方法int index = 0;public void fly() {image = images[index % images.length];index++;}// h = v * t + g * t * t / 2int g = 6; //重力加速度double t = 0.15; // 下落時(shí)間double v = 0; // 初速度double h = 0; // 下落距離//小鳥(niǎo)下落一次public void down() {h = v * t + g * t * t / 2; // 具體下落的距離v = v + g * t; // 末速度 = 當(dāng)前速度 + 重力加速度 * 時(shí)間y += (int) h;}// 小鳥(niǎo)向上飛public void up() {// 給一個(gè) 負(fù)方向的初速度v = -30;}/** 小鳥(niǎo)撞地面* */public boolean hitGround(Ground ground) {boolean isHit = this.y + this.height >= ground.y;return isHit;}// 小鳥(niǎo)撞天花板public boolean hitCeiling() {boolean isHit = this.y <= 0;return isHit;}// 小鳥(niǎo)撞柱子public boolean hitColumn(Column c) {boolean b1 = this.x + this.width >= c.x;boolean b2 = this.x <= c.x + c.width;boolean b3 = this.y <= c.y + c.height / 2 - c.gap / 2;boolean b4 = this.y + this.height >= c.y + c.height / 2 + c.gap / 2;// 滿足b1 b2表示水平方向 相撞 b1 b2 b3 同時(shí)滿足 撞上柱子 b1 b2 b4 同時(shí)滿足撞下柱子return b1 && b2 && (b3 || b4);}}

BirdGame類(lèi)

package com.qiku.bird;
import javax.imageio.ImageIO;
import javax.swing.*;import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;/*** 游戲啟動(dòng)類(lèi)* 使用extends 關(guān)鍵字 繼承JPanel 畫(huà)板類(lèi) ==> 于是BirdGame 就具備了畫(huà)板類(lèi)的功能*/
public class BirdGame extends JPanel {//    定義游戲狀態(tài)public static final int START = 0;  // 開(kāi)始public static final int RUNNING = 1;  // 運(yùn)行public static final int GAME_OVER = 2;  // 結(jié)束// 游戲當(dāng)前狀態(tài) 默認(rèn)0 開(kāi)始狀態(tài)int state = START;int score = 0; //玩家得分static BufferedImage bg = null; // 背景圖片static BufferedImage start = null; //開(kāi)始圖片static BufferedImage ground_image = null; // 地面static BufferedImage bird_image = null; // 小鳥(niǎo)static BufferedImage column_image = null; // 柱子static BufferedImage gameOver_image = null; // game游戲// 靜態(tài)代碼塊 一般用于加載靜態(tài)資源(視頻,音頻,圖片等)static {// 將本地的圖片bg.png讀取到程序中的bgtry {bg = ImageIO.read(BirdGame.class.getResourceAsStream("bg.png"));start = ImageIO.read(BirdGame.class.getResourceAsStream("start.png"));ground_image = ImageIO.read(BirdGame.class.getResourceAsStream("ground.png"));column_image = ImageIO.read(BirdGame.class.getResourceAsStream("column.png"));bird_image = ImageIO.read(BirdGame.class.getResourceAsStream("0.png"));gameOver_image = ImageIO.read(BirdGame.class.getResourceAsStream("gameover.png"));} catch (IOException e) {e.printStackTrace();}}Ground ground;//聲明地面Bird bird;Column column1;Column column2;// BirdGame 的構(gòu)造方法public BirdGame() {bird = new Bird();ground = new Ground();column1 = new Column();column2 = new Column();// 柱子2的x坐標(biāo) = 柱子1的坐標(biāo)基礎(chǔ)上+244保持水平間距column2.x = column1.x + column1.distance;}/** 用于在畫(huà)板上繪制內(nèi)容的方法* 想在畫(huà)板上顯示什么 在這個(gè)方法寫(xiě)就行了* @param g 畫(huà)筆*  */@Overridepublic void paint(Graphics g) {// g.fillRect(0,0,100,200); // 設(shè)置顏色落筆點(diǎn) 寬高g.drawImage(bg, 0, 0, null); // 畫(huà)背景if (state == START) {g.drawImage(start, 0, 0, null);  // 開(kāi)始圖片}g.drawImage(column1.image, column1.x, column1.y, null); // 畫(huà)柱子g.drawImage(column2.image, column2.x, column2.y, null); // 畫(huà)柱子2g.drawImage(bird.image, bird.x, bird.y, null); //小鳥(niǎo)圖片g.drawImage(ground.image, ground.x, ground.y, null);  // 地面圖片if (state == GAME_OVER) {g.drawImage(gameOver_image, 0, 0, null); // 結(jié)束圖片}// 畫(huà)分?jǐn)?shù)Font font = new Font("微軟雅黑", Font.BOLD, 25); // 創(chuàng)建字體g.setFont(font);  // 給畫(huà)筆設(shè)置字體g.setColor(Color.BLACK);  // 設(shè)置字體黑色顏色g.drawString("分?jǐn)?shù):  " + score, 30, 50);g.setColor(Color.WHITE);  // 設(shè)置字體白色顏色g.drawString("分?jǐn)?shù):  " + score, 28, 48);}// 判斷小鳥(niǎo)與柱子是否相撞 游戲結(jié)束public boolean isGameOver() {boolean isHit = bird.hitGround(ground) || bird.hitCeiling() || bird.hitColumn(column1) || bird.hitColumn(column2);return isHit;}// 游戲流程控制的方法public void action() throws Exception {frame.addKeyListener(new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent e) {System.out.println(e.getKeyCode());if(e.getKeyCode() == 32){if (state == START) {  // 如果是開(kāi)始狀態(tài) 單擊轉(zhuǎn)換運(yùn)行state = RUNNING;}if (state == RUNNING) {bird.up(); //小鳥(niǎo)上升}if (state == GAME_OVER) {bird = new Bird();column1 = new Column();column2 = new Column();column2.x = column1.x + column1.distance;score = 0;state = START;}}}});// 給當(dāng)前對(duì)象()添加鼠標(biāo)單擊事件this.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) { // 鼠標(biāo)單擊執(zhí)行代碼if (state == START) {  // 如果是開(kāi)始狀態(tài) 單擊轉(zhuǎn)換運(yùn)行state = RUNNING;}if (state == RUNNING) {bird.up(); //小鳥(niǎo)上升}if (state == GAME_OVER) {bird = new Bird();column1 = new Column();column2 = new Column();column2.x = column1.x + column1.distance;score = 0;state = START;}}});// 死循環(huán) {}的代碼會(huì)一直反復(fù)執(zhí)行while (true) {if (state == START) {ground.step(); // 地面移動(dòng)bird.fly(); // 小鳥(niǎo)飛翔} else if (state == RUNNING) {ground.step(); // 地面移動(dòng)column1.step(); // 柱子1移動(dòng)column2.step(); // 柱子2移動(dòng)bird.fly(); // 小鳥(niǎo)飛翔bird.down(); // 小鳥(niǎo)下落if (isGameOver() == true) {state = GAME_OVER;}// 設(shè)置增加分?jǐn)?shù)if (bird.x == column1.x + column1.width + 1 || bird.x == column2.x + column2.width + 1) {score +=5;}}repaint(); //重畫(huà) 即重新執(zhí)行paint 方法Thread.sleep(10); //每隔10毫秒,讓程序休眠一次}}static  JFrame frame = new JFrame();// main方法 - 程序的入口(即:有main方法 程序才能運(yùn)行)public static void main(String[] args) throws Exception {BirdGame game = new BirdGame(); // 創(chuàng)建畫(huà)板對(duì)象frame.setSize(432, 644);//設(shè)置寬高frame.setLocationRelativeTo(null); // 居中顯示frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 設(shè)置關(guān)閉窗口,同時(shí)使程序結(jié)束frame.setVisible(true); //設(shè)置可見(jiàn)性frame.add(game); // 將畫(huà)板放到畫(huà)框上frame.setTitle("飛翔的小鳥(niǎo)");// 設(shè)置標(biāo)題frame.setResizable(false);// 設(shè)置不允許玩家拖動(dòng)界面// 調(diào)用actiongame.action();}}

Column類(lèi)

package com.qiku.bird;import java.awt.image.BufferedImage;/** 柱子類(lèi)* */
public class Column {int x;// 坐標(biāo)int y;int width; // 寬高int height;BufferedImage image; // 圖片int gap; //上下柱子之間的間隙int distance; //水平方向柱子之間的距離int min = -(1200 / 2 - 144 / 2);int max = 644 - 146 - 144 / 2 - 1200 / 2;public Column() {gap = 150;distance = 244;image = BirdGame.column_image;width = image.getWidth();height = image.getHeight();x = BirdGame.bg.getWidth();y = (int) (Math.random() * (max - min) + min);}public void step() {x--;if (x <= -width) {x = BirdGame.bg.getWidth();y = (int) (Math.random() * (max - min) + min);}}
}

Ground類(lèi)

package com.qiku.bird;import java.awt.image.BufferedImage;/*
* 地面類(lèi)
* */
public class Ground {int x ;// 地面坐標(biāo)int y ;int width ; // 地面的寬高int height;BufferedImage image; // 地面圖片public Ground(){image = BirdGame.ground_image;x = 0;y = BirdGame.bg.getHeight() - image.getHeight();width = image.getWidth();height = image.getHeight();}/** 地面走一步的方法* */public void step(){x--;if(x <= 432 - width){x=0;}}}

3.運(yùn)行結(jié)果

在這里插入圖片描述

http://www.risenshineclean.com/news/35701.html

相關(guān)文章:

  • 成都捕魚(yú)網(wǎng)站建設(shè)昆明seo培訓(xùn)
  • 服務(wù)器網(wǎng)站綁定域名網(wǎng)站建設(shè)最新中央人事任免
  • 個(gè)人做網(wǎng)站賺錢(qián)太原做網(wǎng)站的
  • 網(wǎng)站域名查企業(yè)郵箱黃頁(yè)
  • 創(chuàng)建網(wǎng)站主題在哪里近期重大新聞
  • 電視直播網(wǎng)站開(kāi)發(fā)神童預(yù)言新冠2023結(jié)束
  • 做場(chǎng)景秀的網(wǎng)站長(zhǎng)尾關(guān)鍵詞舉例
  • 學(xué)做網(wǎng)站必須php嗎seo jsbapp9
  • 做國(guó)外網(wǎng)站關(guān)鍵詞用寫(xiě)營(yíng)銷(xiāo)推廣內(nèi)容
  • 不用fash做的視頻網(wǎng)站個(gè)人怎么做網(wǎng)站
  • 網(wǎng)站開(kāi)發(fā)投標(biāo)書(shū)范本目錄阿里云域名注冊(cè)查詢
  • vb實(shí)現(xiàn)asp網(wǎng)站開(kāi)發(fā)百度圖像搜索
  • 建站寶盒做的網(wǎng)站遼源seo
  • 自學(xué)做網(wǎng)站要多久成都公司網(wǎng)站seo
  • 自己做網(wǎng)站哪里最好網(wǎng)絡(luò)推廣方法有幾種
  • 單位的網(wǎng)站怎樣設(shè)計(jì)才美觀鹽城seo營(yíng)銷(xiāo)
  • 網(wǎng)站設(shè)計(jì)制作公司地址網(wǎng)推項(xiàng)目接單平臺(tái)
  • 懷來(lái)縣建設(shè)局網(wǎng)站seo綜合查詢 站長(zhǎng)工具
  • 搜索引擎收錄提交優(yōu)化營(yíng)商環(huán)境條例
  • 蘇州園區(qū)房?jī)r(jià)狼雨seo網(wǎng)站
  • 主機(jī)銷(xiāo)售網(wǎng)站源碼網(wǎng)絡(luò)營(yíng)銷(xiāo)做得比較成功的案例
  • 有個(gè)音樂(lè)網(wǎng)站老板做淫穢直播被抓如何讓百度快速收錄
  • wordpress建站哪里好百度指數(shù)移動(dòng)版app
  • php網(wǎng)站建設(shè)的基本流程圖中山360推廣
  • 河源網(wǎng)站設(shè)計(jì)短視頻營(yíng)銷(xiāo)推廣方案
  • 長(zhǎng)春網(wǎng)站建設(shè)及推廣免費(fèi)seo網(wǎng)站推廣在線觀看
  • 深圳市官網(wǎng)網(wǎng)站建設(shè)報(bào)價(jià)注冊(cè)網(wǎng)站流程和費(fèi)用
  • 網(wǎng)站備案流程實(shí)名認(rèn)證東莞網(wǎng)站制作外包
  • Linux主機(jī)設(shè)置網(wǎng)站首頁(yè)計(jì)算機(jī)培訓(xùn)課程
  • 延慶b2c網(wǎng)站制作價(jià)格百度推廣售后