Results 1 to 4 of 4

Thread: Need Help for my JS Memory Game

  1. #1

    Default Need Help for my JS Memory Game

    Well i am making a memory game i have bits of it done but i don't know how to add scoring into it here is my scirpt

    Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    
    <SCRIPT LANGUAGE="javascript">
    var Pic = new Array(4)
    Pic[0] = '1.jpg'
    Pic[1] = '2.jpg'
    Pic[2] = '3.jpg'
    Pic[3] = '4.jpg'
    
    var p = Pic.length;
    var pre = new Array()
    for (i = 0; i < p; i++){
       pre[i] = new Image()
       pre[i].src = Pic[i]
    }
    var whichImage = Math.round(Math.random()*(p-1));
    function showImage(){
    document.write('<img src="'+Pic[whichImage]+'">');
    }
    var x
    var y
    var counter=0
    var wins=0
    var losses=0
    function rungame ()
    {
    
    if (counter<5)
    {
    var whichImage = Math.round(Math.random()*(p-1));
    function showImage(){
    document.write('<img src="'+Pic[whichImage]+'">');
    }
    
    s1 = new Image(118, 150)
    s1.src = "1.jpg"
    s2 = new Image(118, 150)
    s2.src = "2.jpg"
    s3 = new Image(118, 150)
    s3.src = "3.jpg"
    s4 = new Image(118, 150)
    s4.src = "4.jpg"
    
    document.form1.s01.style.visibility='visible'
    document.form1.s2.style.visibility='visible'
    document.form1.s3.style.visibility='visible'
    document.form1.s4.style.visibility='visible'
    
    x=Math.round(Math.random()*1)
    
        if (x==0)
        {
        document.form1.left.src = '2.jpg'
        document.form1.right.src = '1.jpg'
        document.form1.mid.src = '3.jpg'
        document.form1.center.src = '4.jpg'
        }
    }
    corr=new Array()
    guess=0
    score=0
    function runGame(x){
    guess++
    if(x==picked){document.src="correct.jpg";score++;corr[x]=1}else{document.src="wrong.jpg"}
    document.scrboard.counter.value=guess
    document.scrboard.score.value=score
    if(guess>3){
    alert("It's over! Score = "+score)
    for(x=1;x<6;x++){
    corr[x]=0
    }
    if(score==4) alert("And you win!")
    guess=0
    score=0
    }
    setTimeout('StartTest()',1000)
    }
    }
    
    
    </SCRIPT>
    
    <STYLE type="text/css">
    <!--
    .top    {position: absolute;
        top: 10px;
        left: 200px;
        z-index: 1;
        }
    .aboveLeft    {position: absolute;
        top: 250px;
        left: 125px;
        z-index: 2;
        }
    .belowLeft    {position: absolute;
        top: 250px;
        left: 125px;
        z-index: 1;
        }
    
    .aboveCenter    {position: absolute;
        top: 250px;
        left: 273px;
        z-index: 2;
        }
    .belowCenter    {position: absolute;
        top: 250px;
        left: 273px;
        z-index: 1;
        }
    
    .aboveRight    {position: absolute;
        top: 365px;
        left: 125px;
        z-index: 2;
        }
    .belowRight    {position: absolute;
        top: 365px;
        left: 125px;
        z-index: 1;
        }
    .aboveMid    {position: absolute;
        top: 365px;
        left: 273px;
        z-index: 2;
        }
    .belowMid    {position: absolute;
        top: 365px;
        left: 273px;
        z-index: 1;
        }
    
    .startbutton    {position: absolute;
        top: 500px;
        left: 200px;
        z-index: 1;
        }
    -->
    </STYLE>
    
    </HEAD>
    
    <BODY link="black" alink="black" vlink="black">
    
    <form name='scrboard'>
    Guesses: <input type=text size=3 name=counter> 
    <tr>
    <td align=right>
    <br>
    Score: <input type=text size=3 name=score>
    <tr><td>
    <br>
    <img src= correct.jpg width="100" height="50">
    </table>
    </form>
    
    <FORM NAME="form1">
    
    
    <DIV class="top">
     <SCRIPT language="JavaScript">
    <!-- Begin
    showImage();
    //  End -->
    </script>
    
    </div>
    
    <IMG name="s1" class="aboveLeft" src="0.gif" width="150" height="118" alt="img1" onClick="this.style.visibility='hidden'" >
    <IMG class="belowLeft" src="1.jpg" width="150" height="118" alt="CLICK TO PLAY AGAIN" name="left">
    
    <IMG class="aboveCenter" src="0.gif" width="150" height="118" alt="img2" onClick="this.style.visibility='hidden'" name="s2">
    <IMG class="belowCenter" src="2.jpg" width="150" height="118" alt="CLICK TO PLAY AGAIN"  name="center" style="position: absolute; left: 271; top: 249">
    
    <IMG class="aboveMid" src="0.gif" width="150" height="118" alt="img3" onClick="this.style.visibility='hidden'" name="s4" style="position: absolute; left: 273; top: 365; width: 150px" >
    <IMG class="belowMid" src="4.jpg" width="150" height="118" alt="CLICK TO PLAY AGAIN" name="right">
    
    <IMG class="aboveRight" src="0.gif" width="150" height="118" alt="img3" onClick="this.style.visibility='hidden'" name="s3">
    <IMG class="belowRight" src="3.jpg" width="150" height="118" alt="CLICK TO PLAY AGAIN" name="right" style="position: absolute; left: 125; top: 366">
    
    <input type="button" name="startbutton" value="Click Here to Begin" onClick="runGame(x)" class="startbutton">
    
    </FORM>
    </BODY>
    </HTML>

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    Please keep your questions to being EXT specific

  3. #3
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    So... where is the Ext exactly?

    That is some ugly javascript!

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    heh, yeah reminds me of how people do it on dynamicdrive.com heh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •