java俄罗斯方块问题! 编程求助高手!! 5
高手来看看,帮帮我,问题怎么解决啊!谢谢!importjavax.swing.*;publicclassMain{publicstaticvoidmain(Stringa...
高手来看看,帮帮我,问题怎么解决啊! 谢谢!
import javax.swing.*;
public class Main {
public static void main(String args[]){
NewGame g = new NewGame();
GameTest gt = new GameTest();
TetrisPanel t = new TetrisPanel();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(290,400);
frame.add(g);
frame.setLayout(null);
frame.setVisible(true);
g.getTetro();
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Random;
/**
*
* @author Thinkpad
*/
public class NewGame extends JPanel implements Runnable{
Image [] pics;
String [] gifs = {"1.gif","222.gif"};
Image tetro1 = null;
Image tetro2 = null;
Image tetro1g= null;
int tetroX1;
int tetroX2;
int tetroY1;
int tetroY2;
int tetroYg;
int tetroY;
Thread game;
int type = new Random().nextInt(gifs.length);
public NewGame(){
pics = new Image[gifs.length] ;
int count = 0;
while (count<gifs.length) {
pics[count] = Toolkit.getDefaultToolkit().getImage("F:\\important\\d\\images\\"+gifs[count]);
count++;
}
this.setSize(280,360);
this.setBackground(Color.PINK);
this.setFocusable(true);
}
public void getTetro(){
System.out.println("a new random tetro");
// setTetroImage(pics[type]);
// repaint();
Thread t=new Thread(this);
t.start();
//run();
// t = null;
//.start();
}
public void nextTetro(){
System.out.println("next random tetro");
// tetroY1 =0;
// setTetroImage(pics[type]);
// repaint();
Thread t=new Thread(this);
// t=null;
t.start();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (tetro1 !=null)
g.drawImage(tetro1,tetroX1,tetroY1,this);
if (tetro2 !=null)
g.drawImage(tetro2,tetroX1,tetroY1,this);
if (tetro1g !=null)
g.drawImage(tetro1g,tetroX1,tetroYg,this);
}
public void setTetroImage(Image i) {
tetro1 = i;
tetro2 = i;
}
public void setGroundImage(Image i) {
tetro1g = i;
}
public void moveDown(){
System.out.println("tetro move down");
tetroY1+=40;
}
public void run(){
while(tetroY1 < 200 ){
setTetroImage(pics[type]);
moveDown();
repaint();
if(tetroY1>=200)
beGround();
try{Thread.sleep(600);
}
catch(InterruptedException e){
e.printStackTrace();}
// t = null;
// t.start();
}
nextTetro();
}
public void beGround(){
System.out.println("be ground");
setTetroImage(null);
tetroYg=tetroY1;
setGroundImage(pics[0]);
}
}
代码写到了 一个方块下落, 下落后成为地板, 然后就写不下去了, 一直希望再出现一个方块继续下落, 用的是线程run()方法控制图片下落, 图片是随机产生的, 然后希望得到一个新图片, 我在尝试开启一个新线程, 不知道想法对吗, 我是用画好的图片用成方块, 就是没种方块都是用PHOTOSHOP画好的, 代码如下, 目前有错, 高手帮我看看啊!! 谢谢!!
代码 高手们帮我看看问题在哪啊 谢谢谢谢
(PS:每次下落的都是随机的图片,不能是一样的) 展开
import javax.swing.*;
public class Main {
public static void main(String args[]){
NewGame g = new NewGame();
GameTest gt = new GameTest();
TetrisPanel t = new TetrisPanel();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(290,400);
frame.add(g);
frame.setLayout(null);
frame.setVisible(true);
g.getTetro();
}
}
import javax.swing.*;
import java.awt.*;
import java.util.Random;
/**
*
* @author Thinkpad
*/
public class NewGame extends JPanel implements Runnable{
Image [] pics;
String [] gifs = {"1.gif","222.gif"};
Image tetro1 = null;
Image tetro2 = null;
Image tetro1g= null;
int tetroX1;
int tetroX2;
int tetroY1;
int tetroY2;
int tetroYg;
int tetroY;
Thread game;
int type = new Random().nextInt(gifs.length);
public NewGame(){
pics = new Image[gifs.length] ;
int count = 0;
while (count<gifs.length) {
pics[count] = Toolkit.getDefaultToolkit().getImage("F:\\important\\d\\images\\"+gifs[count]);
count++;
}
this.setSize(280,360);
this.setBackground(Color.PINK);
this.setFocusable(true);
}
public void getTetro(){
System.out.println("a new random tetro");
// setTetroImage(pics[type]);
// repaint();
Thread t=new Thread(this);
t.start();
//run();
// t = null;
//.start();
}
public void nextTetro(){
System.out.println("next random tetro");
// tetroY1 =0;
// setTetroImage(pics[type]);
// repaint();
Thread t=new Thread(this);
// t=null;
t.start();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (tetro1 !=null)
g.drawImage(tetro1,tetroX1,tetroY1,this);
if (tetro2 !=null)
g.drawImage(tetro2,tetroX1,tetroY1,this);
if (tetro1g !=null)
g.drawImage(tetro1g,tetroX1,tetroYg,this);
}
public void setTetroImage(Image i) {
tetro1 = i;
tetro2 = i;
}
public void setGroundImage(Image i) {
tetro1g = i;
}
public void moveDown(){
System.out.println("tetro move down");
tetroY1+=40;
}
public void run(){
while(tetroY1 < 200 ){
setTetroImage(pics[type]);
moveDown();
repaint();
if(tetroY1>=200)
beGround();
try{Thread.sleep(600);
}
catch(InterruptedException e){
e.printStackTrace();}
// t = null;
// t.start();
}
nextTetro();
}
public void beGround(){
System.out.println("be ground");
setTetroImage(null);
tetroYg=tetroY1;
setGroundImage(pics[0]);
}
}
代码写到了 一个方块下落, 下落后成为地板, 然后就写不下去了, 一直希望再出现一个方块继续下落, 用的是线程run()方法控制图片下落, 图片是随机产生的, 然后希望得到一个新图片, 我在尝试开启一个新线程, 不知道想法对吗, 我是用画好的图片用成方块, 就是没种方块都是用PHOTOSHOP画好的, 代码如下, 目前有错, 高手帮我看看啊!! 谢谢!!
代码 高手们帮我看看问题在哪啊 谢谢谢谢
(PS:每次下落的都是随机的图片,不能是一样的) 展开
展开全部
话说真的有点乱,又没有注释,实在看不下去,还不如留个邮箱,我把以前写的程序给你发过去。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询