Results 1 to 5 of 5

Thread: Bank-Charity Game

  1. #1
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bank-Charity Game

    Am new in JavaScript and HTML, still learning the ropes. the scenario i am working on is this:

    An interactive game that will ask the player his name, and personal questions, then ask him if he intends to give money as charity today. if he answers no, the game will end. if he answers yes, the game will pick an amount at random (eg. 800,000) and say "Playername, you Have 800000 to give as charity today. You must spend every penny of it." then the game will pick beneficiaries at random and ask player, "how much are you donating to Christopher Jnr?" Player will mention an amount from the total Figure meant for charity. the game will then deduct the amount and say "Playername, thats good. Lets spend the remaining cash" the circle will continue (... then the game will pick beneficiaries at random and ask player, "how much are you donating to Christopher Jnr?".....) till all the amount is fully spent on charity and the game will end.

    would be very grateful with expert help. thanks.

  2. #2
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,521
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Hey there zamzam!
    Have you started programming this yet, or are you just getting into it?
    Also, are you looking for code that will do as you described, or advice on how to program it yourself?

  3. #3
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks so much. Actually started it on python but got stuck. So I chose JavaScript. Need help building it up. Thinking of using arrays and random but not good with them. Any help would be appreciated. Thanks.

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,800
    Thanks
    2
    Thanked 420 Times in 414 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>
    <script type="text/javascript">
    /*<![CDATA[*/
    var Charities=['Charity 1','Charity 2','Charity 3','Charity 4',];
    
    function Name(o){
     var frm=o.form,n=frm.name.value;
     document.getElementById('donate').style.display=n.replace(/\s/g,'')!=''?'block':'none';
     frm.YesNo[0].checked=frm.YesNo[1].checked=false;
    }
    
    function Open(o,m,x){
     var frm=o.form;
     document.getElementById('donation').style.display=o.value=='Yes'?'block':'none'
     if (m&&x&&m>0&&m<x){
      frm.total.value=Math.round(m+Math.random()*(x-m));
      frm.chartity.value=Charities[Math.floor(Math.random()*(Charities.length-1))];
      document.getElementById('message').innerHTML='';
      frm.amount.value='';
     }
    }
    
    function Donate(o){
     var frm=o.form,n=frm.amount.value.replace(/\D/g,'');
      if (n&&frm.chartity.value&&frm.total.value>0){
       n=parseInt(n);
       n=frm.total.value-n>0?n:frm.total.value;
       frm.total.value-=n;
       document.getElementById('message').innerHTML+=frm.name.value+' you have donated '+n+' to '+frm.chartity.value+'<br>';
       frm.chartity.value=Charities[Math.floor(Math.random()*(Charities.length-1))];
       frm.amount.value='';
      }
    }
    
    
    
    /*]]>*/
    </script></head>
    
    <body>
    <form>
     <div >Please Enter Your Name</div>
     <input name="name" value="DD" />
     <input type="button" value="Continue" onclick="Name(this);" />
     <div id="donate" style="display:none;">
      <input type="radio" name="YesNo" value="Yes" onclick="Open(this,2000,8000);" /> Yes/No <input type="radio" name="YesNo" value="No" onclick="Open(this);"/>
     </div>
     <div id="donation" style="display:none;" >
     <div ><span>You have </span><input name="total" /><span> to Donate</span></div>
     Donate To <input name="chartity" /> Donate Amount <input name="amount" /> <input type="button" name="" value="Donate"  onclick="Donate(this);"/>
     <div id="message"></div>
     </div>
    
    </form>
    
    </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/

  5. #5
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks alot.
    This really help.

Similar Threads

  1. looking for php game
    By vautz in forum Looking for such a script or service
    Replies: 7
    Last Post: 07-16-2012, 05:16 AM
  2. Rescue Charity needs help with coding.
    By chrisjl in forum HTML
    Replies: 2
    Last Post: 09-28-2010, 12:39 AM
  3. My first game!
    By evan in forum Flash
    Replies: 0
    Last Post: 10-22-2009, 02:57 PM
  4. Charity needs help with pausing up-down script
    By bdyoni in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-03-2008, 09:55 AM

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
  •