❶ 為什麼我用java編寫的推箱子小游戲里邊的箱子碰到牆壁時總是會有一部分進入牆體呢
你在推箱子的時候要判斷一下箱子和牆體是否沖撞了,如果有沖撞,箱子就不能再往這個方向推了
❷ 本人需要用JAVA編寫一個推箱子的小游戲 源代碼有了 但是缺少做推箱子這小游戲的圖片
package com.txz1;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Txz {
public static void main(String[] args) {
JFrame frame = new JFrame("������1.0");//����
frame.setBounds(100, 20, 20 * 48 + 16, 14 * 48 + 38);//���ý���λ�úʹ�С
JPanel panel = new JPanel();//��壬�൱������
panel.setBackground(Color.red);//������ɫ
frame.setContentPane(panel);
panel.setLayout(null);//�Զ��壬���λ��
//�������
ImageIcon boxImg = new ImageIcon("box2.PNG");
JLabel box = new JLabel(boxImg);//��ǩ���൱������
panel.add(box);
box.setBounds(5 * 48, 3 * 48, 48, 48);
//��ӹ���
ImageIcon workerImg = new ImageIcon("workerDown2.png");
JLabel worker = new JLabel(workerImg);
panel.add(worker);
worker.setBounds(8 * 48, 8 * 48, 48, 48);
//����ϰ���
ImageIcon goalImg = new ImageIcon("goal2.png");
JLabel goal = new JLabel(goalImg);
panel.add(goal);
goal.setBounds(7 * 48, 6 * 48, 48, 48);
//���Χǽ
ImageIcon wallImg = new ImageIcon("wall2.PNG");
JLabel[] walls = new JLabel[100];
for (int i = 0; i < walls.length; i++) {
walls[i] = new JLabel(wallImg);
}
int index = 0;//������������ͳ��Χǽ����
for (int i = 0; i < 20; i++) {
panel.add(walls[index]);
walls[index].setBounds(i * 48, 0, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(i * 48, 13 * 48, 48, 48);
index++;
}
for (int i = 0; i < 12; i++) {
panel.add(walls[index]);
walls[index].setBounds(0, (i + 1) * 48, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(19 * 48, (i + 1) * 48, 48, 48);
index++;
}
for (int i = 0, j = 0; i < 5; i++, j += 2) {
panel.add(walls[index]);
walls[index].setBounds((i + 2) * 48, j * 48, 48, 48);
index++;
}
for (int i = 0, j = 10; i < 5; i++, j--) {
panel.add(walls[index]);
walls[index].setBounds((i + 12) * 48, j * 48, 48, 48);
index++;
}
//����Ϊ�ɼ��
frame.setVisible(true);
}
}
❸ Java推箱子怎麼寫啊
這是我之前寫的一篇java實現推箱子演算法的文章,簡單的給你看一下:
《推箱子游戲》是一款益智游戲,游戲目標是搬運工自己來找出到某個位置的最短路徑,然後自己走過去。
最後完成地圖顯示問題,每個節點存儲自己父親節點的地址,當節點發現自己已經完成之後根據地址向上查找直到樹頂,望採納,謝謝。