Pipeline

HI thanks for your contribution…but same problem is here again , my question is its ok you can move 'L" shape pipe in diff direction but what about “I” shape …when you click on “I” shape pipe it should move and should not call “L” shape pipe in the display screen…in your code you cant move “I” shape present on the left hand side…

[quote=neilmmm;2333829]i like the game and have had a go … gone in a completely different direction … i don’t think it is the right direction

but here is my code … perhaps someone will respnd to help move it on

var counter:Number = 0;
var mc_id:Number;
var mcConnectionArray:Array=new Array();
var tempArray:Array=newArray();
var mc_type:String;
var empty:MovieClip=this.createEmptyMovieClip("holder",this.getNextHighestDepth());
var target_mc:MovieClip;
function checkleft (target) {
 //trace("checkleft called");
 //trace (empty["pipe"+target]._name)
 //trace ("target array ="+empty["pipe"+target].mcConnectionArray.length)
 /*for (k=0;k<empty["pipe"+target].mcConnectionArray.length;k++) {
  trace(empty["pipe"+target].mcConnectionArray[k])
}
for (i=0;i<tempArray.length;i++) {
 trace (" checking left fornd tempArray = "+tempArray*);
}*/
//if (empty["pipe"+target].mc_type=="straight") {
 if (empty["pipe"+target].mcConnectionArray[1]=="right"&&empty["pipe"+(target+1)].mcConnectionArray[3]=="left") {
  trace("yep");
  trace ("cuurent frame ="+empty["pipe"+(target+1)]._currentframe);
  empty["pipe"+(target+1)].gotoAndStop(2);
}else{
 trace("no");
 empty["pipe"+(target+1)].gotoAndStop(1);
}

//}
}
 
