Jump to content

A Game we can play online !


Commander

Recommended Posts

Commander,

 

OK. You move first.

 

Regards, TAR

 

TAR ,

 

Alright, here we go.

 

I think you have now analyzed well and I might have a tough time.

 

Regards, Thomas

 

|

| |

| | | | |

| | | | | | |

Edited by Commander
Link to comment
Share on other sites

  • 2 months later...
The expert Programmers here like Sensei, fiveworlds , Janus etc can improve on the online implementation of this.

 

 

Well since you asked so nicely. I made the game with zero security and it will allow a player to make as many moves as they want so be honest.

<?php
if(file_exists("matchsticks.txt")){
    $matches=file_get_contents("matchsticks.txt");
    if($matches==="\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\""){
        $fp=fopen("matchsticks.txt","w");
        fwrite($fp,"\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\"");
        fclose($fp);
        $matches="\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\"";
        
    }
    if(isset($_REQUEST["checkbox"]))
    {
        $matches = explode(",",str_replace("\"","",$matches));
         for ($i = 0; $i < count($_REQUEST["checkbox"]); ++$i) {
            $matches[$_REQUEST["checkbox"][$i]]=0;                
        }
        $temp=NULL;
        for ($i = 0; $i < count($matches); ++$i){
            $temp=$temp."\"".$matches[$i]."\"".",";
        }
        $matches=trim($temp, ",");
        file_put_contents("matchsticks.txt",$matches);
    }
    
    echo "<script>matches=new Array({$matches});";
    loadpage();
    
}
else{
    echo "<script>matches=new Array(\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\";)";
    loadpage();
    $fp=fopen("matchsticks.txt","w");
    fwrite($fp,"\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\"");
    fclose($fp);
}

function loadpage(){
    echo "var images = new Array();
    var checkboxes = new Array();
    var table = \"\";
    var form = \"\";
    for    (index = 0; index < matches.length; index++) {
        if(matches[index]===\"1\")
        {
            images[index]=\"<img src=matchstick.jpg />\";
            checkboxes[index]=\"<input type='checkbox' name='checkbox[]' value='\"+index+\"'>\";
        }
        else
        {
            images[index]=\" \";
            checkboxes[index]=\"\";
        }
        
        if(index===0)
        {
            table+=\"<table><tr><td>\"+images[index]+\"</td><td> </td><td> </td><td> </td><td> </td></tr>\";
            form+=\"<form method=get>Row 1\"+checkboxes[index]+\"<input type='submit' value='Submit'></br></form>\";
        }
        
        if(index===2)
        {
            table+=\"<tr><td>\"+images[index-1]+\"</td><td>\"+images[index]+\"</td><td> </td><td> </td><td> </td></tr>\";
            form+=\"<form method=get>Row 2\"+checkboxes[index-1]+checkboxes[index]+\"<input type='submit' value='Submit'></br></form>\";
        }
        
        if(index===5)
        {
            table+=\"<tr><td>\"+images[index-2]+\"</td><td>\"+images[index-1]+\"</td><td>\"+images[index]+\"</td><td> </td><td> </td></tr>\";
            form+=\"<form method=get>Row 3\"+checkboxes[index-2]+checkboxes[index-1]+checkboxes[index]+\"<input type='submit' value='Submit'></br></form>\";
        }
        
        if(index===9)
        {
            table+=\"<tr><td>\"+images[index-3]+\"</td><td>\"+images[index-2]+\"</td><td>\"+images[index-1]+\"</td><td>\"+images[index]+\"</td><td> </td></tr>\";
            form+=\"<form method=get>Row 4\"+checkboxes[index-3]+checkboxes[index-2]+checkboxes[index-1]+checkboxes[index]+\"<input type='submit' value='Submit'></br></form>\";
        }
        
        if(index===14)
        {
            table+=\"<tr><td>\"+images[index-4]+\"</td><td>\"+images[index-3]+\"</td><td>\"+images[index-2]+\"</td><td>\"+images[index-1]+\"</td><td>\"+images[index]+\"</td></tr></table>\";
            form+=\"<form method=get>Row 5\"+checkboxes[index-4]+checkboxes[index-3]+checkboxes[index-2]+checkboxes[index-1]+checkboxes[index]+\"<input type='submit' value='Submit'></br></form>\";
        }
    }

    document.write(table+form);


</script>";

}
?>
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.