bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

java隨機方向行走代碼,java隨機方向行走代碼是什么

用JAVA編寫二維隨機行走問題

public static void main(String[] args) {

網站建設哪家好,找創新互聯!專注于網頁設計、網站建設、微信開發、小程序開發、集團企業網站建設等服務項目。為回饋新老客戶創新互聯還提供了高郵免費建站歡迎大家使用!

// int[] a = new int[]{1,2,3,4};//1 2 3 4 代表上下左右移動

Random r = new Random();

int i = 100;

int[] avgs = new int[4];

Arrays.fill(avgs, 0);//給avgs賦值為0;

for(i = 100;i0;i--){

int walk = r.nextInt(4)+1;

//這里就按得到的walk走

switch (walk) {

case 1:

//上走一步

avgs[0]++;

break;

case 2:

//下走一步

avgs[1]++;

break;

case 3:

//左走一步

avgs[2]++;

break;

case 4:

//右走一步

avgs[3]++;

break;

default:

//錯誤不走

break;

}

}

for(int j = 0;javgs.length;j++){

System.out.println(j+"方向走了多少步:"+avgs[j]+" ");

}

}

java 隨機步法?

給你寫了一個,沒怎么打注釋,哪里看不明白再問,望采納

public?class?Demo{

char[][]?chars?=?new?char[10][10];

int?char_x?=?0;

int?char_y?=?0;

public?static?void?main(String[]?args){

Demo?demo?=?new?Demo();

//System.out.println((int)'A');

for(int?i?=?66;i91;i++){

demo.go((char)i);

}

demo.print();

}

//填充chars

public?Demo(){

for(int?i?=?0?;?i??10?;?i++){

for(int?j?=?0?;?j??10?;?j++){

chars[i][j]?=?'.';

}

}

chars[char_x][char_y]='A';

}

//生成隨機方向,并判斷是否可以移動

public?void?go(char?c){

int?direction;

do{

direction?=?(int)(Math.random()*4);

switch(direction){

case?0:

if(isOut(char_x+1,char_y)isDot(char_x+1,char_y)){

char_x++;

}else{continue;}

break;

case?1:

if(isOut(char_x-1,char_y)isDot(char_x-1,char_y)){

char_x--;

}else{continue;}

break;

case?2:

if(isOut(char_x,char_y+1)isDot(char_x,char_y+1)){

char_y++;

}else{continue;}

break;

case?3:

if(isOut(char_x,char_y-1)isDot(char_x,char_y-1)){

char_y--;

}else{continue;}

break;

}

break;

}while(true);

chars[char_x][char_y]?=?c;

}

//判斷位置是否在數組內,如果在,返回true

public?boolean?isOut(int?x,int?y){

return?(x=0??x10??y=0??y10);

}

//判斷要移動的位置是否為點,若是,則返回true

public?boolean?isDot(int?x,int?y){

return?chars[x][y]=='.';

}

public?void?print(){

for(int?i?=?0;i10;i++){

for(int?j?=?0;j10;j++){

System.out.print(chars[i][j]+"\t");

}

System.out.println();

}

}

}

在Java游戲中讓一個人物走動的代碼是什么?

代碼主要為以下:

package com.lovo.game.frame;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.MediaTracker;

import javax.swing.JFrame;

import com.lovo.game.role.Fire;

import com.lovo.game.role.GameMap;

import com.lovo.game.role.ZhaoYun;

import com.lovo.game.util.TrackerInit;

