I am newer in FLEX and currently i am using FLEX 3.0
I want to develop a Tic Tac Toe game in FLEX. At first i think this one is the easiest for me but now its going to be very tough for me. I have searched on Internet but not a single link helps me that much so please give me proper Idea with proper code. Here i am giving you the sample code. its a bit of complex so sorry for that.
<?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>
I have check the winning condition on btn_click() function but you can give me the idea to change it when the one row is completed.
I want to know how to handle the array of TicTacToe Game.
This game can develop using different Logic.
Refer 1 and 2 Which source enabled.
and try to accomplish your game.