帮看看这些代码!怎么画不出图。
俄罗斯方块未完成的。
//teriseMain类
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;import javax.swing.*;
public class teriseMain extends JFrame {
private static final int WIDTH = 400;
private static final int HIGH = 500;
public teriseMain(){
tersiseWin block = new tersiseWin();
add (block);
JMenuBar menu = new JMenuBar();
setJMenuBar(menu);
JMenu game = new JMenu("菜单");
JMenuItem newgame = game.add("新游戏");
JMenuItem vioce = game.add("声音");
JMenuItem goon = game.add("继续");
JMenuItem exit = game.add("退出");
JMenu help = new JMenu("帮助");
JMenuItem about = help.add("关于");
menu.add(game);
menu.add(help);
setLocationRelativeTo(null);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0)
{
System.exit(0);
}
});
setSize(WIDTH, HIGH);
setTitle("俄罗斯方块,来自软工");
setLocation(350,200);
setVisible(true);
setResizable(false);
newgame.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
newgameActionPerformed(event);
}
}); vioce.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
pauseActionPerformed(event);
}
});
goon.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
goonActionPerformed(event);
}
});
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
exitActionPerformed(event);
}
});
about.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event){
aboutActionPerformed(event);
}
});
}
public void newgameActionPerformed(ActionEvent event)
{
// new RussiaGame();
}
public void pauseActionPerformed(ActionEvent event)
{
//block.suspend();
//block.requestFocus();
}
public void goonActionPerformed(ActionEvent event)
{
//block.startgame(true);
//block.requestFocus();
}
public void exitActionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "退出程序");
System.exit(0);
}
public void aboutActionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "游戏玩法");
//block.suspend();
//block.requestFocus();
}
public static void main(String []args){
try
{
new teriseMain();
}catch(NullPointerException e){}
}
}//import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;import javax.swing.*;
class tersiseWin extends JPanel implements KeyListener{
private JButton startgame;
// private JButton leavegame;
private static final int MAP_WIDTH = 270;
private static final int MAP_HIGH = 435;
private int stastu;
private int turn;
private int i,j,x,y;
private int blocki,blockj;
private int hang = MAP_HIGH/teriseData.BLOCKH;
private int line = MAP_WIDTH/teriseData.BLOCKW;
private int grade = 0,time = 0,level = 0;
private int Map[][];
private int shape[][][][];
thread th;
public void newmap(){
for(i = 0;i<MAP_WIDTH/teriseData.BLOCKW;i++)
{
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
Map[i][j]=0;
}
}
}
public void drawwall(){
for(i = 0;i<MAP_WIDTH/teriseData.BLOCKW;i++)
{
Map[i][MAP_HIGH/teriseData.BLOCKH-1]=2;
}
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
Map[MAP_WIDTH/teriseData.BLOCKW-1][j]=2;
Map[0][j]=2;
}
}
public tersiseWin(){
setLayout(new FlowLayout(FlowLayout.RIGHT));
startgame = new JButton("开始");
add(startgame);
//add( leavegame);
startgame.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==startgame)
{
if(event.getActionCommand().equals("开始")){
cotinue();
startgame.setText("暂停");
}
else {
pause();
startgame.setText("开始");
}
}
}
} );
//newmap();
//drawwall();
newBlock();
addKeyListener(this);
th = new thread();
th.start();
} public void newBlock() {
stastu = (int) (Math.random() * 1000) % 7;
turn = (int) (Math.random() * 1000) % 4;
shape = teriseData.blockpattern;
x = 0;
y = 0;
//shape[stastu][turn][i][j];
}
public void cotinue(){
}
public void pause(){
}
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_LEFT: left();break;
case KeyEvent.VK_RIGHT: right();break;
case KeyEvent.VK_DOWN: down();break;
case KeyEvent.VK_SPACE: space();break;
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.BLUE);
g.draw3DRect(0, 0, 270, 435, true);
g.drawString("分数"+grade, MAP_WIDTH+5, 70);
g.drawLine(MAP_WIDTH+5, 75, MAP_WIDTH+100, 75);
g.drawString("时间"+time, MAP_WIDTH+5, 95);
g.drawLine(MAP_WIDTH+5, 100, MAP_WIDTH+100, 100);
g.drawString("关数"+level, MAP_WIDTH+5, 125);
g.drawLine(MAP_WIDTH+5, 130, MAP_WIDTH+100,130);
g.drawString("下一个方块", MAP_WIDTH+30, 160);
g.fill3DRect(MAP_WIDTH+10,180, 100, 100, true);
g.drawString("俄罗斯方块", MAP_WIDTH+30,370);
g.drawString("软工小组", MAP_WIDTH+30, 390);
//画围墙
for(i=0;i<MAP_WIDTH/teriseData.BLOCKW;i++){
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
if(Map[i][j]==2){
g.setColor(Color.WHITE);
g.fill3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.BLUE);
g.draw3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW, teriseData.BLOCKH,true);
}
if(Map[i][j]==0){ g.setColor(Color.RED);
g.fill3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.BLUE);
g.draw3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW, teriseData.BLOCKH,true);
}
}
}
//画当前砖块
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(shape[stastu][turn][i][j]==1){
g.setColor(Color.GREEN);
g.fill3DRect(x+i*teriseData.BLOCKW,y+ j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.WHITE);
g.fill3DRect(x+i*teriseData.BLOCKW,y+ j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
}
}
}
} public void space() {
} public void down() {
}
public void move(){
}
public void right() {
} private void left() {
} public void keyReleased(KeyEvent e) {
} public void keyTyped(KeyEvent e) {
}
class thread extends Thread{
public void run(){
while(true){
try{
sleep(1000);
repaint();
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
} //teriseData类
public class teriseData {
public static final int blockpattern[][][][] ={ {
{{0,0,0,0},{0,1,1,0}, {0,1,1,0},{0,0,0,0},},{{0,0,0,0}, {0,1,1,0},{0,1,1,0},{0,0,0,0} ,
},{{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0},
},{{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0},},},{{{0,0,0,0},{0,0,1,0},{1,1,1,0},{0,0,0,0},},{{0,0,0,0},{ 0,1,1,1},{0,1,0,0},{0,0,0,0},},{{0,0,1,0},{0,0,1,0},{0,1,1,0},{0,0,0,0},},{{0,0,0,0},{0,1,1,0},{0,0,1,0},{0,0,1,0},},},{{{0,1,0,0},{0,1,0,0},{0,1,0,0},{0,1,0,0},},{{0,0,0,0}, {1,1,1,1}, {0,0,0,0} {0,0,0,0},},{{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0},},{{0,0,0,0},{1,1,1,1}, {0,0,0,0},{0,0,0,0},},
},{{{0,1,0,0},{1,1,1,0},{0,0,0,0},{0,0,0,0},},{{0,1,0,0},{0,1,1,0},{0,1,0,0},{0,0,0,0},},{{0,0,0,0},{1,1,1,0}, {0,1,0,0},{0,0,0,0}, },{{0,1,0,0},{1,1,0,0},{0,1,0,0}, {0,0,0,0},},},{{{1,1,0,0},{0,1,1,0}, {0,0,0,0},{0,0,0,0},},{{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,0,0,0} ,},{{0,0,1,1},{1,1,0,0},{0,0,0,0},{0,0,0,0} ,},{{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0},},},{{{0,0,0,0}, {1,0,0,0}, {1,1,1,0}, {0,0,0,0}, }, {{0,1,1,0},{0,1,0,0},{0,1,0,0},{0,0,0,0},},{{0,0,0,0},{1,1,1,0},{0,0,1,0},{0,0,0,0},},{{0,1,0,0},{0,1,0,0},{1,1,0,0},{0,0,0,0},},},{{{0,0,1,1},{1,1,0,0},{0,0,0,0},{0,0,0,0} ,},{{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0},
},{{0,0,0,0},{0,1,1,0},{1,1,0,0},{0,0,0,0},},{{1,0,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0},},}}
public static final int BLOCKW = 15;
public static final int BLOCKH = 15;
}
俄罗斯方块未完成的。
//teriseMain类
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;import javax.swing.*;
public class teriseMain extends JFrame {
private static final int WIDTH = 400;
private static final int HIGH = 500;
public teriseMain(){
tersiseWin block = new tersiseWin();
add (block);
JMenuBar menu = new JMenuBar();
setJMenuBar(menu);
JMenu game = new JMenu("菜单");
JMenuItem newgame = game.add("新游戏");
JMenuItem vioce = game.add("声音");
JMenuItem goon = game.add("继续");
JMenuItem exit = game.add("退出");
JMenu help = new JMenu("帮助");
JMenuItem about = help.add("关于");
menu.add(game);
menu.add(help);
setLocationRelativeTo(null);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0)
{
System.exit(0);
}
});
setSize(WIDTH, HIGH);
setTitle("俄罗斯方块,来自软工");
setLocation(350,200);
setVisible(true);
setResizable(false);
newgame.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
newgameActionPerformed(event);
}
}); vioce.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
pauseActionPerformed(event);
}
});
goon.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
goonActionPerformed(event);
}
});
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
exitActionPerformed(event);
}
});
about.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event){
aboutActionPerformed(event);
}
});
}
public void newgameActionPerformed(ActionEvent event)
{
// new RussiaGame();
}
public void pauseActionPerformed(ActionEvent event)
{
//block.suspend();
//block.requestFocus();
}
public void goonActionPerformed(ActionEvent event)
{
//block.startgame(true);
//block.requestFocus();
}
public void exitActionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "退出程序");
System.exit(0);
}
public void aboutActionPerformed(ActionEvent event)
{
JOptionPane.showMessageDialog(null, "游戏玩法");
//block.suspend();
//block.requestFocus();
}
public static void main(String []args){
try
{
new teriseMain();
}catch(NullPointerException e){}
}
}//import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;import javax.swing.*;
class tersiseWin extends JPanel implements KeyListener{
private JButton startgame;
// private JButton leavegame;
private static final int MAP_WIDTH = 270;
private static final int MAP_HIGH = 435;
private int stastu;
private int turn;
private int i,j,x,y;
private int blocki,blockj;
private int hang = MAP_HIGH/teriseData.BLOCKH;
private int line = MAP_WIDTH/teriseData.BLOCKW;
private int grade = 0,time = 0,level = 0;
private int Map[][];
private int shape[][][][];
thread th;
public void newmap(){
for(i = 0;i<MAP_WIDTH/teriseData.BLOCKW;i++)
{
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
Map[i][j]=0;
}
}
}
public void drawwall(){
for(i = 0;i<MAP_WIDTH/teriseData.BLOCKW;i++)
{
Map[i][MAP_HIGH/teriseData.BLOCKH-1]=2;
}
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
Map[MAP_WIDTH/teriseData.BLOCKW-1][j]=2;
Map[0][j]=2;
}
}
public tersiseWin(){
setLayout(new FlowLayout(FlowLayout.RIGHT));
startgame = new JButton("开始");
add(startgame);
//add( leavegame);
startgame.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==startgame)
{
if(event.getActionCommand().equals("开始")){
cotinue();
startgame.setText("暂停");
}
else {
pause();
startgame.setText("开始");
}
}
}
} );
//newmap();
//drawwall();
newBlock();
addKeyListener(this);
th = new thread();
th.start();
} public void newBlock() {
stastu = (int) (Math.random() * 1000) % 7;
turn = (int) (Math.random() * 1000) % 4;
shape = teriseData.blockpattern;
x = 0;
y = 0;
//shape[stastu][turn][i][j];
}
public void cotinue(){
}
public void pause(){
}
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_LEFT: left();break;
case KeyEvent.VK_RIGHT: right();break;
case KeyEvent.VK_DOWN: down();break;
case KeyEvent.VK_SPACE: space();break;
}
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.BLUE);
g.draw3DRect(0, 0, 270, 435, true);
g.drawString("分数"+grade, MAP_WIDTH+5, 70);
g.drawLine(MAP_WIDTH+5, 75, MAP_WIDTH+100, 75);
g.drawString("时间"+time, MAP_WIDTH+5, 95);
g.drawLine(MAP_WIDTH+5, 100, MAP_WIDTH+100, 100);
g.drawString("关数"+level, MAP_WIDTH+5, 125);
g.drawLine(MAP_WIDTH+5, 130, MAP_WIDTH+100,130);
g.drawString("下一个方块", MAP_WIDTH+30, 160);
g.fill3DRect(MAP_WIDTH+10,180, 100, 100, true);
g.drawString("俄罗斯方块", MAP_WIDTH+30,370);
g.drawString("软工小组", MAP_WIDTH+30, 390);
//画围墙
for(i=0;i<MAP_WIDTH/teriseData.BLOCKW;i++){
for(j = 0;j<MAP_HIGH/teriseData.BLOCKH;j++){
if(Map[i][j]==2){
g.setColor(Color.WHITE);
g.fill3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.BLUE);
g.draw3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW, teriseData.BLOCKH,true);
}
if(Map[i][j]==0){ g.setColor(Color.RED);
g.fill3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.BLUE);
g.draw3DRect(i*teriseData.BLOCKW, j*teriseData.BLOCKW, teriseData.BLOCKW, teriseData.BLOCKH,true);
}
}
}
//画当前砖块
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(shape[stastu][turn][i][j]==1){
g.setColor(Color.GREEN);
g.fill3DRect(x+i*teriseData.BLOCKW,y+ j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
g.setColor(Color.WHITE);
g.fill3DRect(x+i*teriseData.BLOCKW,y+ j*teriseData.BLOCKW, teriseData.BLOCKW,teriseData.BLOCKH, true);
}
}
}
} public void space() {
} public void down() {
}
public void move(){
}
public void right() {
} private void left() {
} public void keyReleased(KeyEvent e) {
} public void keyTyped(KeyEvent e) {
}
class thread extends Thread{
public void run(){
while(true){
try{
sleep(1000);
repaint();
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
} //teriseData类
public class teriseData {
public static final int blockpattern[][][][] ={ {
{{0,0,0,0},{0,1,1,0}, {0,1,1,0},{0,0,0,0},},{{0,0,0,0}, {0,1,1,0},{0,1,1,0},{0,0,0,0} ,
},{{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0},
},{{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0},},},{{{0,0,0,0},{0,0,1,0},{1,1,1,0},{0,0,0,0},},{{0,0,0,0},{ 0,1,1,1},{0,1,0,0},{0,0,0,0},},{{0,0,1,0},{0,0,1,0},{0,1,1,0},{0,0,0,0},},{{0,0,0,0},{0,1,1,0},{0,0,1,0},{0,0,1,0},},},{{{0,1,0,0},{0,1,0,0},{0,1,0,0},{0,1,0,0},},{{0,0,0,0}, {1,1,1,1}, {0,0,0,0} {0,0,0,0},},{{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0},},{{0,0,0,0},{1,1,1,1}, {0,0,0,0},{0,0,0,0},},
},{{{0,1,0,0},{1,1,1,0},{0,0,0,0},{0,0,0,0},},{{0,1,0,0},{0,1,1,0},{0,1,0,0},{0,0,0,0},},{{0,0,0,0},{1,1,1,0}, {0,1,0,0},{0,0,0,0}, },{{0,1,0,0},{1,1,0,0},{0,1,0,0}, {0,0,0,0},},},{{{1,1,0,0},{0,1,1,0}, {0,0,0,0},{0,0,0,0},},{{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,0,0,0} ,},{{0,0,1,1},{1,1,0,0},{0,0,0,0},{0,0,0,0} ,},{{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0},},},{{{0,0,0,0}, {1,0,0,0}, {1,1,1,0}, {0,0,0,0}, }, {{0,1,1,0},{0,1,0,0},{0,1,0,0},{0,0,0,0},},{{0,0,0,0},{1,1,1,0},{0,0,1,0},{0,0,0,0},},{{0,1,0,0},{0,1,0,0},{1,1,0,0},{0,0,0,0},},},{{{0,0,1,1},{1,1,0,0},{0,0,0,0},{0,0,0,0} ,},{{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0},
},{{0,0,0,0},{0,1,1,0},{1,1,0,0},{0,0,0,0},},{{1,0,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0},},}}
public static final int BLOCKW = 15;
public static final int BLOCKH = 15;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货