public class GameStartFrame extends JFrame implements Runnable{

private Image memoryImage;

private Graphics memoryGraphics;

public static boolean isRun = true;

private static GameMap gameMap = new GameMap();

private ZhaoYun zy = new ZhaoYun();

private Fire fire = new Fire();

public GameStartFrame(){

this.setSize(900,700);

this.setVisible(true);

this.setDefaultCloseOperation(3);

//設置居中

this.setLocationRelativeTo(null);

//初始化雙緩沖畫布、畫筆

this.memoryImage = this.createImage(900,700);

this.memoryGraphics = this.memoryImage.getGraphics();

//媒體追蹤器

MediaTracker tracker = new MediaTracker(this);

TrackerInit.initImage(tracker);

//啟動線程

Thread th = new Thread(this);

th.start();

}

public static void main(String[] args) {

GameStartFrame game = new GameStartFrame();

}

public void run() {

while(isRun){

this.flushFrame();

try {

Thread.sleep(20);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

private void flushFrame(){

gameMap.drawMap(memoryGraphics);

zy.drawImage(memoryGraphics);

fire.drawImage(memoryGraphics);

//將雙緩沖畫布中的圖片顯示在窗體

this.getGraphics().drawImage(this.memoryImage,0,0,this);

}

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.role;

import java.awt.Graphics;

import java.awt.Image;

public class GameMap {

public static Image mapImg;

public static int mapx;

public void drawMap(Graphics memoryGraphics){

mapx -=5;

if(mapx =-17100){

mapx = -17100;

}

memoryGraphics.drawImage(mapImg,mapx,0,null);

}

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.role;

import java.awt.Graphics;

import java.awt.Image;

import com.lovo.game.util.MoveImageChange;

public class Fire {

public static Image[]fireImage;

private int x =100;

private int y =300;

private int width = 200;

private int height = 130;

private MoveImageChange moveChange = new MoveImageChange(3);

public void drawImage(Graphics memoryGraphics){

Image img = moveChange.imageChange(fireImage);

memoryGraphics.drawImage(img,this.x,this.y,this.width,this.height,null);

}

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.util;

import java.awt.MediaTracker;

import com.lovo.game.role.Fire;

import com.lovo.game.role.GameMap;

import com.lovo.game.role.ZhaoYun;

public class TrackerInit {

public static void initImage(MediaTracker tracker){

//初始化地圖圖片

GameMap.mapImg = CutImage.getSingleImage("image/map.jpg", tracker);

//趙云

ZhaoYun.zyImage = CutImage.cutOneImage("image/boss/playSpear.png",18, 236, 134,tracker);

//火

Fire.fireImage = CutImage.cutOneImage("image/fireImg.png", 6, 283, 161,tracker);

try {

//0組的圖片全部等待加載完畢后,在顯示

tracker.waitForID(0);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.util;

import java.awt.Image;

import java.awt.MediaTracker;

import java.awt.image.CropImageFilter;

import java.awt.image.FilteredImageSource;

import java.awt.image.ImageProducer;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

public class CutImage {

public static Image[][] cutManyImage(String filePath, int row, int col,

int imageWidth, int imageHight,MediaTracker tracker) {

Image[][] img = new Image[row][col];

ImageIcon imIcon = new ImageIcon(filePath);// 創建圖像數組對象

Image imgTemp = imIcon.getImage();// 創建源圖像

// 為源 圖象獲取ImageProducer源

ImageProducer sourceProducer = imgTemp.getSource();

for (int i = 0; i row; i++) {

for (int j = 0; j col; j++) {

// 創建圖片分割圖像對象,第一、二個參數為分割圖像起始坐標。后兩個參數為圖像大小

CropImageFilter cropImg = new CropImageFilter(j * imageWidth, i * imageHight,imageWidth, imageHight);

ImageProducer imgProducer = new FilteredImageSource(sourceProducer, cropImg);

img[i][j] = new JFrame().createImage(imgProducer);

tracker.addImage(img[i][j], 0);

}

}

return img;

}

public static Image[] cutOneImage(String filePath,int col,

int imageWidth, int imageHight,MediaTracker tracker) {

Image[] img = new Image[col];

ImageIcon imIcon = new ImageIcon(filePath);// 創建圖像數組對象

Image imgTemp = imIcon.getImage();// 創建源圖像

// 為源 圖象獲取ImageProducer源

ImageProducer sourceProducer = imgTemp.getSource();

for (int j = 0; j col; j++) {

// 創建圖片分割圖像對象,第一、二個參數為分割圖像起始坐標。后兩個參數為圖像大小

CropImageFilter cropImg = new CropImageFilter(j * imageWidth, 0,imageWidth, imageHight);

ImageProducer imgProducer = new FilteredImageSource(sourceProducer, cropImg);

img[j] = new JFrame().createImage(imgProducer);

tracker.addImage(img[j], 0);

}

return img;

}

public static Image getSingleImage(String imgPath,MediaTracker tracker){

Image img = new ImageIcon(imgPath).getImage();

tracker.addImage(img, 0);

return img;

}

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.util;

import java.awt.Image;

public class MoveImageChange {

private int count;

private Image img;

private int frequency;

private int loopCount;

public MoveImageChange(int frequency){

this.frequency=frequency;

}

public MoveImageChange(int frequency,int count){

this.frequency=frequency;

this.count = count;

}

public Image imageChange(Image[] images){

if(img==null){//初始圖片為第一張圖片

img=images[0];

}

count++;

if(countfrequency){//當記數器大于頻率時

count=0;

loopCount++;

if(loopCount = images.length){//圖片下標越界時

loopCount=0;

}

img=images[loopCount];

}

return img;

}

public void setLoopCount(int loopCount){

this.loopCount = loopCount;

}

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

package com.lovo.game.role;

import java.awt.Graphics;

import java.awt.Image;

import com.lovo.game.util.MoveImageChange;

public class ZhaoYun {

public static Image[] zyImage;

private int x =600;

private int y =300;

private int width =200;

private int height =130;

private MoveImageChange moveChange = new MoveImageChange(3);

public void drawImage(Graphics memoryGraphics){

Image img = moveChange.imageChange(zyImage);

memoryGraphics.drawImage(img,this.x,this.y,this.width,this.height,null);

JAVA 做一個物體移動的方向問題

Math類有很多數學方面的方法

比如

//三角函數

public static double sin(double a)

public static double cos(double a)

public static double tan(double a)

//反三角函數

public static double asin(double a)

public static double acos(double a)

public static double atan(double a)

//弧度、角度轉換

public static double toRadians(double angdeg)

public static double toDegrees(double angrad)

由于sin,cos等方法參數都是弧度制,所以先使用toRadians()方法把角度轉換成弧度。

比如想獲得 sin30°的值

double d=Math.sin(Math.toRadians(30.0));

java 里如何實現打這樣一張圖載入后,上下左右控制人物行走呢?

這個叫人物行走方位圖吧,一般多用于制作RPG類游戲,比較常見的一種做法是,取坐標:你定義一個矩形,剛好框住一個人,這樣就把一個人物動作取出來了,然后控制框的坐標移動,取下一個動作,直到一個動作循環完成!一樓的辦法也可以,不過是切重新切圖片,比較麻煩,載入的時候,也比較麻煩!

網站欄目:java隨機方向行走代碼,java隨機方向行走代碼是什么
本文來源:http://vcdvsql.cn/article32/hsoppc.html

成都網站建設公司_創新互聯,為您提供外貿建站網站設計公司商城網站App設計建站公司搜索引擎優化

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都app開發公司