PDA

View Full Version : Bank-Charity Game



zamzam
04-05-2014, 04:14 PM
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.

keyboard
04-05-2014, 11:06 PM
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?

zamzam
04-06-2014, 06:38 AM
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.

vwphillips
04-06-2014, 03:22 PM
<!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>

zamzam
04-09-2014, 06:08 PM
Thanks alot.
This really help.