首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flex中的Tac Tac Toe游戏

Flex中的Tac Tac Toe游戏
EN

Stack Overflow用户
提问于 2012-01-04 19:12:31
回答 4查看 1.2K关注 0票数 0

我是FLEX的新手,目前我正在使用FLEX 3.0,我想在FLEX中开发一个Tic Tac Toe游戏。起初,我认为这对我来说是最简单的,但现在它对我来说将是非常困难的。我已经在互联网上搜索,但没有一个链接对我有那么大的帮助,所以请给我适当的想法和适当的代码。在这里,我将给您示例代码。这有点复杂,所以很抱歉。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="#000000" 
horizontalAlign="center" verticalAlign="middle" height="100%" width="100%" verticalGap="0" horizontalGap="0">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.controls.Image;

        private var blnFirst:Boolean = true;
        private var arr0:Array = new Array();
        private var arr1:Array = new Array();
        private var arr2:Array = new Array();
        private var count:int = 0;
        private var arr:Array = new Array();
        private var pl1Won:Boolean = false;
        private var pl2Won:Boolean = false;

        public function img_click(event:Event):void
        {
            if(event.currentTarget.enabled)
            {
                count++;
                if(blnFirst)
                {
                    blnFirst = false;
                    var itemp:Image = new Image();
                    itemp.percentHeight = 100;
                    itemp.percentWidth = 100;
                    itemp.source = "Images/Circle.png";
                    event.currentTarget.addChild(itemp);
                    event.currentTarget.enabled = false;
                    arrayInsert(event.currentTarget.id,true);
                }
                else
                {
                    blnFirst = true;
                    var itemp:Image = new Image();
                    itemp.percentHeight = 100;
                    itemp.percentWidth = 100;
                    itemp.source = "Images/Cross.png";
                    event.currentTarget.addChild(itemp);
                    event.currentTarget.enabled = false;
                    arrayInsert(event.currentTarget.id,false);
                }
            }

            if(count == 9)
            {
                arr = [arr0, arr1, arr2];
            }
        }

        private function arrayInsert(id:String,value:Boolean):void
        {
            if(id == "box00")
                arr0[0] = value;    
            if(id == "box01")
                arr0[1] = value;
            if(id == "box02")
                arr0[2] = value;
            if(id == "box10")
                arr1[0] = value;
            if(id == "box11")
                arr1[1] = value;    
            if(id == "box12")
                arr1[2] = value;
            if(id == "box20")
                arr2[0] = value;    
            if(id == "box21")
                arr2[1] = value;    
            if(id == "box22")
                arr2[2] = value;
        }

        private function btn_click():void
        {
                        for(var i:int=0;i<3;i++)
            {
                for(var j:int=0;j<3;j++)
                {
                    //very confused in this part
                }
            }
                            }

    ]]>
</mx:Script>
<mx:VBox height="500" width="500" borderStyle="solid" borderThickness="3" borderColor="#000000"
    backgroundColor="#ffffff" verticalGap="0" horizontalGap="0">

    <mx:HBox width="100%" height="33.3%" horizontalGap="0" verticalGap="0">

        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box00" >
        </mx:Box>
        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box01">
        </mx:Box>
        <mx:Box height="100%" width="33.4%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box02">
        </mx:Box>

    </mx:HBox>
    <mx:HBox width="100%" height="33.3%" horizontalGap="0" verticalGap="0">

        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box10">
        </mx:Box>
        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box11">
        </mx:Box>
        <mx:Box height="100%" width="33.4%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box12">
        </mx:Box>

    </mx:HBox>
    <mx:HBox width="100%" height="33.4%" horizontalGap="0" verticalGap="0">

        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box20">
        </mx:Box>
        <mx:Box height="100%" width="33.3%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box21">
        </mx:Box>
        <mx:Box height="100%" width="33.4%" borderStyle="solid" borderThickness="3" borderColor="#000000" backgroundColor="#ffffff"
            click="{img_click(event);}" id="box22">
        </mx:Box>

    </mx:HBox>

</mx:VBox>

<mx:Button click="{btn_click();}" />

</mx:Application>

我已经检查了btn_click()函数的获胜条件,但您可以给我一个想法,当一行完成时更改它。

我想知道如何处理TicTacToe游戏的数组。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-01-04 20:14:46

这个游戏可以使用不同的逻辑进行开发。

请参阅启用了信号源的12。试着完成你的游戏。

票数 1
EN

Stack Overflow用户

发布于 2012-01-04 19:57:23

假设你正在创建一个3x3网格的tic tac toe。创建一个二维数组以获得更好的可视化效果。将它们初始化为0。

每次在ai处输入0,j将-1赋给ai,如果为空,请检查第i行和第j列的sum -3,如果i=j或i+j=2检查对角线是否有sum -3,您就有了赢家。

每次在ai处输入X时,j将1赋值给ai,如果为空,则检查第i行和第j列的和是否为3,如果i=j或i+j=2检查对角线的和为3,则您有一个胜利者

票数 2
EN

Stack Overflow用户

发布于 2012-01-04 23:19:57

下面是写给学生(完全初学者)的作业:http://code.google.com/p/as3-workshop/source/browse/#svn%2Ftrunk%2Fsrc%2Ftld%2Fcourse%2Flesson1 (玩家自己玩的游戏,因此站在"O“和"X”的一边。

作业:http://code.google.com/p/as3-workshop/source/browse/#svn%2Ftrunk%2Fsrc%2Ftld%2Fcourse%2Fhomework1 (计算机与人类对战)。

这些例子没有很好的文档记录(我们在课堂上做了评论和解释,我没有记录),但是考虑到没有太多的代码,你应该通过它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8725870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档