function spinPipe () {
 
 for (k=0;k<this.mcConnectionArray.length;k++) {
  //trace(this.mcConnectionArray[k])
}
 this._rotation+=90;
 
 if (this._rotation==0) {
  //trace ("rotation =0");
  this.mcConnectionArray=["top","right","no","no"];
}else if(this._rotation==90){
 //trace ("rotation =90");
 this.mcConnectionArray=["no","right","bottom","no"];
}else if(this._rotation==180){
 //trace ("rotation =180");
 this.mcConnectionArray=["no","no","bottom","left"];
}else{
 //trace ("rotation =-90");
 this.mcConnectionArray=["top","no","no","left"];
}
 tempArray=[];
 
 //trace(this.mc_id);
 //trace(this._rotation);
 for (k=0;k<this.mcConnectionArray.length;k++) {
  //trace(this.mcConnectionArray[k])
  tempArray.push(this.mcConnectionArray[k]);
  //trace("tempArray "+k+" = "+tempArray[k]);
}
trace("");
trace(this._name);
trace (this.mc_id-1)
checkleft(this.mc_id-1);
 
 
}
for (i=0; i<10; i++) {
 for (j=0; j<10; j++) {
  counter++;
  if (j==0) {
   var mc:MovieClip =  empty.attachMovie("straightPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="straight";
  mc.gotoAndStop(2);
mc.mcConnectionArray=["no","right","no","left"];
  
  mc._rotation=90;
  mc.mc_id=counter;
  //mc.onRelease=spinPipe;
   
   
}else if (j==9){
var mc:MovieClip =  empty.attachMovie("straightPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="straight";
  mc.gotoAndStop(3);
mc.mcConnectionArray=["no","right","no","left"];;
  
  mc._rotation=90;
  mc.mc_id=counter;
}else{
  var mc:MovieClip =  empty.attachMovie("elbowPipe", "pipe"+counter, counter);
  mc._x = mc._width*j;
  mc._y = mc._height*i;
  mc.mc_type="elbow";
  mc._rotation=(Math.floor(Math.random()*4)*90);
  mc.mc_id=counter;
  //// add rotatio id
  if (mc._rotation==0) {
  
  mc.mcConnectionArray=["top","right","no","no"];
}else if(mc._rotation==90){
 
 mc.mcConnectionArray=["no","right","bottom","no"];
}else if(mc._rotation==180){
 
 mc.mcConnectionArray=["no","no","bottom","left"];
}else{
 
 mc.mcConnectionArray=["top","no","no","left"];
}
  
  
  /// end rotation id
  mc.onRelease=spinPipe;
}
 }
 
}
empty._xscale=empty._yscale=130
0;
 empty._x=(Stage.width- empty._width)/2;
 empty._y=(Stage.height- empty._height)/2;

if you look at the attach file

a pipe will change colour if it connects to the one on the left but not dependent on touching one on the left or right

to check right is roughly the asme code but target is +1, to check up is target -10, to below is target +10

i might do more at a later date …if i feel i am going in the right direction[/quote]

well can you explain in more detials …like with just 1 demo …
Thanks

[quote=tarwin;2333993]Man, you guys is crazy.

Just use a multidimensional array full of objects. So much easier! Have the objects hold what kind of pipe they are and a checker against other pipes. Then just go through the array and do checks from X pipe to all 4 pipes around it to check what’s happening. Even better, just go from the first active pipe and follow it along the line.

You’re not trying to write a game in machine code here, or even a game for a calculator (memory restrictions). The amount of memory for this app, and the processing of the code, will take about 1/100% of the memory of any one of your visual assets (probably even just a simple box).[/quote]

And how to pick element from array , this is As3 so i am new to that just tell me how to bind the element…thanks if you can post the fla…

[quote=tarwin;2333998]AS2 or 3?

Oh well … here’s an idea… At least a start …

ActionScript Code:
[LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**class**[/COLOR] Pipe[COLOR=#000000]{[/COLOR]

    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_STRAIGHT_VERTICAL:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_straight_vertical”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_STRAIGHT_HORIZONTAL:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_straight_horizontal”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_CROSS:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_cross”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_LEFT_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_left_top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_LEFT_BOTTM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_left_bottom”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_RIGHT_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_right_top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_RIGHT_BOTTOM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_right_bottom”[/COLOR];
    
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_RIGHT:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“right”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_BOTTOM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“bottom”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_LEFT:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“left”[/COLOR];
    
    public [COLOR=#000000]var[/COLOR] [COLOR=#0000FF]type[/COLOR]:[COLOR=#0000FF]String[/COLOR];
    
    public [COLOR=#000000]function[/COLOR] PipeCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
        type = _type;
    [COLOR=#000000]}[/COLOR]
    
    public [COLOR=#000000]function[/COLOR] joins[COLOR=#000000]([/COLOR]p:Pipe, [COLOR=#0000FF]position[/COLOR]:[COLOR=#0000FF]String[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000FF]Boolean[/COLOR]
    [COLOR=#000000]{[/COLOR]
        switchCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
            case PIPE_STRAIGHT_VERTICAL:
                if[COLOR=#000000]([/COLOR][COLOR=#0000FF]position[/COLOR] == POS_TOP || [COLOR=#0000FF]position[/COLOR] == POS_BOTTOM[COLOR=#000000])[/COLOR] [COLOR=#0000FF]return[/COLOR] [COLOR=#000000]true[/COLOR];
                break;
            case PIPE_STRAIGHT_HORIZONTAL:
                if[COLOR=#000000]([/COLOR][COLOR=#0000FF]position[/COLOR] == POS_LEFT || [COLOR=#0000FF]position[/COLOR] == POS_RIGHT[COLOR=#000000])[/COLOR] [COLOR=#0000FF]return[/COLOR] [COLOR=#000000]true[/COLOR];
                break;            
            case PIPE_CROSS:

                break;            
            case PIPE_LEFT_TOP:
            
                break;
            case PIPE_LEFT_BOTTM:
            
                break;
            case PIPE_RIGHT_TOP:
            
                break;
            case PIPE_RIGHT_BOTTOM:
            
                break;                
        [COLOR=#000000]}[/COLOR]
        returnCOLOR=#000000[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]

[/quote]

ok finaly i want to know how one can show the flow of water through connected pipes…

[quote=tarwin;2333998]AS2 or 3?

Oh well … here’s an idea… At least a start …

ActionScript Code:
[LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**class**[/COLOR] Pipe[COLOR=#000000]{[/COLOR]

    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_STRAIGHT_VERTICAL:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_straight_vertical”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_STRAIGHT_HORIZONTAL:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_straight_horizontal”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_CROSS:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_cross”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_LEFT_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_left_top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_LEFT_BOTTM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_left_bottom”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_RIGHT_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_right_top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] PIPE_RIGHT_BOTTOM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“pipe_right_bottom”[/COLOR];
    
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_TOP:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“top”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_RIGHT:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“right”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_BOTTOM:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“bottom”[/COLOR];
    public [COLOR=#0000FF]static[/COLOR] [COLOR=#000000]var[/COLOR] POS_LEFT:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“left”[/COLOR];
    
    public [COLOR=#000000]var[/COLOR] [COLOR=#0000FF]type[/COLOR]:[COLOR=#0000FF]String[/COLOR];
    
    public [COLOR=#000000]function[/COLOR] PipeCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
        type = _type;
    [COLOR=#000000]}[/COLOR]
    
    public [COLOR=#000000]function[/COLOR] joins[COLOR=#000000]([/COLOR]p:Pipe, [COLOR=#0000FF]position[/COLOR]:[COLOR=#0000FF]String[/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000FF]Boolean[/COLOR]
    [COLOR=#000000]{[/COLOR]
        switchCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]
            case PIPE_STRAIGHT_VERTICAL:
                if[COLOR=#000000]([/COLOR][COLOR=#0000FF]position[/COLOR] == POS_TOP || [COLOR=#0000FF]position[/COLOR] == POS_BOTTOM[COLOR=#000000])[/COLOR] [COLOR=#0000FF]return[/COLOR] [COLOR=#000000]true[/COLOR];
                break;
            case PIPE_STRAIGHT_HORIZONTAL:
                if[COLOR=#000000]([/COLOR][COLOR=#0000FF]position[/COLOR] == POS_LEFT || [COLOR=#0000FF]position[/COLOR] == POS_RIGHT[COLOR=#000000])[/COLOR] [COLOR=#0000FF]return[/COLOR] [COLOR=#000000]true[/COLOR];
                break;            
            case PIPE_CROSS:

                break;            
            case PIPE_LEFT_TOP:
            
                break;
            case PIPE_LEFT_BOTTM:
            
                break;
            case PIPE_RIGHT_TOP:
            
                break;
            case PIPE_RIGHT_BOTTOM:
            
                break;                
        [COLOR=#000000]}[/COLOR]
        returnCOLOR=#000000[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]

[/quote]