Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Nicole Buck
//Prog 109 Project 3
var bet = 0;
var credits = 100;
var count = 0;
var slotImages = new Array("lemon.png", "plum.png", "bell.png", "diamond.png", "clover.jpg");
function BetChange() {
totCredits = credits;
if (bet < 20) {
bet += credits < 5 ? credits : 5;
credits -= credits > 5 ? 5 : credits;
document.getElementById("totalAmount").innerHTML = " $" + bet;
document.getElementById("credits").innerHTML = "$" + credits;
}
else if (bet >= 20) {
document.getElementById("minBet").disabled;
document.getElementById("maxBet").disabled;
}
document.getElementById("winnings").src = "nocoin.jpg";
document.getElementById("start").disabled = false;
if (credits < 5) {
bet = credits;
credits -= totCredits;
}
if (credits == 0) {
GameOver();
}
}
function MaxChange() {
totalCredits = credits;
if (count < 1 && bet != 20) {
bet = 20;
credits -= 20;
count += 1;
}
if (credits < 20) {
bet = credits;
credits -= totalCredits;
}
if (count == 1) {
document.getElementById("maxBet").disabled;
document.getElementById("minBet").disabled;
}
if (credits == 0) {
GameOver();
}
document.getElementById("winnings").src = "nocoin.jpg";
document.getElementById("totalAmount").innerHTML = " $" + bet;
document.getElementById("credits").innerHTML = "$" + credits;
document.getElementById("start").disabled = false;
}
function Roll() {
imageIndex1 = Math.floor(Math.random() * 5);
imageIndex2 = Math.floor(Math.random() * 5);
imageIndex3 = Math.floor(Math.random() * 5);
document.getElementById("firstPic").src = slotImages[imageIndex1];
document.getElementById("secondPic").src = slotImages[imageIndex2];
document.getElementById("thirdPic").src = slotImages[imageIndex3];
Payout();
document.getElementById("start").disabled = true;
}
function Payout() {
count = 0;
var first = document.getElementById("firstPic");
var second = document.getElementById("secondPic");
var third = document.getElementById("thirdPic");
if (first.src == second.src && second.src == third.src) {
credits += 30;
document.getElementById("credits").innerHTML = "$" + credits;
document.getElementById("winnings").src = "coins.jpg";
}
else if (first.src == second.src || second.src == third.src) {
credits += 10;
document.getElementById("credits").innerHTML = "$" + credits;
document.getElementById("winnings").src = "smcoin.jpg";
}
else if (first.src == third.src) {
credits += 10;
document.getElementById("credits").innerHTML = "$" + credits;
document.getElementById("winnings").src = "smcoin.jpg";
}
bet = 0;
}
function GameOver() {
document.getElementById("maxBet").disabled;
document.getElementById("minBet").disabled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment