快速业务通道

FLASH教程:as3实现的俄罗斯方块

作者 佚名技术 来源 服务器技术 浏览 发布时间 2012-07-07

俄罗斯方块swf: 源文件: Tetris.rar 详细代码:
  1. package
  2. {
  3. import Flash.display.Sprite;
  4. import flash.events.Event;
  5. import flash.events.KeyboardEvent;
  6. import flash.events.MouseEvent;
  7. import flash.events.TimerEvent;
  8. import flash.geom.Point;
  9. import flash.text.TextField;
  10. import flash.ui.Keyboard;
  11. import flash.utils.Timer;
  12. import flash.net.*;
  13. /**
  14. * ...
  15. * @author sliz
  16. * @qq:405628079
  17. */
  18. [SWF(width="400", height="500", backgroundColor="0x000000", frameRate="60")]
  19. public class Main extends Sprite
  20. {
  21. private var deadBoxs:Array = new Array();
  22. private var liveBoxs:Array = new Array();
  23. private var xNum:int = 20;
  24. private var yNum:int = 40;
  25. private var w:Number = 10;
  26. private var world:Sprite = new Sprite();
  27. private var liveWrapper:Sprite = new Sprite();
  28. private var keyRight :Boolean = false;
  29. private var keyLeft :Boolean = false;
  30. private var keyUp:Boolean = false;
  31. private var keyRollLeft:Boolean = false;
  32. private var keyRollRight:Boolean = false;
  33. private var lives:Array = new Array();
  34. private var livesLength:int = 5;
  35. public function Main():void
  36. {
  37. init();
  38. }
  39. private function init():void
  40. {
  41. ////////////////////////////
  42. var lable1:TextField = new TextField();
  43. addChild(lable1);
  44. lable1.textColor = 0xffffff;
  45. lable1.text = "上,下,左,右,空格";
  46. var lable2:TextField = new TextField();
  47. addChild(lable2);
  48. lable2.textColor = 0xffffff;
  49. lable2.text = "sliz";
  50. lable2.width = 50;
  51. lable2.height=20
  52. lable2.addEventListener(MouseEvent.CLICK, clickHandler);
  53. lable2.x = stage.stageWidth - lable2.width;
  54. lable2.y = stage.stageHeight - lable2.height;
  55. ///////////////////////////
  56. var timer:Timer = new Timer(1000);
  57. var timer2:Timer = new Timer(100);
  58. addChild(world);
  59. world.x = stage.stageWidth / 2 - xNum * w / 2;
  60. world.y = stage.stageHeight / 2 - yNum * w / 2
  61. addChild(liveWrapper);
  62. for (var i:int = 0; i < yNum;i++ ) {
  63. deadBoxs = new Array();
  64. for (var j:int = 0; j < xNum;j++ ) {
  65. deadBoxs[j] = 0;
  66. }
  67. }
  68. lives[0] = 1;
  69. for (i = 0; i < livesLength; i++) {
  70. initLive();
  71. }
  72. update();
  73. stage.addEventListener(MouseEvent.CLICK, clickHandler);
  74. stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  75. stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  76. stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  77. timer.addEventListener(TimerEvent.TIMER, timeHandler);
  78. timer2.addEventListener(TimerEvent.TIMER, timeHandler2);
  79. timer2.start();
  80. timer.start();
  81. }
  82. private function init

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号