Results 1 to 3 of 3

Thread: Making a random card game

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Making a random card game

    Hello, I have a limited to basic understanding of coding and have come to the conclusion I need some help on a project for my site.

    I currently have a card game as a printable, but would like to have a version playable in browser. I'm thinking javascript is the way to go here. PHP is not available to me, however I am able to insert code directly into the page. The game would consist of a "startup" image with rules etc. , and then click that image to randomly load one of roughly one hundred card images, then another round and so on. No ending round is needed for this type of game. Also the images will likely be hosted on a separate site so linked by url.

    Any and all help is greatly appreciated!
    Last edited by ryank; 03-17-2015 at 02:10 AM.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <img id="img1" src="http://www.vicsjavascripts.org/StdImages/1.gif" onclick="zxcRandomImage.Random('img1');"/>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcRandomImage={
    
      Random:function(id){
       var o=this['zxc'+id],n,ni;
       if (o){
        n=Math.floor(Math.random()*o.ary.length);
        while (n==o.n){
         n=Math.floor(Math.random()*o.ary.length);
        }
        o.n=n;
        ni=new Image();
        ni.src=o.ary[n]
        this.load(o,ni);
       }
      },
    
      Init:function(o){
       var id=o.ImageID,ary=o.SRCArray,img=document.getElementById(id);
       if (img&&ary instanceof Array&&ary.length>1){
        o.img=img;
        o.ary=ary;
        o.n=-1;
        this['zxc'+id]=o;
       }
      },
    
      load:function(o,ni){
       var oop=this;
       clearTimeout(o.to);
       if (ni.width<40){
        return o.to=setTimeout(function(){  oop.load(o,ni); },200);
       }
       o.img.src=ni.src;
      }
    }
    
    zxcRandomImage.Init({
     ImageID:'img1',
     SRCArray:[
      'http://www.vicsjavascripts.org/StdImages/1.gif',
      'http://www.vicsjavascripts.org/StdImages/2.gif',
      'http://www.vicsjavascripts.org/StdImages/3.gif',
      'http://www.vicsjavascripts.org/StdImages/4.gif',
      'http://www.vicsjavascripts.org/StdImages/5.gif'  // no commer
     ]
    });
    
    /*]]>*/
    </script>
    
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    ryank (03-17-2015)

  4. #3
    Join Date
    Mar 2015
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot! That works beautifully!

Similar Threads

  1. In need of some advice for making a game...
    By Rockonmetal in forum Other
    Replies: 1
    Last Post: 07-01-2008, 11:36 PM
  2. DHTML Game making
    By turkey1605 in forum JavaScript
    Replies: 2
    Last Post: 06-09-2007, 10:27 PM
  3. Card game in HTML, CSS and PHP
    By jalbam in forum Submit a DHTML or CSS code
    Replies: 2
    Last Post: 09-01-2006, 02:30 PM
  4. Random Game Generator
    By MommaCassie in forum JavaScript
    Replies: 3
    Last Post: 01-24-2006, 07:38 PM
  5. Random Game Generator
    By MommaCassie in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 01-24-2006, 07:38 PM

Bookmarks

Posting Permissions

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