我对编程有点陌生,想尝试制作一个比我以前的游戏更难的盒子式 2d 游戏来学习。唉,我还是新手,所以如果可能的话,请降低你的答案。
几个小时以来,我一直在玩弄哈希图,但似乎无法弄清楚为什么将我的密钥提供给 java 不会给我它的价值。
package main;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
}
public Map<Point, Integer> Blocks = new HashMap<Point, Integer>();
int x = 0;
int y = 0;
while (active == true) {
Point Apple = new Point(x, y);
Blocks.put(Apple, 1);
if (x <= 800) {
x += 32;
} else {
x = 0;
y += 32;
}
if (y > 600) {
active = false;
}
}
MouseX = (Mouse.getX() / 32) * 32;
MouseY = (Mouse.getY() / 32) * 32;
Point rawr = new Point(MouseX, MouseY);
if (Blocks.containsKey(rawr)) {
y = Blocks.get(rawr);
}
结果,我得到 y = 0 而不是 y = 1。感谢您提供的任何帮助。