www.webdeveloper.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33

Thread: [RESOLVED] Quick Help needed, PLEASE! Help wit my assignment(Triple Roll game)

  1. #16
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    225
    Quote Originally Posted by Petersonik View Post
    I m looking forward to help somebody in the future I already have the book javascript for dumies I ll put more of my own time and invation to study = new years resolution == true
    That's the right attitude just continue to read and to improve your skills

  2. #17
    Join Date
    Dec 2013
    Posts
    23
    I am trying.. this assignment is ficused only on the js code... Thanks anyway. Maybe there is somebody willing to help and do the triple roll game for own pleasure If I would fail I know who to blaim I should start my battle much ealier

  3. #18
    Join Date
    Dec 2013
    Posts
    23
    Bionoid haha the monster

  4. #19
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    776
    ok, seeing as I had to do it, I had a little fun at the same time:

    index.htm
    Code:
    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title>Quick Help needed, PLEASE! Help wit my assignment(Triple Roll game)</title>
    
    		<style type="text/css">
    
    			#Dice0,
    			#Dice1,
    			#Dice2 {
    				position: absolute;
    				width: 50px;
    				height: 50px;
    				text-align: center;
    				line-height: 50px;
    				top: 80px;
    				margin-left: -25px;
    				border: 1px solid #000;
    				background-color: #fff;
    			}
    
    		</style>
    
    		<script type="text/javascript">
    
    			window.onload = function()
    			{
    				var
    					total_credit = 100,
    					dice = [],
    					amount, credit, message,
    					i;
    
    				for (i = 0; i < 3; ++i) {dice.push(document.getElementById('Dice' + i));}
    
    				function updateCredit(value)
    				{
    					total_credit += value;
    					credit.innerHTML = 'Credit: ' + total_credit;
    				}
    
    				credit  = document.getElementById('Credit');
    				amount  = document.getElementById('BetAmount');
    				message = document.getElementById('Message');
    				amount.onchange = function() {this.value = Math.max(parseInt('0' + this.value, 10), 1);};
    				document.getElementById('Bet').onclick = function()
    				{
    					var
    						betting = Number(amount.value),
    						values = [], winnings = 0,
    						i;
    
    					if (betting > 100)          {alert('You\'re bet is too high!');} else
    					if (betting > total_credit) {alert('You don\'t have enough credit!');} else {
    
    						updateCredit(-betting);
    						for (i = 0; i < dice.length; ++i) {dice[i].innerHTML = values[i] = Math.floor(Math.random() * 6) + 1;}
    
    						if (values[0] === values[1] && values[0] === values[2]) {winnings = (betting * (1 === values[0] ? 50 : 30)) + betting;} else
    						if (values[0] === values[1] || values[0] === values[2] || values[1] === values[2]) {winnings = (betting * 8) + betting;} else
    						if ((values[0] + values[1] + values[2]) >= 15) {winnings = (betting * 2) + betting;} else
    						if ((values[0] === 6 || values[1] === 6 || values[2] === 6) || ((values[0] % 2) && (values[1] % 2) && (values[2] % 2))) {winnings = betting;}
    
    						if (winnings) {
    							updateCredit(winnings);
    							message.innerHTML = 'You win <b>' + winnings + '</b> credits!';
    						} else {
    							message.innerHTML = 'You did not win!';
    						}
    					}
    				};
    
    				updateCredit(0);
    			};
    
    		</script>
    
    	</head>
    	<body>
    
    		<div style="background-color: #fafafa; border: 1px solid #000; width: 200px; height: 300px; margin: 0 auto; position: relative; overflow: hidden; border-radius: 5px;">
    
    			<div id="Credit" style="position: absolute; top: 5px; right: 5px;"></div>
    
    			<div id="Dice0" style="left: 20%;"></div>
    			<div id="Dice1" style="left: 50%;"></div>
    			<div id="Dice2" style="left: 80%;"></div>
    
    			<div id="Message" style="position: absolute; left: 5px; right: 5px; top: 170px; text-align: center;"></div>
    
    			<div style="text-align: center; background-color: #eee; border-top: 1px solid #000; padding: 4px 0; position: absolute; width: 100%; left: 0; bottom: 0;">
    				<input id="BetAmount" type="text" style="width: 60px; height: 1.5em; text-align: center;" value="1" />
    				<button id="Bet" style="width: 80px;">Bet</button>
    			</div>
    		</div>
    
    		<div style="width: 800px; margin: 10px auto;">
    		    <h1>Welcome to ACME casino Ltd!!</h1>
    		    <p>Tripple Roll Game - Rules:</p>
    			<ul>
    				<li>After you place your bet and press "Bet" button, dices are thrown.</li>
    				<li>For each round of the game, You can bet between 1 and 100.</li>
    				<li>Game has maximum of 10 rounds. At the end of each round You can continue or quit.</li>
    				<li>If 3 die all show value of 1 than You win your bet * 50 + Your original stake back.</li>
    				<li>If the 3 die all show three same values (other than the value 1), then You win your bet * 30 + Your original stake back.</li>
    				<li>If 2 die show the same value, then You win your bet * 8 + Your original stake back.</li>
    				<li>If none of these prizes have been won, if the total of die come to 15 or more, You win 2 * Your bet + orginal stake back.</li>
    				<li>If one die shows a 6, or all the values of the die are odd numbers, then You will get Your bet back.</li>
    			</ul>
    		</div>
    
    	</body>
    </html>
    JavaScript: Learn | Validate | Compact

  5. #20
    Join Date
    Dec 2013
    Posts
    23
    thanks I though You do not exist bionoid
    I have check deffinition of bionoid on wikipedia: Bionoids are chitinous, bipedal humanoid insects with a glowing circular gem in the center of their forehead. Though their appearance strikes fear in those who view them, their demeanor belies their looks. They originated as “Living Weapons” during the Unhuman Wars.
    Thanks for the reply

  6. #21
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    225
    Now go to study
    Last edited by tech_soul8; 12-12-2013 at 04:58 PM.

  7. #22
    Join Date
    Dec 2013
    Posts
    23
    all I need to do is make the game to last only 10 rounds, because is continue to play more rounds I ll try to figure it out..... I hope so

  8. #23
    Join Date
    Dec 2013
    Posts
    23
    I need to stuudy this code is pretty good

  9. #24
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    776
    Ok, added the 10 round limit, then it will prompt if you want to continue afterwards:

    index.htm
    Code:
    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8" />
    		<title>Quick Help needed, PLEASE! Help wit my assignment(Triple Roll game)</title>
    
    		<style type="text/css">
    
    			#Dice0,
    			#Dice1,
    			#Dice2 {
    				position: absolute;
    				width: 50px;
    				height: 50px;
    				text-align: center;
    				line-height: 50px;
    				top: 80px;
    				margin-left: -25px;
    				border: 1px solid #000;
    				background-color: #fff;
    			}
    
    		</style>
    
    		<script type="text/javascript">
    
    			window.onload = function()
    			{
    				var
    					total_credit = 100, rounds = 10,
    					dice = [],
    					amount, credit, message,
    					i;
    
    				for (i = 0; i < 3; ++i) {dice.push(document.getElementById('Dice' + i));}
    
    				function updateCredit(value)
    				{
    					total_credit += value;
    					credit.innerHTML = 'Credit: <u>' + total_credit + '</u> Rounds: <u>' + rounds + '</u>';
    				}
    
    				credit  = document.getElementById('Credit');
    				amount  = document.getElementById('BetAmount');
    				message = document.getElementById('Message');
    				amount.onchange = function() {this.value = Math.max(parseInt('0' + this.value, 10), 1);};
    				document.getElementById('Bet').onclick = function()
    				{
    					var
    						betting = Number(amount.value),
    						values = [], winnings = 0,
    						i;
    
    					if (!rounds)                {if (confirm('Would you like to continue?')) {rounds = 10; updateCredit(0);}} else
    					if (betting > 100)          {alert('You\'re bet is too high!');} else
    					if (betting > total_credit) {alert('You don\'t have enough credit!');} else {
    
    						rounds--;
    						updateCredit(-betting);
    						for (i = 0; i < dice.length; ++i) {dice[i].innerHTML = values[i] = Math.floor(Math.random() * 6) + 1;}
    
    						if (values[0] === values[1] && values[0] === values[2]) {winnings = (betting * (1 === values[0] ? 50 : 30)) + betting;} else
    						if (values[0] === values[1] || values[0] === values[2] || values[1] === values[2]) {winnings = (betting * 8) + betting;} else
    						if ((values[0] + values[1] + values[2]) >= 15) {winnings = (betting * 2) + betting;} else
    						if ((values[0] === 6 || values[1] === 6 || values[2] === 6) || ((values[0] % 2) && (values[1] % 2) && (values[2] % 2))) {winnings = betting;}
    
    						if (winnings) {
    							updateCredit(winnings);
    							message.innerHTML = 'You win <b>' + winnings + '</b> credits!';
    						} else {
    							message.innerHTML = 'You did not win!';
    						}
    					}
    				};
    
    				updateCredit(0);
    			};
    
    		</script>
    
    	</head>
    	<body>
    
    		<div style="background-color: #fafafa; border: 1px solid #000; width: 200px; height: 300px; margin: 0 auto; position: relative; overflow: hidden; border-radius: 5px;">
    
    			<div id="Credit" style="position: absolute; top: 5px; right: 5px;"></div>
    
    			<div id="Dice0" style="left: 20%;"></div>
    			<div id="Dice1" style="left: 50%;"></div>
    			<div id="Dice2" style="left: 80%;"></div>
    
    			<div id="Message" style="position: absolute; left: 5px; right: 5px; top: 170px; text-align: center;"></div>
    
    			<div style="text-align: center; background-color: #eee; border-top: 1px solid #000; padding: 4px 0; position: absolute; width: 100%; left: 0; bottom: 0;">
    				<input id="BetAmount" type="text" style="width: 60px; height: 1.5em; text-align: center;" value="1" />
    				<button id="Bet" style="width: 80px;">Bet</button>
    			</div>
    		</div>
    
    		<div style="width: 800px; margin: 10px auto;">
    		    <h1>Welcome to ACME casino Ltd!!</h1>
    		    <p>Tripple Roll Game - Rules:</p>
    			<ul>
    				<li>After you place your bet and press "Bet" button, dices are thrown.</li>
    				<li>For each round of the game, You can bet between 1 and 100.</li>
    				<li>Game has maximum of 10 rounds. At the end of each round You can continue or quit.</li>
    				<li>If 3 die all show value of 1 than You win your bet * 50 + Your original stake back.</li>
    				<li>If the 3 die all show three same values (other than the value 1), then You win your bet * 30 + Your original stake back.</li>
    				<li>If 2 die show the same value, then You win your bet * 8 + Your original stake back.</li>
    				<li>If none of these prizes have been won, if the total of die come to 15 or more, You win 2 * Your bet + orginal stake back.</li>
    				<li>If one die shows a 6, or all the values of the die are odd numbers, then You will get Your bet back.</li>
    			</ul>
    		</div>
    
    	</body>
    </html>
    JavaScript: Learn | Validate | Compact

  10. #25
    Join Date
    Dec 2013
    Posts
    23
    ok thank you. I much appreciate.
    I will try to use your functions to make it simpler version to understand it better as my assignment requiers only good valid javascript code(even without any user interface) with something like 'game over yet?' ; 'place bet'; 'roll dices'; and 'update winnings' functions-something like that. And all this in some for/while or do while loop
    or if you have 5 min to make very simple version for dumie like me with simple document.writeln messages and window.prompt s I ll be very happy and I ll own you a big big big favor.Please?
    var credit = 100;
    var bet = 0;
    var d1;
    var d2;
    var d3;
    var betInput;
    I think that s correct
    and my roll dice function which looks like that:
    var rolldice = function()
    {
    d1 = Math.round(Math.random()*6);
    d2 = Math.round(Math.random()*6);
    d3 = Math.round(Math.random()*6);
    }


    If you have time please simplyfy this for me....... much much much appriciate, thanks very much, I hope to gein skills like You or close to Your knowledge

  11. #26
    Join Date
    Dec 2013
    Posts
    23
    this exercise involves design, writing code and testing our software. I hope I am not such a pain and not asking for too much from You pro guys

  12. #27
    Join Date
    Dec 2013
    Posts
    23
    bionoid You are a star. Is there any chance You could make a realy simple version of it?? Just for me to follow and understand all this task better? Only if You have time and if You are patient enough to do so. Cheers

  13. #28
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    776
    ok, a REALLY simple version of it... :P

    Code:
    <h1>Welcome to ACME casino Ltd!!</h1>
    <p>Tripple Roll Game - Rules:</p>
    <ul>
    	<li>After you place your bet and press "Bet" button, dices are thrown.</li>
    	<li>For each round of the game, You can bet between 1 and 100.</li>
    	<li>Game has maximum of 10 rounds. At the end of each round You can continue or quit.</li>
    	<li>If 3 die all show value of 1 than You win your bet * 50 + Your original stake back.</li>
    	<li>If the 3 die all show three same values (other than the value 1), then You win your bet * 30 + Your original stake back.</li>
    	<li>If 2 die show the same value, then You win your bet * 8 + Your original stake back.</li>
    	<li>If none of these prizes have been won, if the total of die come to 15 or more, You win 2 * Your bet + orginal stake back.</li>
    	<li>If one die shows a 6, or all the values of the die are odd numbers, then You will get Your bet back.</li>
    </ul>
    <script type="text/javascript">
    
    	var
    		die1, die2, die3,
    		i, betting = 1, credit = 100, winnings;
    
    	for (i = 1; i <= 10; ++i) {
    
    		betting = parseInt('0' + prompt('Current Credit: ' + credit + '\nPlease enter bet amount! or Cancel to quit!', betting), 10);
    
    		if (!betting) {break;}
    
    		die1 = Math.floor(Math.random() * 6) + 1;
    		die2 = Math.floor(Math.random() * 6) + 1;
    		die3 = Math.floor(Math.random() * 6) + 1;
    
    		if (die1 === die2 && die1 === die3) {winnings = (betting * (1 === die1 ? 50 : 30)) + betting;} else
    		if (die1 === die2 || die1 === die3 || die2 === die3) {winnings = (betting * 8) + betting;} else
    		if ((die1 + die2 + die3) >= 15) {winnings = (betting * 2) + betting;} else
    		if ((die1 === 6 || die2 === 6 || die3 === 6) || ((die1 % 2) && (die2 % 2) && (die3 % 2))) {winnings = betting;} else {
    			winnings = 0;
    		}
    
    		credit -= betting;
    		if (winnings) {credit += winnings;}
    
    		alert(
    			'Round: ' + i + '\n' +
    			'You rolled: ' + die1 + ', ' + die2 + ', ' + die3 + '\n' +
    			'You bet: ' + betting + '\n' +
    			(winnings ? 'You won ' + winnings + '!' : 'You did not win!') + '\n\n' +
    			'Your current credit is: ' + credit
    		);
    
    	}
    
    	alert('You walk away with ' + credit + ' credits!');
    
    </script>
    Now I need to sleep.
    JavaScript: Learn | Validate | Compact

  14. #29
    Join Date
    Dec 2013
    Posts
    23
    have a good night mate. I d come meet You one day drinking session involed haha. Whenever you are don't think in binary for too long.
    cheers

  15. #30
    Join Date
    Dec 2013
    Posts
    23
    Just trying to make it stop bet more than 100

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles