栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

中脉虚假宣传APP不存在,从设计到研发过程解析

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

中脉虚假宣传APP不存在,从设计到研发过程解析

中脉虚假宣传APP不存在,从设计到研发过程解析

该文件定义了一个Circle类,用以生成每个球的对象。

属性有圆的半径、x坐标、y坐标、x方向的偏移量、y方向的偏移量、id。

方法有移动和获取每个属性的接口

package com.hust.game;
import java.awt.*;
import java.util.Random;
public class Circle {
    protected int radius,x,y,dx,dy;
    private int id;
    protected GUI gui;
    String color;
    public Circle(int X,int Y,int R,int id,String color,GUI gui,int dx,int dy){
        x = X;
        y = Y;
        radius = R;
        Random random = new Random();
        this.dx = random.nextBoolean() ? dx : -dx;
        this.dy = random.nextBoolean() ? dy : -dy;
        this.gui = gui;
        this.id = id;
        this.color = color;
        draw();
    }
    public Circle(int X,int Y,int R,int id,String color,GUI gui){
        x = X;
        y = Y;
        radius = R;
        this.gui = gui;
        this.id = id;
        this.color = color;
    }
    public void draw(){
        gui.updateCircle(this);
    }
    public void move(){
//        clearcircle()
        x += dx;
        y += dy;
        if(x + radius > gui.graphWidth || x - radius < 0){
            dx = -dx;
        }
        if(y + radius > gui.graphHeight || y - radius < GUI.PROGRESSWIDTH){
            dy = -dy;
        }
        draw();
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }
    public int getR(){
        return radius;
    }
    public int getD(){
        return radius << 1;
    }
    public int getID(){
        return id;
    }
}

 

中脉虚假宣传APP不存在,从设计到研发过程解析

import java.util.Random; 
 

public class Bee extends FlyingObject implements Award{ 
 private int xSpeed = 1; //x坐标移动速度 
 private int ySpeed = 2; //y坐标移动速度 
 private int awardType; //奖励类型 
 
 
 public Bee(){ 
  this.image = ShootGame.bee; 
  width = image.getWidth(); 
  height = image.getHeight(); 
  y = -height; 
  Random rand = new Random(); 
  x = rand.nextInt(ShootGame.WIDTH - width); 
  awardType = rand.nextInt(2); //初始化时给奖励 
 } 
 
 
 public int getType(){ 
  return awardType; 
 } 
 
 
 @Override
 public boolean outOfBounds() { 
  return y>ShootGame.HEIGHT; 
 } 
 
 
 @Override
 public void step() {  
  x += xSpeed; 
  y += ySpeed; 
  if(x > ShootGame.WIDTH-width){ 
   xSpeed = -1; 
  } 
  if(x < 0){ 
   xSpeed = 1; 
  } 
 } 
}

 

好了不扯蛋了,认真回答问题。
0.用java写小游戏需要知道什么,明白什么?
首先需要知道游戏的本质,其实是图片(像)的显示以及图片的移动(图片坐标的改变)。
明白了这两点以后,问题就变得简单了,把问题变成,如何用java显示一张图片与如何动态的改变图片的坐标。
到这里回答题主的第二个问题。
1.需要初学者做的步骤有哪些
展示一张图片,需要一个容器,容器的种类有很多, 这里不一一列举,以上述游戏中使用的java原生javax.swing包中的类容为例,不需要再引入其它jar包。

public class Bullet extends FlyingObject { 
 private int speed = 3; //移动的速度 
 
 
 public Bullet(int x,int y){ 
  this.x = x; 
  this.y = y; 
  this.image = ShootGame.bullet; 
 } 
 
 
 @Override
 public void step(){  
  y-=speed; 
 } 
 
 
 @Override
 public boolean outOfBounds() { 
  return y<-height; 
 } 
 
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/270815.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号