Java實(shí)現(xiàn)經(jīng)典俄羅斯方塊游戲
前言
俄羅斯方塊是一個(gè)最初由阿列克謝帕吉特諾夫在蘇聯(lián)設(shè)計(jì)和編程的益智類(lèi)視頻游戲。
《俄羅斯方塊》的基本規(guī)則是移動(dòng)、旋轉(zhuǎn)和擺放游戲自動(dòng)輸出的各種方塊,使之排列成完整的一行或多行并且消除得分。
用java語(yǔ)言實(shí)現(xiàn),采用了swing技術(shù)進(jìn)行了界面化處理,設(shè)計(jì)思路用了面向?qū)ο笏枷搿?/p>
主要需求
由小方塊組成的不同形狀的板塊陸續(xù)從屏幕上方落下來(lái),玩家通過(guò)調(diào)整板塊的位置和方向,使它們?cè)谄聊坏撞科闯鐾暾囊粭l或幾條。這些完整的橫條會(huì)隨即消失,給新落下來(lái)的板塊騰出空間,與此同時(shí),玩家得到分?jǐn)?shù)獎(jiǎng)勵(lì)。沒(méi)有被消除掉的方塊不斷堆積起來(lái),一旦堆到屏幕頂端,玩家便告輸,游戲結(jié)束。
主要設(shè)計(jì)
1、用鍵盤(pán)操作,"←"左移一格;"→"右移一格;"↑"旋轉(zhuǎn)方塊;↓ 方塊丟下(方塊下落到底)
2、一旦堆到屏幕頂端,游戲結(jié)束
3、設(shè)計(jì)不同的方塊
4、設(shè)計(jì)方塊下落的速度
5、設(shè)計(jì)分?jǐn)?shù)系統(tǒng)
功能截圖
游戲啟動(dòng)頁(yè)

開(kāi)始游戲


游戲結(jié)束

