求个简单的俄罗斯方块java代码,初学者能看懂的

俄罗斯的功能不要太多,能玩就行

java版的我没有,给你看个js版的:
<html>
<style>.c {margin :1px;width:19px;height:19px;background:red;position:absolute;}
.d {margin :1px;width:19px;height:19px;background:gray;position:absolute;}
.f {top:0px;left:0px;background:black;position:absolute;}
</style>
<body></body><html>
<script>
var over=false,shapes=("0,1,1,1,2,1,3,1;1,0,1,1,1,2,2,2;2,0,2,1,2,2,1,2;0,1,1,1,1,2,2,2;1,2,2,2,2,1,3,1;1,1,2,1,1,2,2,2;0,2,1,2,1,1,2,2").split(";");
function create(tag,css){
var elm=document.createElement(tag);
elm.className = css;
document.body.appendChild(elm);
return elm;}
function Tetris(c, t, x, y){
var c=c?c:"c";
this.divs = [create("div",c),create("div",c),create("div",c),create("div",c)];
this.reset = function(){
this.x = typeof x != 'undefined'?x:3;
this.y = typeof y != 'undefined'?y:0;
this.shape = t?t:shapes[Math.floor(Math.random()*(shapes.length-0.00001))].split(",");
this.show();
if(this.field&&this.field.check(this.shape,this.x,this.y,'v')=='D'){
over=true;
this.field.fixShape(this.shape,this.x,this.y);
alert('game over');}}
this.show = function(){
for(var i in this.divs){
this.divs[i].style.left = (this.shape[i*2]*1+this.x)*20+'px';
this.divs[i].style.top = (this.shape[i*2+1]*1+this.y)*20+'px';}}
this.field=null;
this.hMove = function(step){
var r = this.field.check(this.shape,this.x- -step,this.y,'h');
if(r!='N'&&r==0){
this.x-=-step;
this.show();}}
this.vMove = function(){
if(this.field.check(this.shape,this.x,this.y- -1,'v')=='N'){
this.y++;
this.show();}
else{
this.field.fixShape(this.shape,this.x,this.y);
this.field.findFull();
this.reset();}}
this.rotate = function(){
var s=this.shape;
var newShape=[3-s[1],s[0],3-s[3],s[2],3-s[5],s[4],3-s[7],s[6]];
var r = this.field.check(newShape,this.x,this.y,'h');
if(r=='D')return;
if(r==0){
this.shape=newShape;
this.show();}
else if(this.field.check(newShape,this.x-r,this.y,'h')==0){
this.x-=r;
this.shape=newShape;
this.show();}}
this.reset();}
function Field(w,h){
this.width = w?w:10;
this.height = h?h:20;
this.show = function(){
var f = create("div","f")
f.style.width=this.width*20+'px';
f.style.height=this.height*20+'px';}
this.findFull = function(){
for(var l=0;l<this.height;l++){
var s=0;
for(var i=0;i<this.width;i++){
s+=this[l*this.width+i]?1:0;}
if(s==this.width){
this.removeLine(l);}}}
this.removeLine = function(line){
for(var i=0;i<this.width;i++){
document.body.removeChild(this[line*this.width+i]);}
for(var l=line;l>0;l--){
for(var i=0;i<this.width;i++){
this[l*this.width- -i]=this[(l-1)*this.width- -i];
if(this[l*this.width- -i])this[l*this.width- -i].style.top = l*20+'px';}}}
this.check = function(shape, x, y, d){
var r1=0,r2='N';
for(var i=0;i<8;i+=2){
if(shape[i]- -x < 0 && shape[i]- -x <r1)
{r1 = shape[i]- -x;}
else if(shape[i]- -x>=this.width && shape[i]- -x>r1)
{r1 = shape[i]- -x;}
if(shape[i+1]- -y>=this.height || this[shape[i]- -x- -(shape[i+1]- -y)*this.width])
{r2='D'}}
if(d=='h'&&r2=='N')return r1>0?r1-this.width- -1:r1;
else return r2;}
this.fixShape = function(shape,x,y){
var d=new Tetris("d",shape,x,y);
d.show();
for(var i=0;i<8;i+=2){
this[shape[i]- -x- -(shape[i+1]- -y)*this.width]=d.divs[i/2];}}}
var f = new Field();
f.show();
var s = new Tetris();
s.field = f;
s.show();
window.setInterval("if(!over)s.vMove();",500);
document.onkeydown = function(e){
if(over)return;
var e = window.event ? window.event : e;
switch(e.keyCode){
case 38: //up
s.rotate();
break;
case 40: //down
s.vMove();
break;
case 37: //left
s.hMove(-1);
break;
case 39: //right
s.hMove(1);
break;}}
</script>
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-08-01
CSDN上面有的!!
第2个回答  2012-08-01
我有,如你所说,只完成了最基本的功能.

