0
回答
想当年,初学ActionScript3.0,我就熬了几个通宵,写出了一个经典的五子棋游戏,从winform移植过来
开发十年,就只剩下这套Java开发体系了   

现在不搞flash了,在手里也浪费,倾囊传授需要的人,flash as3设计五子棋

package 
{
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.media.Sound;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.text.TextFieldAutoSize;
	import flash.utils.Timer;
	/**
	 * ...
	 * @author xjl
	 */
	public class Main extends Sprite 
	{
		private var sp:Sprite;
		private var bz:Boolean;
		private var check:Array;
		private var xx:Number;
		private var yy:Number;
		private var tx:TextField;
		private var tx2:TextField;
		private var tf:TextFormat;
		private var sound:Sound;
		private var fonttext:TextField;
		private var time:Number = 0;
		private var percent:Number = 0;
		private var per:TextField = new TextField();
		public function Main():void 
		{
			sound = new Sound(new URLRequest('http://zja.zggs.gov.cn/images/%d4%c2%c1%c1%d6%ae%c9%cf.mp3'));
			sound.play(0, 30, null);
			fonttext = new TextField();
			fonttext.autoSize = TextFieldAutoSize.CENTER;
			fonttext.selectable = false;
			fonttext.htmlText = '<font size="20" color="#3b7743">五 子 棋 游 戏</font>';	
			fonttext.border = true;
			fonttext.borderColor = 0x91c364;
			fonttext.x = stage.stage.stageWidth / 2 - 50;
			fonttext.y = stage.stage.stageHeight / 2 - 50;
			addChild(fonttext);
			var timer:Timer = new Timer(20, 500);
			timer.addEventListener(TimerEvent.TIMER, onTime);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimeCom);
			timer.start();
		}
		private function onTime(eve:TimerEvent):void
		{			
			per.x = stage.stage.stageWidth / 2 ;
			per.y = stage.stage.stageHeight / 2;
			percent++;
			var perstr:uint = uint(percent / 5);
			per.selectable = false;
			per.htmlText ="<font size='30'>"+perstr + "%</font>";
			addChild(per);
			time = time + 0.25;
			graphics.clear();
			graphics.beginFill(0xc0c0c0);		
			graphics.drawRect(stage.stage.stageWidth / 2 - 50, stage.stage.stageHeight / 2 - 50, time, 26);
			graphics.endFill();
		}
		private function onTimeCom(eve:TimerEvent):void
		{
			init();
		}
		public function init():void 
		{
			check = new Array();
			for (var k:uint = 0; k < 800; k = k + 20)
			{
				check[k] = new Array();
				for (var n:uint = 0; n < 600; n = n + 20)
				{
					check[k][n] = new Array();
				}
			}
			bz = true;
			sp = new Sprite();
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.SHOW_ALL;
			sp.graphics.beginFill(0xeb9c5d);
			sp.graphics.drawRect(20, 20, 760, 560);
			sp.graphics.endFill();
			sp.graphics.lineStyle(1);
			for (var i:uint = 20; i < 800; i=i+20)
			{				
				sp.graphics.moveTo(i, 20);				
				sp.graphics.lineTo(i, 580);				
			}
			for (var y:uint = 20; y< 600; y=y+20)
			{
				sp.graphics.moveTo(20,y);
				sp.graphics.lineTo(780,y);
			}
			addChild(sp);
			sp.addEventListener(MouseEvent.CLICK, click);
			sp.addEventListener(MouseEvent.MOUSE_OVER, mouseover);
			sp.addEventListener(MouseEvent.MOUSE_MOVE, mouseover);
		}
		private function mouseover(eve:MouseEvent):void
		{
			if ((eve.target.mouseX) % 20 >= 0 && (eve.target.mouseX) % 20 <=5&&  (eve.target.mouseY) % 20 >=0
			&&  (eve.target.mouseY) % 20 <=5)
			{
				buttonMode = true;
			}
			else
			{
				buttonMode = false;
			}
		}
		private function newstart(eve:MouseEvent):void
		{
			init();
		}
		private function changeColor(eve:MouseEvent):void
		{
			eve.target.textColor = 0xff0000;
		}
		private function restoreColor(eve:MouseEvent):void
		{
			eve.target.textColor = 0x000000;
		}
		private function restore():void
		{
			tx2 = new TextField();
			tx2.selectable = false;
			tx2.htmlText = "<font size='20'>重新开始</font>";
			tx2.x = 360;
			tx2.y = 320;
			tx2.autoSize = TextFieldAutoSize.CENTER;
			sp.addChild(tx2);
			tx2.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
			tx2.addEventListener(MouseEvent.MOUSE_OUT, restoreColor);
			tx2.addEventListener(MouseEvent.CLICK, newstart);
		}
		private function blackwon():void
		{
			sp.graphics.clear();
				sp.graphics.beginFill(0xf9edc7);
				sp.graphics.drawRect(20, 20, 760, 560);
				sp.graphics.endFill();
				tx = new TextField();
				tx.selectable = false;
				tx.text = '黑棋获胜';
				tx.x = 360;
				tx.y = 260;
				tx.autoSize = TextFieldAutoSize.CENTER;
				tf = new TextFormat();
				tf.font = '华文行楷';
				tf.size = 30;
				tf.bold = true;
				tx.setTextFormat(tf);
				restore();
				sp.addChild(tx);
				sp.removeEventListener(MouseEvent.CLICK, click);
				sp.removeEventListener(MouseEvent.MOUSE_OVER, mouseover);
				sp.removeEventListener(MouseEvent.MOUSE_MOVE, mouseover);		
				buttonMode = false;
		}
		private function whitewon():void
		{
			sp.graphics.clear();
				sp.graphics.beginFill(0xf9edc7);
				sp.graphics.drawRect(20, 20, 760, 560);
				sp.graphics.endFill();
				tx = new TextField();
				tx.selectable = false;
				tx.text = '白棋获胜';
				tx.x = 360;
				tx.y = 260;
				tx.autoSize = TextFieldAutoSize.CENTER;
				tf = new TextFormat();
				tf.font = '华文行楷';
				tf.size = 30;
				tf.bold = true;
				tx.setTextFormat(tf);
				restore();
				sp.addChild(tx);
				sp.removeEventListener(MouseEvent.CLICK, click);
				sp.removeEventListener(MouseEvent.MOUSE_OVER, mouseover);
				sp.removeEventListener(MouseEvent.MOUSE_MOVE, mouseover);		
				buttonMode = false;
		}
		private function click(eve:MouseEvent):void
		{
			if ((eve.target.mouseX) % 20 >= 0 && (eve.target.mouseX) % 20 <=5&&  (eve.target.mouseY) % 20 >=0
			&&  (eve.target.mouseY) % 20 <=5)
			{
				if (bz == true)
				{
					if (check[eve.target.mouseX - (eve.target.mouseX) % 20][eve.target.mouseY - (eve.target.mouseY) % 20] != 1 &&
						check[eve.target.mouseX - (eve.target.mouseX) % 20][eve.target.mouseY - (eve.target.mouseY) % 20] != 2
					)
					{
					bz = false;
					sp.graphics.beginFill(0x000000);
					sp.graphics.drawCircle(eve.target.mouseX-(eve.target.mouseX) % 20 , eve.target.mouseY-(eve.target.mouseY) % 20 , 10);
					sp.graphics.endFill();
					xx = eve.target.mouseX - (eve.target.mouseX) % 20;
					yy = eve.target.mouseY - (eve.target.mouseY) % 20;
					check[xx][yy] = 1;
					}
				}
				else
				{
					if (check[eve.target.mouseX - (eve.target.mouseX) % 20][eve.target.mouseY - (eve.target.mouseY) % 20] != 1 &&
						check[eve.target.mouseX - (eve.target.mouseX) % 20][eve.target.mouseY - (eve.target.mouseY) % 20] != 2
					)
					{
					bz = true;
					sp.graphics.beginFill(0xffffff);
					sp.graphics.drawCircle(eve.target.mouseX-(eve.target.mouseX) % 20 , eve.target.mouseY-(eve.target.mouseY) % 20 , 10);
					sp.graphics.endFill();
					xx = eve.target.mouseX - (eve.target.mouseX) % 20;
					yy =eve.target.mouseY - (eve.target.mouseY) % 20;
					check[xx][yy] = 2;
					}
				}
								
			 	if (check[xx][ yy] == 1 && check[xx + 20][ yy] == 1 && check[xx + 40][ yy] == 1
                  && check[xx + 60][ yy] == 1 && check[xx + 80][ yy] == 1 ||
                check[xx][ yy] == 1 && check[xx - 20][ yy] == 1 && check[xx - 40][ yy] == 1
                  && check[xx - 60][ yy] == 1 && check[xx - 80][ yy] == 1 ||
                 check[xx][ yy] == 1 && check[xx - 20][ yy] == 1 && check[xx + 20][ yy] == 1
                  && check[xx + 40][ yy] == 1 && check[xx + 60][ yy] == 1 ||
                check[xx][ yy] == 1 && check[xx + 20][ yy] == 1 && check[xx - 20][ yy] == 1
                  && check[xx - 40][ yy] == 1 && check[xx - 60][ yy] == 1 ||
                check[xx][ yy] == 1 && check[xx - 20][ yy] == 1 && check[xx + 20][ yy] == 1
                  && check[xx - 40][ yy] == 1 && check[xx + 40][ yy] == 1
                )
            {
				blackwon();
            }
           if (check[xx][ yy] == 2 && check[xx + 20][ yy] == 2 && check[xx + 40][ yy] == 2
                     && check[xx + 60][ yy] == 2 && check[xx + 80][ yy] == 2 ||
                   check[xx][ yy] == 2 && check[xx - 20][ yy] == 2 && check[xx - 40][ yy] == 2
                     && check[xx - 60][ yy] == 2 && check[xx - 80][ yy] == 2 ||
                    check[xx][ yy] == 2 && check[xx - 20][ yy] == 2 && check[xx + 20][ yy] == 2
                     && check[xx + 40][ yy] == 2 && check[xx + 60][ yy] == 2 ||
                   check[xx][ yy] == 2 && check[xx + 20][ yy] == 2 && check[xx - 20][ yy] == 2
                     && check[xx - 40][ yy] == 2 && check[xx - 60][ yy] == 2 ||
                   check[xx][ yy] == 2 && check[xx - 20][ yy] == 2 && check[xx + 20][ yy] == 2
                     && check[xx - 40][ yy] == 2 && check[xx + 40][ yy] == 2
                   )
            {
               whitewon();
            }
            if (check[xx][ yy] == 1 && check[xx][ yy + 20] == 1 && check[xx][ yy + 40] == 1
                      && check[xx][ yy + 60] == 1 && check[xx][ yy + 80] == 1 ||
                    check[xx][ yy] == 1 && check[xx][ yy - 20] == 1 && check[xx][ yy - 40] == 1
                      && check[xx][ yy - 60] == 1 && check[xx][ yy - 80] == 1 ||
                     check[xx][ yy] == 1 && check[xx][ yy - 20] == 1 && check[xx][ yy + 20] == 1
                      && check[xx][ yy + 40] == 1 && check[xx][ yy + 60] == 1 ||
                    check[xx][ yy] == 1 && check[xx][ yy + 20] == 1 && check[xx][ yy - 20] == 1
                      && check[xx][ yy - 40] == 1 && check[xx][ yy - 60] == 1 ||
                    check[xx][ yy] == 1 && check[xx][ yy - 20] == 1 && check[xx][ yy + 20] == 1
                      && check[xx][ yy - 40] == 1 && check[xx][ yy + 40] == 1
                    )
            {
               blackwon();
            }
            if (check[xx][ yy] == 2 && check[xx][ yy + 20] == 2 && check[xx][ yy + 40] == 2
                          && check[xx][ yy + 60] == 2 && check[xx][ yy + 80] == 2 ||
                        check[xx][ yy] == 2 && check[xx][ yy - 20] == 2 && check[xx][ yy - 40] == 2
                          && check[xx][ yy - 60] == 2 && check[xx][ yy - 80] == 2 ||
                         check[xx][ yy] == 2 && check[xx][ yy - 20] == 2 && check[xx][ yy + 20] == 2
                          && check[xx][ yy + 40] == 2 && check[xx][ yy + 60] == 2 ||
                        check[xx][ yy] == 2 && check[xx][ yy + 20] == 2 && check[xx][ yy - 20] == 2
                          && check[xx][ yy - 40] == 2 && check[xx][ yy - 60] == 2 ||
                        check[xx][ yy] == 2 && check[xx][ yy - 20] == 2 && check[xx][ yy + 20] == 2
                          && check[xx][ yy - 40] == 2 && check[xx][ yy + 40] == 2
                        )
            {
              whitewon();
            }
            if (check[xx][ yy] == 1 && check[xx + 20][ yy + 20] == 1 && check[xx + 40][ yy + 40] == 1
                         && check[xx + 60][ yy + 60] == 1 && check[xx + 80][ yy + 80] == 1 ||
                       check[xx][ yy] == 1 && check[xx - 20][ yy - 20] == 1 && check[xx - 40][ yy - 40] == 1
                         && check[xx - 60][ yy - 60] == 1 && check[xx - 80][ yy - 80] == 1 ||
                        check[xx][ yy] == 1 && check[xx - 20][ yy - 20] == 1 && check[xx + 20][ yy + 20] == 1
                         && check[xx + 40][ yy + 40] == 1 && check[xx + 60][ yy + 60] == 1 ||
                       check[xx][ yy] == 1 && check[xx + 20][ yy + 20] == 1 && check[xx - 20][ yy - 20] == 1
                         && check[xx - 40][ yy - 40] == 1 && check[xx - 60][ yy - 60] == 1 ||
                       check[xx][ yy] == 1 && check[xx - 20][ yy - 20] == 1 && check[xx + 20][ yy + 20] == 1
                         && check[xx - 40][ yy - 40] == 1 && check[xx + 40][ yy + 40] == 1
                       )
            {
               blackwon();
            }
            if (check[xx][ yy] == 2 && check[xx + 20][ yy + 20] == 2 && check[xx + 40][ yy + 40] == 2
                            && check[xx + 60][ yy + 60] == 2 && check[xx + 80][ yy + 80] == 2 ||
                          check[xx][ yy] == 2 && check[xx - 20][ yy - 20] == 2 && check[xx - 40][ yy - 40] == 2
                            && check[xx - 60][ yy - 60] == 2 && check[xx - 80][ yy - 80] == 2 ||
                           check[xx][ yy] == 2 && check[xx - 20][ yy - 20] == 2 && check[xx + 20][ yy + 20] == 2
                            && check[xx + 40][ yy + 40] == 2 && check[xx + 60][ yy + 60] == 2 ||
                          check[xx][ yy] == 2 && check[xx + 20][ yy + 20] == 2 && check[xx - 20][ yy - 20] == 2
                            && check[xx - 40][ yy - 40] == 2 && check[xx - 60][ yy - 60] == 2 ||
                          check[xx][ yy] == 2 && check[xx - 20][ yy - 20] == 2 && check[xx + 20][ yy + 20] == 2
                            && check[xx - 40][ yy - 40] == 2 && check[xx + 40][ yy + 40] == 2
                          )
            {
               whitewon();
            }
            if (check[xx][ yy] == 1 && check[xx + 20][ yy - 20] == 1 && check[xx + 40][ yy - 40] == 1
                             && check[xx + 60][ yy - 60] == 1 && check[xx + 80][ yy - 80] == 1 ||
                           check[xx][ yy] == 1 && check[xx - 20][ yy + 20] == 1 && check[xx - 40][ yy + 40] == 1
                             && check[xx - 60][ yy + 60] == 1 && check[xx - 80][ yy + 80] == 1 ||
                            check[xx][ yy] == 1 && check[xx - 20][ yy + 20] == 1 && check[xx + 20][ yy - 20] == 1
                             && check[xx + 40][ yy - 40] == 1 && check[xx + 60][ yy - 60] == 1 ||
                           check[xx][ yy] == 1 && check[xx + 20][ yy - 20] == 1 && check[xx - 20][ yy + 20] == 1
                             && check[xx - 40][ yy + 40] == 1 && check[xx - 60][ yy + 60] == 1 ||
                           check[xx][ yy] == 1 && check[xx - 20][ yy + 20] == 1 && check[xx + 20][ yy - 20] == 1
                             && check[xx - 40][ yy + 40] == 1 && check[xx + 40][ yy - 40] == 1
                           )
            {
                blackwon();
            }
            if (check[xx][ yy] == 2 && check[xx + 20][ yy - 20] == 2 && check[xx + 40][ yy - 40] == 2
                                 && check[xx + 60][ yy - 60] == 2 && check[xx + 80][ yy - 80] == 2 ||
                               check[xx][ yy] == 2 && check[xx - 20][ yy + 20] == 2 && check[xx - 40][ yy + 40] == 2
                                 && check[xx - 60][ yy + 60] == 2 && check[xx - 80][ yy + 80] == 2 ||
                                check[xx][ yy] == 2 && check[xx - 20][ yy + 20] == 2 && check[xx + 20][ yy - 20] == 2
                                 && check[xx + 40][ yy - 40] == 2 && check[xx + 60][ yy - 60] == 2 ||
                               check[xx][ yy] == 2 && check[xx + 20][ yy - 20] == 2 && check[xx - 20][ yy + 20] == 2
                                 && check[xx - 40][ yy + 40] == 2 && check[xx - 60][ yy + 60] == 2 ||
                               check[xx][ yy] == 2 && check[xx - 20][ yy + 20] == 2 && check[xx + 20][ yy - 20] == 2
                                 && check[xx - 40][ yy + 40] == 2 && check[xx + 40][ yy - 40] == 2
                               )
            {
               whitewon();
            }
		}
	}
  }
}

<无标签>
举报
顶部