代碼實(shí)現(xiàn)
窗口設(shè)計(jì)類(lèi)
public class Windows extends JFrame {
private Toolkit took = null;
private static int width= 470; //寬
private static int height = 680; //高
private static int width_g = 10; //游戲區(qū)域
private static int height_g = 22; //
private static int size = 30; //方塊大小
private static int space= 10; //坐標(biāo)距邊界間隔
Map map = new Map(width_g,height_g);//地圖坐標(biāo)
ArrayList <Diamonds> ds = new ArrayList<Diamonds>();//方塊數(shù)組
private boolean game=false; //游戲開(kāi)始
private int flag = 0; //游戲狀態(tài)【暫停:0,繼續(xù):1】
private JLabel jl2;
private JButton jb1;
private int speed = 500; //速度
private int score = 0; //分?jǐn)?shù)
private int[] scores = new int[4]; //排名
public static void main(String[] args) {
Windows win = new Windows();
win.run();
}
public void run(){
init();
try {
while(true) {
if(game&&flag==1) {
ds.get(ds.size()-2).movement(map);
if(!ds.get(ds.size()-2).isStatus()) {
//判斷游戲是否失敗
if(ds.get((ds.size()-2)).getY()<=3) {
game=false;
//重置游戲參數(shù)
ds = new ArrayList<Diamonds>();
map = new Map(width_g,height_g);
JOptionPane.showMessageDialog(new JFrame().getContentPane(), "游戲結(jié)束!\n您獲得【"+score+"】點(diǎn)分?jǐn)?shù)");
score=0;
jl2.setText("分?jǐn)?shù): "+score);
jb1.setEnabled(true);
jb1.setText("重新開(kāi)始");
}else {
//消除判斷
score=map.dispel(score);
jl2.setText("分?jǐn)?shù): "+score);
//生成新方塊
Diamonds diamonds = new Diamonds(width_g);
ds.add(diamonds);
}
}
}
repaint();
Thread.sleep(speed);
}
}catch(InterruptedException e) {
e.printStackTrace();
}
}
//窗口加載
public void init() {
//界面設(shè)置
this.setTitle("俄羅斯方塊"); //標(biāo)題
this.setSize(width, height); //界面大小
took = Toolkit.getDefaultToolkit();
Dimension dm = took.getScreenSize();
int swidth = (dm.width - width)/2;
int sheight = (dm.height - height)/2;
this.setLocation(swidth, sheight);
//容器
JPanel p1 = new JPanel(); //地圖
JPanel p2 = new JPanel(); //俄羅斯方塊控制界面
JPanel p3 = new JPanel(); //按鈕
JPanel p4 = new JPanel(); //說(shuō)明
//圖形繪制容器
JPanel contentPane = new PaintPanel();
setContentPane(contentPane);
//標(biāo)簽
JLabel jl1 = new JLabel("俄羅斯方塊控制界面");
jl2 = new JLabel("分?jǐn)?shù): "+score);
JLabel jl3 = new JLabel("游戲說(shuō)明:");
//按鈕
jb1 = new JButton("游戲開(kāi)始");
JButton jb2 = new JButton("難度選擇");
JButton jb3 = new JButton("繼續(xù)/暫停");
JButton jb4 = new JButton("游戲退出");
JButton jb5 = new JButton("高級(jí)");
JButton jb6 = new JButton("中級(jí)");
JButton jb7 = new JButton("低級(jí)");
JButton jb8 = new JButton("顯示排名");
//文本
JTextArea jta = new JTextArea("1.點(diǎn)擊【游戲開(kāi)始】按鈕開(kāi)始游戲。"
+ "\n2.游戲中可隨時(shí)暫停,使用方向鍵可繼續(xù)游戲"
+ "\n3.用鍵盤(pán)操作,\"←\"左移一格;\"→\"右移一格;\"↑\"旋轉(zhuǎn)方塊;↓ 方塊丟下(方塊下落到底)",50,9);
jta.setSelectionColor(Color.RED);
jta.setEditable(false);
jta.setLineWrap(true);
//布局
this.setLayout(new BorderLayout(5,5));
p2.setLayout(new GridLayout(2,1,5,5));
p3.setLayout(new GridLayout(10,1,5,5));
p4.setLayout(new BorderLayout(5,5));
//設(shè)置邊界
p2.setBorder(BorderFactory.createEmptyBorder(20,20,15,15));
//背景顏色
p1.setBackground(new Color(255,255,255,0));
p2.setBackground(new Color(255,255,255,0));
p3.setBackground(new Color(255,255,255,0));
p4.setBackground(new Color(255,255,255,0));
jta.setBackground(Color.WHITE);
//添加容器/組件
p3.add(jl1);
p3.add(jl2);
p3.add(jb1);
//p3.add(jb2);
p3.add(jb3);
p3.add(jb4);
p3.add(jb8);
p4.add(jl3,BorderLayout.NORTH);
p4.add(jta,BorderLayout.CENTER);
p2.add(p3);
p2.add(p4);
//主容器
this.add(p1,BorderLayout.CENTER);
this.add(p2,BorderLayout.EAST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setUndecorated(true);
this.setVisible(true);
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
//游戲開(kāi)始時(shí)按鍵有效
if(ds.size()!=0) {
int type = ds.get(ds.size()-2).getType();
int x = ds.get(ds.size()-2).getX();
if(e.getKeyCode()==KeyEvent.VK_LEFT) {
ds.get(ds.size()-2).left(map);
}
if(e.getKeyCode()==KeyEvent.VK_RIGHT) {
ds.get(ds.size()-2).right(map);
}
if(e.getKeyCode()==KeyEvent.VK_UP) {
if(type<=1) {
//可能在轉(zhuǎn)換過(guò)程發(fā)生越界的解決辦法
if(type==1) {
if(x>=width_g-3) {
ds.get(ds.size()-2).setX(width_g-4);
}
}
ds.get(ds.size()-2).setType(type==0?1:0);
}else if(type<=5) {
if(type==3||type==5) {
if(x==width_g-2) {
ds.get(ds.size()-2).setX(width_g-3);
}
}
ds.get(ds.size()-2).setType(type==5?2:++type);
}else if(type<=9) {
ds.get(ds.size()-2).setType(type==9?6:++type);
}else if(type<=10) {
ds.get(ds.size()-2).setType(10);
}else if(type<=14) {
if(type==12||type==14) {
if(x==width_g-2) {
ds.get(ds.size()-2).setX(width_g-3);
}
}
ds.get(ds.size()-2).setType(type==14?11:++type);
}else if(type<=18) {
if(type==16||type==18) {
if(x==width_g-2) {
ds.get(ds.size()-2).setX(width_g-3);
}
}
ds.get(ds.size()-2).setType(type==18?15:++type);
}
}
}
if(e.getKeyCode()==KeyEvent.VK_DOWN) {
speed = 100;
}
}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_DOWN) {
speed = 500;
}
}
});
//游戲開(kāi)始
jb1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
requestFocus();
//生成第一個(gè)方塊
Diamonds diamonds = new Diamonds(width_g);
ds.add(diamonds);
//生成提示方塊
Diamonds point = new Diamonds(width_g);
ds.add(point);
//游戲開(kāi)始
game=true;
flag=1;
//游戲開(kāi)始后禁止使用
jb1.setEnabled(false);
}
});
//退出
jb4.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.exit(0);
}
});
//暫停/繼續(xù)
jb3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(flag==0) {
flag=1;
}else {
flag=0;
}
requestFocus();
}
});
}
//重寫(xiě)paintComponent(圖形繪制)
private class PaintPanel extends JPanel{
@Override
protected void paintComponent(Graphics g) {
//還原size的值
size=30;
//繪制邊界
g.setColor(Color.GRAY);
g.fillRect(0, 0, width-149, height-1);
g.setColor(Color.PINK);
g.fillRect(width-149, 0, 148, height-1);
g.setColor(Color.BLACK);
g.drawLine(width-149, 0, width-149, height-1);
g.drawRect(0, 0, width-1, height-1);
g.setColor(Color.WHITE);
g.fillRect(space, space, width_g*size, height_g*size);
g.setColor(Color.BLACK);
g.drawRect(space, space, width_g*size, height_g*size);
g.drawLine(space, space+3*size, space+width_g*size, space+3*size);
//提示框
g.setColor(Color.WHITE);
g.fillRect(width-135, 222, 4*size, 4*size);
g.setColor(Color.BLACK);
g.drawRect(width-135, 222, 4*size, 4*size);
if(game) {
Color[][] color_xy = map.getColor();
int[][] map_xy = map.getMap();
//繪制地圖
for(int i=0;i<width_g;i++) {
for(int j=0;j<height_g;j++) {
// 繪制網(wǎng)格線(xiàn),可注釋
g.drawRect(i*size+space, j*size+space, size, size);
if(map_xy[i][j]==1) {
//g.setColor(color_xy[i][j]);
g.setColor(Color.BLUE);
g.fillRect(i*size+space, j*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(i*size+space, j*size+space, size, size);
}
}
}
//繪制可移動(dòng)的方塊
int type=ds.get(ds.size()-2).getType();
int x=ds.get(ds.size()-2).getX();
int y=ds.get(ds.size()-2).getY();
Color color = ds.get(ds.size()-2).getColor();
//繪制提示方塊
int typeO=ds.get(ds.size()-1).getType();
int xO=width-100;
int yO=260;
Color colorO = ds.get(ds.size()-1).getColor();
//繪制圖形
//圖形一,兩種形態(tài)
if(type==0) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+2)*size+space, y*size+space, size, size);
g.fillRect((x+3)*size+space, y*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+2)*size+space, y*size+space, size, size);
g.drawRect((x+3)*size+space, y*size+space, size, size);
}
if(type==1) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect(x*size+space, (y+2)*size+space, size, size);
g.fillRect(x*size+space, (y+3)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect(x*size+space, (y+2)*size+space, size, size);
g.drawRect(x*size+space, (y+3)*size+space, size, size);
}
//圖形二,四種形態(tài)
if(type==2) {
g.setColor(color);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect((x+2)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect((x+2)*size+space, (y+1)*size+space, size, size);
}
if(type==3) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect(x*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect(x*size+space, (y+2)*size+space, size, size);
}
if(type==4) {
g.setColor(color);
g.fillRect((x)*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+2)*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+2)*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
}
if(type==5) {
g.setColor(color);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+2)*size+space, size, size);
}
//圖形三,四種形態(tài)
if(type==6) {
g.setColor(color);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
}
if(type==7) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
}
if(type==8) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
}
if(type==9) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
}
//圖形四,一種形態(tài)
if(type==10) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
}
//圖形五,三種形態(tài)
if(type==11) {
g.setColor(color);
g.fillRect((x+2)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect((x+2)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect((x+2)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect((x+2)*size+space, (y+1)*size+space, size, size);
}
if(type==12) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+2)*size+space, size, size);
}
if(type==13) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+2)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+2)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
}
if(type==14) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect(x*size+space, (y+2)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect(x*size+space, (y+2)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+2)*size+space, size, size);
}
//圖形六,三種形態(tài)
if(type==15) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect((x+2)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect((x+2)*size+space, (y+1)*size+space, size, size);
}
if(type==16) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect(x*size+space, (y+1)*size+space, size, size);
g.fillRect(x*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect(x*size+space, (y+1)*size+space, size, size);
g.drawRect(x*size+space, (y+2)*size+space, size, size);
}
if(type==17) {
g.setColor(color);
g.fillRect(x*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+2)*size+space, y*size+space, size, size);
g.fillRect((x+2)*size+space, (y+1)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect(x*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+2)*size+space, y*size+space, size, size);
g.drawRect((x+2)*size+space, (y+1)*size+space, size, size);
}
if(type==18) {
g.setColor(color);
g.fillRect((x+1)*size+space, y*size+space, size, size);
g.fillRect((x+1)*size+space, (y+1)*size+space, size, size);
g.fillRect(x*size+space, (y+2)*size+space, size, size);
g.fillRect((x+1)*size+space, (y+2)*size+space, size, size);
g.setColor(Color.BLACK);
g.drawRect((x+1)*size+space, y*size+space, size, size);
g.drawRect((x+1)*size+space, (y+1)*size+space, size, size);
g.drawRect(x*size+space, (y+2)*size+space, size, size);
g.drawRect((x+1)*size+space, (y+2)*size+space, size, size);
}
//繪制提示圖形
size=(int)(size/1.5);
if(typeO==0) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO+size, yO, size, size);
g.fillRect(xO+size*2, yO, size, size);
g.fillRect(xO+size*3, yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO+size, yO, size, size);
g.drawRect(xO+size*2, yO, size, size);
g.drawRect(xO+size*3, yO, size, size);
}
if(typeO==1) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(xO, 2*size+yO, size, size);
g.fillRect(xO, 3*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(xO, 2*size+yO, size, size);
g.drawRect(xO, 3*size+yO, size, size);
}
//圖形二,四種形態(tài)
if(typeO==2) {
g.setColor(colorO);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(2*size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(2*size+xO, size+yO, size, size);
}
if(typeO==3) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(xO, 2*size+yO, size, size);
}
if(typeO==4) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(2*size+xO, yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(2*size+xO, yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
}
if(typeO==5) {
g.setColor(colorO);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(size+xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(size+xO, 2*size+yO, size, size);
}
//圖形三,四種形態(tài)
if(typeO==6) {
g.setColor(colorO);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
}
if(typeO==7) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
}
if(typeO==8) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
}
if(typeO==9) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
}
//圖形四,一種形態(tài)
if(typeO==10) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
}
//圖形五,三種形態(tài)
if(typeO==11) {
g.setColor(colorO);
g.fillRect(2*size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(2*size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(2*size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(2*size+xO, size+yO, size, size);
}
if(typeO==12) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(size+xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(size+xO, 2*size+yO, size, size);
}
if(typeO==13) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(2*size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(2*size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
}
if(typeO==14) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(xO, 2*size+yO, size, size);
g.fillRect(size+xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(xO, 2*size+yO, size, size);
g.drawRect(size+xO, 2*size+yO, size, size);
}
//圖形六,三種形態(tài)
if(typeO==15) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(2*size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(2*size+xO, size+yO, size, size);
}
if(typeO==16) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(xO, size+yO, size, size);
g.fillRect(xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(xO, size+yO, size, size);
g.drawRect(xO, 2*size+yO, size, size);
}
if(typeO==17) {
g.setColor(colorO);
g.fillRect(xO, yO, size, size);
g.fillRect(size+xO, yO, size, size);
g.fillRect(2*size+xO, yO, size, size);
g.fillRect(2*size+xO, size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(xO, yO, size, size);
g.drawRect(size+xO, yO, size, size);
g.drawRect(2*size+xO, yO, size, size);
g.drawRect(2*size+xO, size+yO, size, size);
}
if(typeO==18) {
g.setColor(colorO);
g.fillRect(size+xO, yO, size, size);
g.fillRect(size+xO, size+yO, size, size);
g.fillRect(xO, 2*size+yO, size, size);
g.fillRect(size+xO, 2*size+yO, size, size);
g.setColor(Color.BLACK);
g.drawRect(size+xO, yO, size, size);
g.drawRect(size+xO, size+yO, size, size);
g.drawRect(xO, 2*size+yO, size, size);
g.drawRect(size+xO, 2*size+yO, size, size);
}
}
}
}
}方塊及相關(guān)事件設(shè)計(jì)類(lèi)
/*
* 方塊
*/
public class Diamonds {
private int x; //坐標(biāo)x
private int y; //坐標(biāo)y
private Color color; //顏色
private int type; //類(lèi)型
Random rm = new Random();
private boolean status=true;//狀態(tài)
private int width;
public Diamonds() {
super();
// TODO Auto-generated constructor stub
}
//方塊初始化
public Diamonds(int width) {
super();
this.width = width;
this.x = rm.nextInt(width-3);
this.y = 0;
//this.color = Color.GREEN;
this.color = new Color(rm.nextInt(255),rm.nextInt(255),rm.nextInt(255));
this.type = rm.nextInt(16);
}
//向左移動(dòng)
public void left(Map map) {
int[][]map_xy = map.getMap();
if(x!=0) {
switch(type){
case 0:if(map_xy[x-1][y]==0) {x--;} break;
case 1:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0 && map_xy[x-1][y+2]==0 && map_xy[x-1][y+3]==0) {x--;} break;
case 2:if(map_xy[x][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 3:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0 && map_xy[x-1][y+2]==0) {x--;} break;
case 4:if(map_xy[x-1][y]==0 && map_xy[x][y+1]==0) {x--;} break;
case 5:if(map_xy[x][y]==0 && map_xy[x-1][y+1]==0 && map_xy[x][y+2]==0) {x--;} break;
case 6:if(map_xy[x][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 7:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 8:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 9:if(map_xy[x-1][y]==0 && map_xy[x][y+1]==0) {x--;} break;
case 10:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 11:if(map_xy[x+1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 12:if(map_xy[x-1][y]==0 && map_xy[x][y+1]==0 && map_xy[x][y+2]==0) {x--;} break;
case 13:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 14:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0 && map_xy[x-1][y+2]==0) {x--;} break;
case 15:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0) {x--;} break;
case 16:if(map_xy[x-1][y]==0 && map_xy[x-1][y+1]==0 && map_xy[x-1][y+2]==0) {x--;} break;
case 17:if(map_xy[x-1][y]==0 && map_xy[x+1][y+1]==0) {x--;} break;
case 18:if(map_xy[x][y]==0 && map_xy[x][y+1]==0 && map_xy[x-1][y+2]==0) {x--;} break;
}
}
}
//向右移動(dòng)
public void right(Map map) {
int[][]map_xy = map.getMap();
switch(type) {
case 0: if(x<width-4 && map_xy[x+4][y]==0) {x++;}break;
case 1: if(x<width-1 && map_xy[x+1][y]==0 && map_xy[x+1][y+1]==0 && map_xy[x+1][y+2]==0 && map_xy[x+1][y+3]==0) {x++;}break;
case 2: if(x<width-3 && map_xy[x+2][y]==0 && map_xy[x+3][y+1]==0) {x++;}break;
case 3: if(x<width-2 && map_xy[x+1][y]==0 && map_xy[x+2][y+1]==0 && map_xy[x+1][y+2]==0) {x++;}break;
case 4: if(x<width-3 && map_xy[x+3][y]==0 && map_xy[x+2][y+1]==0) {x++;}break;
case 5: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0 && map_xy[x+2][y+2]==0) {x++;}break;
case 6: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0) {x++;}break;
case 7: if(x<width-2 && map_xy[x+1][y]==0 && map_xy[x+2][y+1]==0) {x++;}break;
case 8: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+1][y+1]==0) {x++;}break;
case 9: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0) {x++;}break;
case 10: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0) {x++;}break;
case 11: if(x<width-3 && map_xy[x+3][y]==0 && map_xy[x+3][y+1]==0) {x++;}break;
case 12: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0 && map_xy[x+2][y+2]==0) {x++;}break;
case 13: if(x<width-3 && map_xy[x+3][y]==0 && map_xy[x+1][y+1]==0) {x++;}break;
case 14: if(x<width-2 && map_xy[x+1][y]==0 && map_xy[x+1][y+1]==0 && map_xy[x+2][y+2]==0) {x++;}break;
case 15: if(x<width-3 && map_xy[x+1][y]==0 && map_xy[x+3][y+1]==0) {x++;}break;
case 16: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+1][y+1]==0 && map_xy[x+1][y+2]==0) {x++;}break;
case 17: if(x<width-3 && map_xy[x+3][y]==0 && map_xy[x+3][y+1]==0) {x++;}break;
case 18: if(x<width-2 && map_xy[x+2][y]==0 && map_xy[x+2][y+1]==0 && map_xy[x+2][y+2]==0) {x++;}break;
}
}
//向下移動(dòng)
public void movement(Map map){
int[][]map_xy = map.getMap();
Color[][]color_xy = map.getColor();
//向下移動(dòng)一格
switch(type) {
case 0:
if(map_xy[x][y+1]==0 && map_xy[x+1][y+1]==0 && map_xy[x+2][y+1]==0 && map_xy[x+3][y+1]==0){
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+2][y]=1;
map_xy[x+3][y]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+2][y]=color;
color_xy[x+3][y]=color;
status=false;
}
break;
case 1:
if(map_xy[x][y+4]==0){
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x][y+1]=1;
map_xy[x][y+2]=1;
map_xy[x][y+3]=1;
color_xy[x][y]=color;
color_xy[x][y+1]=color;
color_xy[x][y+2]=color;
color_xy[x][y+3]=color;
status=false;
}
break;
case 2:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0 && map_xy[x+2][y+2]==0) {
y+=1;
}else {
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
map_xy[x+2][y+1]=1;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
color_xy[x+2][y+1]=color;
status=false;
}
break;
case 3:
if(map_xy[x][y+3]==0 && map_xy[x+1][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
map_xy[x][y+2]=1;
color_xy[x][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
color_xy[x][y+2]=color;
status=false;
}
break;
case 4:
if(map_xy[x][y+1]==0 && map_xy[x+1][y+2]==0 && map_xy[x+2][y+1]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+2][y]=1;
map_xy[x+1][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+2][y]=color;
color_xy[x+1][y+1]=color;
status=false;
}
break;
case 5:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+3]==0) {
y+=1;
}else {
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
map_xy[x+1][y+2]=1;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
color_xy[x+1][y+2]=color;
status=false;
}
break;
case 6:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0) {
y+=1;
}else {
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
status=false;
}
break;
case 7:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
color_xy[x][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
status=false;
}
break;
case 8:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+1]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
status=false;
}
break;
case 9:
if(map_xy[x][y+1]==0 && map_xy[x+1][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+1][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+1][y+1]=color;
status=false;
}
break;
case 10:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
status=false;
}
break;
case 11:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0 && map_xy[x+2][y+2]==0) {
y+=1;
}else {
map_xy[x+2][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
map_xy[x+2][y+1]=1;
color_xy[x+2][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
color_xy[x+2][y+1]=color;
status=false;
}
break;
case 12:
if(map_xy[x][y+1]==0 && map_xy[x+1][y+3]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+1][y+1]=1;
map_xy[x+1][y+2]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+1][y+1]=color;
color_xy[x+1][y+2]=color;
status=false;
}
break;
case 13:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+1]==0 && map_xy[x+2][y+1]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+2][y]=1;
map_xy[x][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+2][y]=color;
color_xy[x][y+1]=color;
status=false;
}
break;
case 14:
if(map_xy[x][y+3]==0 && map_xy[x+1][y+3]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x][y+1]=1;
map_xy[x][y+2]=1;
map_xy[x+1][y+2]=1;
color_xy[x][y]=color;
color_xy[x][y+1]=color;
color_xy[x][y+2]=color;
color_xy[x+1][y+2]=color;
status=false;
}
break;
case 15:
if(map_xy[x][y+2]==0 && map_xy[x+1][y+2]==0 && map_xy[x+2][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x][y+1]=1;
map_xy[x+1][y+1]=1;
map_xy[x+2][y+1]=1;
color_xy[x][y]=color;
color_xy[x][y+1]=color;
color_xy[x+1][y+1]=color;
color_xy[x+2][y+1]=color;
status=false;
}
break;
case 16:
if(map_xy[x][y+3]==0 && map_xy[x+1][y+1]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x][y+1]=1;
map_xy[x][y+2]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x][y+1]=color;
color_xy[x][y+2]=color;
status=false;
}
break;
case 17:
if(map_xy[x][y+1]==0 && map_xy[x+1][y+1]==0 && map_xy[x+2][y+2]==0) {
y+=1;
}else {
map_xy[x][y]=1;
map_xy[x+1][y]=1;
map_xy[x+2][y]=1;
map_xy[x+2][y+1]=1;
color_xy[x][y]=color;
color_xy[x+1][y]=color;
color_xy[x+2][y]=color;
color_xy[x+2][y+1]=color;
status=false;
}
break;
case 18:
if(map_xy[x][y+3]==0 && map_xy[x+1][y+3]==0) {
y+=1;
}else {
map_xy[x+1][y]=1;
map_xy[x+1][y+1]=1;
map_xy[x][y+2]=1;
map_xy[x+1][y+2]=1;
color_xy[x+1][y]=color;
color_xy[x+1][y+1]=color;
color_xy[x][y+2]=color;
color_xy[x+1][y+2]=color;
status=false;
}
break;
}
map.setMap(map_xy);
map.setColor(color_xy);
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
}總結(jié)
通過(guò)此次的《俄羅斯方塊》游戲?qū)崿F(xiàn),讓我對(duì)swing的相關(guān)知識(shí)有了進(jìn)一步的了解,對(duì)java這門(mén)語(yǔ)言也有了比以前更深刻的認(rèn)識(shí)。
java的一些基本語(yǔ)法,比如數(shù)據(jù)類(lèi)型、運(yùn)算符、程序流程控制和數(shù)組等,理解更加透徹。java最核心的核心就是面向?qū)ο笏枷?,?duì)于這一個(gè)概念,終于悟到了一些。
以上就是Java實(shí)現(xiàn)經(jīng)典俄羅斯方塊游戲的詳細(xì)內(nèi)容,更多關(guān)于Java俄羅斯方塊的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SpringBoot實(shí)現(xiàn)前后端分離國(guó)際化的示例詳解
Springboot國(guó)際化可以幫助使用者在不同語(yǔ)言環(huán)境中構(gòu)建應(yīng)用程序,這樣應(yīng)用程序可以有效地適應(yīng)不同語(yǔ)言文化背景下的用戶(hù)需求。本文主要介紹了SpringBoot實(shí)現(xiàn)前后端分離國(guó)際化的方法,需要的可以參考一下2023-02-02
Java中實(shí)現(xiàn)String.padLeft和String.padRight的示例
本篇文章主要介紹了Java中實(shí)現(xiàn)String.padLeft和String.padRight,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
Java批量向PDF文件中添加圖像水印實(shí)現(xiàn)細(xì)節(jié)
這篇文章主要為大家介紹了Java批量向PDF文件中添加圖像水印實(shí)現(xiàn)細(xì)節(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
Java中操作Xml使用方法備忘錄(Hutool工具類(lèi)XmlUtil、XStream)
這篇文章主要給大家介紹了關(guān)于Java中操作Xml使用方法(Hutool工具類(lèi)XmlUtil、XStream)的相關(guān)資料,XMLUtil是一個(gè)工具類(lèi),主要用于讀取XML配置文件并提供相應(yīng)的操作方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11

