日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java rpg项目代码_java rpg游戏代码(移动保存读取)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java rpg项目代码_java rpg游戏代码(移动保存读取) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

package ggg;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

import java.io.*;

public class Tank1? extends JFrame

{

//用來存儲對應的圖片的二維數組 (這里的icon數組,只是用來將我們設置好的數組在界面上顯示出來,不用保存進文件)

MyJPanel mp=null;

public static void main(String[] args)

{

Tank1 t1=new Tank1();

// t1.BuildWorld();

}

public Tank1 ()

{

mp=new MyJPanel();

this.add(mp);

String v="";//

System.out.println();

Scanner ini=new? Scanner(System.in);

v= ini.next();

if(v.equals("x"))

{

System.out.print("載入");

mp.BuildWorld();

}

if(v.equals("d"))

{

mp.BuildWorld();

mp.duqu();

System.out.print("讀取");

}

Thread t=new Thread(mp);//啟動面板線程

t.start();

this.addKeyListener(mp);

this.setSize(1600,1000);

this.setLocation(1,1);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

class MyJPanel extends JPanel implements KeyListener,Runnable//?Perception感知主界面

{

ImageIcon lawn = new ImageIcon("000草地.png");

ImageIcon?? person = new ImageIcon("ren.png");

ImageIcon green_trees = new ImageIcon("101綠樹.png");

ImageIcon [][] plane = new ImageIcon[100][100];

int [][]map=new int [100][100];

int x=8;

int y=8;

MyJPanel()

{

}

private void baocun()//游戲保存

{

// TODO 自動生成的方法存根

File f=null;

FileOutputStream fx=null;

//DataOutputStream fx=null;

try

{

f=new File("D:\\map999999999999.txt");

fx=new FileOutputStream(f);

//fx=new DataOutputStream (f);

for(int i=0;i<100;i++)

{

for(int j=0;j<100;j++)

{

if(mp.plane[i][j]==mp.person)

{

mp.map[i][j]=0;

//System.out.print(p.map[i][j]);

}

if(mp.plane[i][j]==mp.green_trees)

{

mp.map[i][j]=1;

System.out.print(mp.map[i][j]+"?? ");

}

fx.write(mp.map[i][j]);

//強制流中的數據完全輸出完

}

}

System.out.print("保存X Y"+this.x+" "+this.y);

fx.write(this.x);

fx.write(this.y);

fx.flush();

//關閉輸出流

fx.close();

}

catch(Exception e)

{

}

}

public void duqu()游戲讀取

{

FileInputStream in=null;

DataInputStream inn=null;

try

{

in=new FileInputStream("D:\\map999999999999.txt");

inn=new DataInputStream (in);

for(int i=0;i<100;i++)

{

for(int j=0;j<100;j++)

{

mp.map[i][j]=inn.read();

if(map[i][j]==0)

{

mp.plane[i][j]=this.lawn;

}

if(map[i][j]==1)

{

mp.plane[i][j]=mp.green_trees;

}

//強制流中的數據完全輸出完

}

}

mp.x=inn.read();

mp.y=inn.read();

System.out.print("讀取"+this.x+"?? "+this.y);

//關閉輸出流

inn.close();

}

catch(Exception e)

{

}

}

public void keyTyped(KeyEvent e){}//鍵盤監聽

public void keyReleased(KeyEvent e){}

public void keyPressed(KeyEvent e)

{

if(e.getKeyCode()==KeyEvent.VK_S)

{

this.xia();

System.out.print("xxxxx"+this.x+this.y+"??? ");

}

if(e.getKeyCode()==KeyEvent.VK_W)

{

this.shang();

System.out.print("xxxxx"+this.x+this.y+"??? ");

}

if(e.getKeyCode()==KeyEvent.VK_A)

{

mp.zuo();

System.out.print("xxxxx"+this.x+this.y+"??? ");

}

if(e.getKeyCode()==KeyEvent.VK_D)

{

mp.you();

System.out.print("xxxxx"+this.x+this.y+"??? ");

}

if(e.getKeyCode()==KeyEvent.VK_B)

{

mp.baocun();

System.out.print("保存");

}

}

public void run()

{

while(true)

{

try?{

Thread.sleep(100);}

catch (Exception e) {}

this.repaint();

}

}

public void zuo()

{

this.x=this.x-1;

}

public void you()

{

this.x=this.x+1;

}

public void xia()

{

this.y=this.y+1;

}

public void shang()

{

this.y=this.y-1;

}

public void paint(Graphics g)

{?super.paint(g);

for(int i=0;i<20;i++)

{

for(int j=0;j<20;j++)

{

g.drawImage(this.plane[i+this.x][j+y].getImage(), i*55, j*55, 50,50, null);

//g.drawImage(icon1.getImage(), this.x,this.y , 50,50, null);

g.drawImage(this.person.getImage(),this.x*55 ,this.y*55, 50,50, null);

}

}

}

public void BuildWorld()//生成地圖的方法

{

for(int i=0;i<100;i++)

{

for(int j=0;j<100;j++)

{

plane[i][j]=lawn;

}

}

this.plane[5][5]=green_trees;

this.plane[6][6]=green_trees;

this.plane[8][8]=green_trees;

}

}

}

總結

以上是生活随笔為你收集整理的java rpg项目代码_java rpg游戏代码(移动保存读取)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。