求java编的俄罗斯方块代码! 最好是网络版的!单机版的也好啊!谢谢...
\/\/方块下落的方法 public void down() { Y++; switch(MODE) { case 0: o[X+2][Y]=1; o[X+2][Y+1]=1; o[X+2][Y+2]=1; o[X+2][Y+3]++; o[X+2][Y-1]=0; break; case 1: o[X][Y+1]++; o[X+1][Y+1]++; o[X+2][Y+1]++; o[X+3][Y+1]++; o[X][Y]=...

求用JAVA编写俄罗斯方块游戏的源代码
俄罗斯方块——java源代码提供 import java.awt.*; import java.awt.event.*; \/\/俄罗斯方块类 public class ERS_Block extends Frame{ public static boolean isPlay=false; public static int level=1,score=0; public static TextField scoreField,levelField; public static MyTimer timer; GameCanvas gameScr...

求俄罗斯Java代码
setLayout(new java.awt.BorderLayout()); add(gameCanvas,"Center"); setResizable(false); setLocation((java.awt.Toolkit.getDefaultToolkit().getScreenSize().width-gameCanvas.getPreferredSize().width)\/2,(java.awt.Toolkit.getDefaultToolkit().getScreenSize().height-gameCanvas.getPreferredSize().height...

急求俄罗斯方块等小游戏的源代码
public static void main(String[] argus){ ERS_Block ers = new ERS_Block("俄罗斯方块游戏 V1.0 Author:Vincent"); WindowListener win_listener = new WinListener(); ers.addWindowListener(win_listener); } \/\/俄罗斯方块类的构造方法 ERS_Block(String title){ super(title); setSize(600,480); setLa...

俄罗斯方块 Java源代码 Eclipse能运行的。要求如下图,谢谢
import java.awt.*; \\x0d\\x0aimport java.awt.event.*; \\x0d\\x0aimport javax.swing.*; \\x0d\\x0apublic class Els extends JFrame implements KeyListener,Runnable \\x0d\\x0a{\\x0d\\x0apublic Els() \\x0d\\x0a{ \\x0d\\x0asetSize(240,320); \\x0d\\x0asetUndecorated(true)...

java编写的俄罗斯方块游戏
以下为一个俄罗斯方块的源代码,以---线分隔一个类。郁闷太长了,不能全部粘贴上来,要的话在线M我吧。import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import java.io.IOException;\/ Title: 俄罗斯方块 Description: 俄罗斯方块游戏 Copyright: Copyright (c) 2005 Company: Star...

java俄罗斯方块实现新游戏、暂停、继续功能的代码怎么写
jMenuItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { \/\/这里实现游戏开始 } });

java俄罗斯方块旋转算法,求解
如果是2*2的方格,就可以变为二阶行列式,也就是2*2的二元数组,这里给出3*3九宫格改变的示意,我的代码如下:import java.util.Random;public class T{public static void main(String[] args){int[][] a=new int[3][3];System.out.println("now begin to form a new integer array");...

java做的 俄罗斯方块 急用 谢谢啊 atb_machao@163.com大神们帮帮忙...
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.*; import javax.swing.Timer; public class Tetris extends JFrame { public Tetris() { Tetrisblok a = ...

求大神给一份JAVA小游戏,贪吃蛇或者俄罗斯方块源代码。my eclipse能直接...
import java.awt.*;import java.awt.event.*;class Game extends JFrame implements KeyListener,Runnable { Thread Down10 = new Thread(this);GameCanvas test = new GameCanvas();JLabel LabelTetris = new JLabel("Tetris Game");JLabel ScorePrint1 = new JLabel("Score");JLabel Score...

相似回答