求教c 俄罗斯方块教程问题,关于Timer

俄罗斯方块详解_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
俄罗斯方块详解
上传于||文档简介
&&C​语​言​程​序​开​发
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩13页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢君,已阅读到文档的结尾了呢~~
《俄罗斯方块》程序编写超详细解释
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
《俄罗斯方块》程序编写超详细解释
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口关于俄罗斯方块的一点小问题_java吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:552,246贴子:
关于俄罗斯方块的一点小问题收藏
最近JAVA作业在写俄罗斯方块,但写到中途发现,我写的地图下边界和在落到底部生成一个新的图形这两个功能没有实现,但是又没有报错,作为新手确实很苦恼,想请大神们看看,指出错误的地方。/* * To change this template, choose Tools | Templates * and open the template in the editor. */package 俄罗斯方块;import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * *
Administrator */public class ELS extends JFrame {
int Type = 0;
int State = 0;
private int x = 0;
private int y = 0;
public ELS() {
ELSPanel panel = new ELSPanel();
this.add(panel);
addKeyListener(panel);
private class timer implements ActionListener {
public void actionPerformed(ActionEvent e) {
repaint();
private class ELSPanel extends JPanel implements KeyListener {
private int map[][] = new int[13][23];
private final int shapes[][][] = new int[][][]{
{{0, 0, 0, 0,
1, 1, 1, 1,
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, 0,
1, 1, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0},
{0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0}},
{{1, 0, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},
{0, 1, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0},
{1, 1, 1, 0,
0, 0, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},
{1, 1, 0, 0,
1, 0, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0}},
{{0, 0, 1, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},
{1, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0},
{1, 1, 1, 0,
1, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0},
{1, 0, 0, 0,
1, 0, 0, 0,
1, 1, 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},
{1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0}},
{{0, 1, 1, 0,
1, 1, 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, 1, 1, 0,
1, 1, 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}},
{{1, 1, 0, 0,
0, 1, 1, 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},
{1, 1, 0, 0,
0, 1, 1, 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, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0},
{0, 1, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0},
{1, 1, 1, 0,
0, 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}}};
public ELSPanel() {
time = new Timer(1000, new timer());
time.start();
public void clean() {
for (int i = 1; i & 11; i++) {
for (int j = 0; j & 21; j++) {
map[i][j] = 0;
public void block() {
Type = (int) (Math.random() * 1000) % 7;
State = (int) (Math.random() * 1000) % 4;
public void wall() {
for (int i = 0; i & 12; i++) {
map[i][21] = 2;
for (int j = 0; j & 22; j++) {
map[0][j] = 2;
map[11][j] = 2;
public boolean isFrotiers(int x, int y) {
for (int a = 0; a & 4; a++) {
for (int b = 0; b & 4; b++) {
if ((shapes[Type][State][a * 4 + b] == 1) && (map[x + 1 + b][y + a]) == 1) {
} else if ((shapes[Type][State][a * 4 + b] == 1) && (map[x + 1 + b][y + a]) == 2) {
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int j = 0; j & 22; j++) {
for (int i = 0; i & 12; i++) {
if (map[i][j] == 2) {
g.drawRect(i * 20, j * 20, 20, 20);
if (map[i][j] == 1) {
g.fillRect(i * 20, j * 20, 20, 20);
for (int i = 0; i & 16; i++) {
if (shapes[Type][State][i] == 1) {
g.fillRect((x + 1 + i % 4) * 20, (y + i / 4) * 20, 20, 20);
public void keyTyped(KeyEvent e) {
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_SPACE:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_LEFT:
case KeyEvent.VK_RIGHT:
public void keyReleased(KeyEvent e) {
public void add() {
int i = 0;
for (int a = 0; a & 4; a++) {
for (int b = 0; a & 4; b++) {
if (map[x + 1 + b][y + a] == 0) {
map[x + 1 + b][y + a] = shapes[Type][State][i];
private void turn() {
int temp = S
State = (State + 1) % 4;
if (isFrotiers(x, y)) {
repaint();
private void down() {
if (!isFrotiers(x, y + 1)) {
repaint();
int score = 0;
public void delete() {
int c = 0;
for (int b = 0; b & 22; b++) {
for (int a = 0; a & 11; a++) {
if (map[a][b] == 1) {
if (c == 10) {
score += 10;
for (int d = d & 0; d--) {
for (int e = 0; e & 11; e++) {
map[e][d] = map[e][d - 1];
private void left() {
if (!isFrotiers(x - 1, y)) {
repaint();
private void right() {
if (!isFrotiers(x + 1, y)) {
repaint();
public static void main(String[] args) {
ELS frame = new ELS();
JMenuBar menu = new JMenuBar();
frame.setJMenuBar(menu);
JMenu game = new JMenu("菜单");
JMenuItem newgame = game.add("新游戏");
JMenuItem pause = game.add("暂停");
JMenuItem Continue = game.add("继续");
JMenuItem exit = game.add("退出");
menu.add(game);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setTitle("俄罗斯方块");
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setResizable(false);
千锋java,Java+大数据全项目实训,两周免费试听,0基础小班授课!千锋java零学费学习,Java+大数据培训,先入学后付款
= =大神们来看一下呗
擦。。。人工置顶一下
擦,为什么没人进来看看啊
太长,不看。
估计这会又沉了。。。
不要沉啊,很蛋疼的啊
不要沉!!!
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或

我要回帖

更多关于 俄罗斯方块问题 的文章

 

随机推荐