Hello everyone.

I am ending a SVG document that allows the user to throw in a 
Javascript programmed dice four svg pieces around a 40 piece board 
(like Monopoly game)...

The doubt is about the final position of the piece, I want to catch 
using javascript that position so I can use this position in other 
facts of the project.

By now i am passing only the javascript program, I hope I can give 
you an idea what i am doing.

I must say first that I don't want any correction, this program is 
working really fine, thanks for the help of some of you, I am only 
trying to find a way to catch the value called "i" to set it in 
other page.

Thanks and sorry for the long code.

Travsam

Code (svg not included, sorry for put the comments between 
parenthesis)

(declaring variables)
 var currentTime=0
        var timeText
        var gameboard= new Array()
        var player1
        var player2
        var player3
        var player4
        var comment
        var comment2
        var comment3
        var color
        var pM
        var pP
        var cP=1
        var k=0
        var svgns="http://www.w3.org/2000/svg";;
        var xlinkns="http://www.w3.org/1999/xlink";; 
               
(this function works when the user loads the svg)
        function init(){
        if ( window.svgDocument == null )
            svgDocument = evt.target.ownerDocument;
        for(var i=0;i<40;i++) {
        var f= document.getElementById("field"+i);
        gameboard.push(new field(f));
        }
        player1=new player(svgDocument.getElementById("player1"));
        player2=new player(svgDocument.getElementById("player2"));
        player3=new player(svgDocument.getElementById("player3"));
        player4=new player(svgDocument.getElementById("player4"));
        timeText=document.getElementById("text");
        setInterval("gameloop()",10);
        }

(this update the player position)
    function gameloop() {
        currentTime++
        //timeText.firstChild.nodeValue=currentTime
        player1.update()
        player2.update()
        player3.update()
        player4.update()
        }
        
(set the x and y of every field of the board)
        function field(svg){
        var x=svg.getAttribute("x")*1
        var y=svg.getAttribute("y")*1
        var w=svg.getAttribute("width")*1
        var h=svg.getAttribute("height")*1
        this.svg=svg
         this.x=x+w/5
         this.y=y+h/5
         }

(

(set the values of throwdice and allows to make the movement of the 
pieces, x and y must increase or decrease when they find some limits 
on the screen just like a board)
        function player(svg){
                this.svg=svg
                this.field=0
                this.move=0
                this.currentX=gameboard[0].x*1
                this.currentY=gameboard[0].y*1
                this.dx=0
                this.dy=0
                this.update= function() {
                if(this.dx==0 && this.dy==0 && this.move!=0) {
                        this.move-=1
                        oldField=this.field*1
                        newField=oldField*1+1
                        if(newField>=40){newField=0;}
                        this.dx=gameboard[newField].x-gameboard
[oldField].x
                        this.dy=gameboard[newField].y-gameboard
[oldField].y
                        this.field=newField
                        }
                if (this.dx>0) {
                        this.dx-=2
                        this.currentX+=2
                        }
                if(this.dy<0){
                        this.dy+=2
                        this.currentY-=2
                        }
                if(this.dx<0){
                        this.dx+=2
                        this.currentX-=2
                        }
                if(this.dy>0) {
                        this.dy-=2
                        this.currentY+=2
                        }
        this.svg.setAttribute("x",this.currentX)
        this.svg.setAttribute("y",this.currentY)
        }

        }

(make two random numbers between 1 to 6 and set it on function 
player, then pass the turn to the next player, if the user rolls 
double the user must roll again)
        function throwDice(){
        
        var randomDice=Math.round(Math.random()*5) + 1;
        var randomDice2=Math.round(Math.random()*5) + 1;
        dice = randomDice;
        dice2 = randomDice2;
        window["player"+cP].move= (randomDice + randomDice2);
        for(var i = 1;i<7;i++){
        var d = document.getElementById("d"+ i);
        if(i==dice){
        d.setAttribute( "visibility", "visible" );
        }else{
        d.setAttribute( "visibility", "hidden" );
        }

        }

        for(var j = 1;j<7;j++){
        var e = document.getElementById("e"+ j);
        if(j==dice2){
        e.setAttribute( "visibility", "visible" );
        }else{
        e.setAttribute( "visibility", "hidden" );
        }

        }
        if (dice!=dice2){
        k=0;
        if(cP==1){cP=2}
        else if (cP==2) {cP=3}
        else if (cP==3) {cP=4}
        else {cP=1}
        } else {
                k=k+1;
                if (k==3){
                        window["player"+cP].field=field11;
                        }
                }
        }





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/1U_rlB/TM
--------------------------------------------------------------------~-> 

-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




Reply via email to