java打磚塊
① 用java語言設計打磚塊的小游戲需要用到哪些知識
要用到多線程技術
② Java大二課設,做一個打磚塊小游戲
很具體點嗎
③ JAVA有一款打磚塊的游戲,裡面還有人物對話,地點是在酒吧里,畫面真的挺精緻的,人物也長的好看,我
太容易了,這個游戲再走有個中文游戲500的游戲光碟裡面有,自己去買個,插能玩游戲的碟機裡面,就可以了!
④ java基礎知識編寫打磚塊游戲 使用eclipse 有分
你搞這些沒有什麼用的,難道你打算把你的打磚塊賣出去,趕快找家軟體公司上班吧,工作中才能學到更多。你還嫌程序員不夠累腦?去想這些累腦還得不到好處的東西?
⑤ 誰有java打磚塊的代碼,能記分,務必能運行
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Timer;
import javax.swing.JFrame;
public class dazhuankuai implements KeyListener
{
private JFrame jframe;
Canvas canvas;
board b;
int x;
int scoret;
int diffscore;
private int canvaswidth = 400;//canvas 的屬性
private int canvasheight =600;
dazhuankuai(){
jframe = new JFrame("打磚塊");
canvas = new Canvas();
canvas.setSize(canvaswidth, canvasheight);
canvas.addKeyListener(this);
jframe.add(canvas);
jframe.setBounds(320, 100,410, 500);
jframe.addKeyListener(this);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
begin();
}
public void begin()
{ b=new board(this);
b.run();
b.ball.vx=5;
b.ball.vy=10;
}
void paint()
{Graphics g = canvas.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, 400, 350);
for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
if(b.matrix[i][j]){
g.setColor(b.brickcolor[i][j]);
g.fillRect(i*20, j*10, 20, 10);
g.setColor(Color.white);
g.drawRect(i*20, j*10, 20, 10);}
g.setColor(Color.RED);
if(b.ball.y<=350)
g.fillOval(b.ball.x, b.ball.y, 10, 10);
}
void paintrect()
{Graphics g = canvas.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 350, 400, 10);
g.setColor(Color.black);
g.fillRect(b.leftpoint, 350, 50, 10);
}
void paintscore()
⑥ 在用JAVA編寫打磚塊小游戲,球的運動是一個線程,怎麼讓球改變方向
你說的很多東西都是你自己定義的方法與成員,其他人不知道是什麼意思。
判定的方法可以用用坐標范圍判定。球每次移動到一個新點立刻判定該點及周圍坐標是否有磚塊就行了,另外不要他繼承Thread來表示一個線程,用類實現Runnable介面 然後用一個新的Thread來執行類的實例。
⑦ 急需 JAVA 打磚塊的代碼 打包的最好
你有點誤解了 JAVA用到的英文單詞其實不多,你說的介面名、類名等都是可以自己起的只要自己看到這個名字能知道是什麼意思就行,沒必要非要用英語。 這年頭什麼東西都不會缺的 去網上隨便搜搜就是一堆書,但真的沒多大用。 f
⑧ 球幾個經典的JAVA游戲,最好是現在安卓機能安裝的那種包!!!
你好,經典的java游戲的話像俄羅斯方塊,超級泡泡龍,超級瑪麗,貪吃蛇,打磚塊,這些都好玩,而且像上圖這種就是可以安卓機玩的,可以去應用寶上找,上邊大多都是安卓系統的應用,無廣告,而且安裝包小,希望可以幫助到您。
⑨ Java程序解惑,希望大家幫幫忙,打磚塊游戲不能用鍵盤控制。開始和移動都不能。運行是用application嗎
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class ballApplet extends Applet implements Runnable {
Dimension d;
Font bFont = new Font("Helvetica", Font.BOLD, 24);
Font sFont = new Font("Helvetica", Font.BOLD, 14);
FontMetrics fmSmall, fmBig;
Graphics goff;
Image img;
Thread mThread;
boolean ingame = false;
int ballx, bally, batpos;
int batdpos = 0;
int balldx = 0, balldy = 0, dxval;
int iScroe, ballNum;
boolean[] showbrick;
int brickNumOfLine;
final int bWidth = 5;
final int batW = 20;
final int ballsize = 5;
final int batH = 5;
final int scoreH = 25;
final int brickW = 15;
final int brickH = 8;
final int space = 1;
final int backcol = 0x102040;
final int line = 4;
final int startline = 32;
public void init() {
Graphics g;
d=size();
setBackground(new Color(backcol));
brickNumOfLine = (d.width-2*bWidth)/(brickW +space);
d.width = brickNumOfLine*(brickW+space)+(2*bWidth);
g = getGraphics();
g.setFont(sFont);
fmSmall= g.getFontMetrics();
g.setFont(bFont);
fmBig = g.getFontMetrics();
showbrick = new boolean[brickNumOfLine*line];
this.addKeyListener(new BallGameKeyListener());
GameInit();
}
public void GameInit() {
batpos = (d.width - batW) / 2;
ballx = (d.width - ballsize) / 2;
bally = (d.height - ballsize - scoreH - 2 * bWidth);
iScroe = 0;
ballNum = 3;
dxval = 2;
if (Math.random() < 0.5)
balldx = dxval;
else
balldx = -dxval;
balldy = -dxval;
batdpos = 0;
InitBricks();
}
public void InitBricks() {
int i;
for (i = 0; i < line * brickNumOfLine; i++)
showbrick[i] = true;
}
// public boolean keyDown(Event e, int key) {
// if (ingame) {
// if (key == Event.LEFT)
// batdpos = -4;
// if (key == Event.RIGHT)
// batdpos = 4;
// if (key == Event.ESCAPE)
// ingame = false;
// } else {
// if (key == 's' || key == 'S') {
// ingame = true;
// GameInit();
// }
// }
// return true;
// }
//
// public boolean keyUp(Event e, int key) {
// if (key == Event.LEFT || key == Event.RIGHT)
// batdpos = 0;
// return true;
// }
public void paint(Graphics g) {
if (goff == null && d.width > 0 && d.height > 0) {
img = createImage(d.width, d.height);
goff = img.getGraphics();
}
if (goff == null || img == null)
return;
goff.setColor(new Color(backcol));
goff.fillRect(0, 0, d.width, d.height);
if (ingame)
PlayGame();
else
ShowIntroScreen();
g.drawImage(img, 0, 0, this);
}
public void PlayGame() {
MoveBall();
CheckBat();
CheckBricks();
DrawPlayField();
DrawBricks();
ShowScore();
}
public void ShowIntroScreen() {
MoveBall();
CheckBat();
CheckBricks();
BatDummyMove();
DrawPlayField();
DrawBricks();
ShowScore();
goff.setFont(bFont);
goff.setColor(new Color(96, 128, 255));
String s = "彈球游戲";
goff.drawString(s, (d.width - fmBig.stringWidth(s)) / 2, (d.height
- scoreH - bWidth) / 2 - 20);
goff.setFont(sFont);
goff.setColor(new Color(128, 255, 32));
s = "請按下'S'鍵開始游戲";
goff.drawString(s, (d.width - fmSmall.stringWidth(s)) / 2, (d.height
- scoreH - bWidth) / 2 + 30);
goff.setColor(new Color(255, 160, 64));
s = "使用方向鍵控制球拍移動";
goff.drawString(s, (d.width - fmSmall.stringWidth(s)) / 2, (d.height
- scoreH - bWidth) / 2 + 50);
}
public void DrawBricks() {
int i, j;
boolean nobricks = true;
int colorDelta = 255 / (line - 1);
for (j = 0; j < line; j++) {
for (i = 0; i < brickNumOfLine; i++) {
if (showbrick[j * brickNumOfLine + i]) {
nobricks = false;
goff.setColor(new Color(255, j * colorDelta, 255 - j
* colorDelta));
goff.fillRect(bWidth + i * (brickW + space), startline + j
* (brickH + space), brickW, brickH);
}
}
}
if (nobricks) {
InitBricks();
if (ingame)
iScroe += 100;
}
}
public void DrawPlayField() {
goff.setColor(Color.white);
goff.fillRect(0, 0, d.width, bWidth);
goff.fillRect(0, 0, bWidth, d.height);
goff.fillRect(d.width - bWidth, 0, bWidth, d.height);
goff.fillRect(0, d.height - bWidth, d.width, bWidth);
goff.fillRect(batpos, d.height - 2 * bWidth - scoreH, batW, batH);
goff.fillRect(ballx, bally, ballsize, ballsize);
}
public void ShowScore() {
goff.setFont(sFont);
goff.setColor(Color.white);
goff.drawString("得分:" + iScroe, 40, d.height - 10);
String s = "生命:" + ballNum;
goff
.drawString(s, d.width - 40 - fmSmall.stringWidth(s),
d.height - 10);
}
public void MoveBall() {
ballx += balldx;
bally += balldy;
if (bally <= bWidth) {
balldy = -balldy;
bally = bWidth;
}
if (bally >= (d.height - ballsize - scoreH)) {
if (ingame) {
ballNum--;
if (ballNum <= 0)
ingame = false;
}
ballx = batpos + (batW - ballsize) / 2;
bally = startline + line * (brickH + space);
balldy = dxval;
balldx = 0;
}
if (ballx >= (d.width - bWidth - ballsize)) {
balldx = -balldx;
ballx = d.width - bWidth - ballsize;
}
if (ballx <= bWidth) {
balldx = -balldx;
ballx = bWidth;
}
}
public void BatDummyMove() {
if (ballx < (batpos + 2))
batpos -= 3;
else if (ballx > (batpos + batW - 3))
batpos += 3;
}
public void CheckBat() {
batpos += batpos;
if (batpos < bWidth)
batpos = bWidth;
else if (batpos > (d.width - bWidth - batW))
batpos = (d.width - bWidth - batW);
if (bally >= (d.height - scoreH - 2 * bWidth - ballsize)
&& bally < (d.height - scoreH - 2 * bWidth)
&& (ballx + ballsize) >= batpos && ballx <= (batpos + batW)) {
bally = d.height - scoreH - ballsize - bWidth * 2;
balldy = -dxval;
balldx = CheckBatBounce(balldx, ballx - batpos);
}
}
public int CheckBatBounce(int dy, int delta) {
int sign;
int stepsize, i = -ballsize, j = 0;
stepsize = (ballsize + batW) / 8;
if (dy > 0)
sign = 1;
else
sign = -1;
while (i < batW && delta > i) {
i += stepsize;
j++;
}
switch (j) {
case 0:
case 1:
return -4;
case 2:
return -3;
case 7:
return 3;
case 3:
case 6:
return sign * 2;
case 4:
case 5:
return sign * 1;
default:
return 4;
}
}
public void CheckBricks() {
int i, j, x, y;
int xspeed = balldx;
if (xspeed < 0)
xspeed = -xspeed;
int ydir = balldy;
if (bally < (startline - ballsize)
|| bally > (startline + line * (space + brickH)))
return;
for (j = 0; j < line; j++) {
for (i = 0; i < brickNumOfLine; i++) {
if (showbrick[j * brickNumOfLine + i]) {
y = startline + j * (space + brickH);
x = bWidth + i * (space + brickW);
if (bally >= (y - ballsize) && bally < (y + brickH)
&& ballx >= (x - ballsize) && ballx < (x + brickW)) {
showbrick[j * brickNumOfLine + i] = false;
if (ingame)
iScroe += (line - j);
if (ballx >= (x - ballsize)
&& ballx <= (x - ballsize + 3)) {
balldx = -xspeed;
} else if (ballx <= (x + brickW - 1)
&& ballx >= (x + brickW - 4)) {
balldx = xspeed;
}
balldy = -ydir;
}
}
}
}
}
public void run() {
long starttime;
Graphics g = getGraphics();
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while (true) {
starttime = System.currentTimeMillis();
try {
paint(g);
starttime += 20;
Thread.sleep(Math
.max(0, starttime - System.currentTimeMillis()));
} catch (InterruptedException e) {
break;
}
}
}
public void start() {
if (mThread == null) {
mThread = new Thread(this);
mThread.start();
}
}
public void stop() {
if (mThread != null) {
mThread.stop();
mThread = null;
}
}
public static void main(String[] args) {
Frame frame = new Frame("彈球游戲");
ballApplet app = new ballApplet();
frame.add("Center", app);
frame.setSize(270, 350);
frame.validate();
frame.setVisible(true);
frame.addWindowListener(new WindowControl(app));
app.init();
app.start();
}
class BallGameKeyListener implements KeyListener{
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
// TODO Auto-generated method stub
if (ingame) {
switch(key){
case KeyEvent.VK_ESCAPE:
ingame = false;
break;
case KeyEvent.VK_RIGHT:
batdpos = 4;
break;
case KeyEvent.VK_LEFT:
batdpos = -4;
break;
}
} else {
if (key == KeyEvent.VK_S) {
ingame = true;
GameInit();
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT || key == KeyEvent.VK_RIGHT)
batdpos = 0;
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
}
class WindowControl extends WindowAdapter {
Applet app;
public WindowControl(Applet app) {
this.app = app;
}
public void WindowClosing(WindowEvent e) {
app.stop();
app.destroy();
System.exit(0);
}
}
給你+了個keyListener 然後按你的理念給你加入了按鍵判定。按S按鍵可以開始游戲但方向鍵不能移動應該是你的方法錯誤了你自己修改去把懶得看了。。太長了 一般畫可以移動的物體是直接按坐標來畫然後移動的時候+= 好哦這-= 控制坐標 我發現你的錯誤是你用batdpos這個變數去控制移動。。但你根本沒用這個變數去畫圖。。所以不能移動。。你自己去改把。。