I don't understand what's wrong..
Trying to do a very simple slot machine and can't figure out where's mistake.
And I need to check if it's 3 pikachus - add to amt 1000, but if it's 3 charmanders - add 500. "amt" is a current amount of coins. At the beginning it's equal 100. Every attempt costs 10 coins. Can someone give me some ideas?
var slotitem = [];
slotitem[0] = "slowpoke";
slotitem[1] = "snorlax";
slotitem[2] = "squirtle";
slotitem[3] = "bulbasaur";
slotitem[4] = "charmander";
slotitem[5] = "picachu";
var coins = 100;
var arm = document.getElementById('arm');
arm.onclick = function(){
this.classList.toggle('rotate')
//this.style.height = '200px';
//this.style.width= '100px';
};
/*arm.onclick = function() {
var start = Date.now(); // сохранить время начала
var timer = setInterval(function() {
// вычислить сколько времени прошло из opts.duration
var timePassed = Date.now() - start;
arm.style.top = timePassed / 7 + 'px';
if (timePassed > 1000) clearInterval(timer);
}, 20);
}
*/
///////////////////////////
slots.txtCoins.value="100";
///////////////////////////
function rollem() {
counter = 0;
spinem();
}
function spinem() {
turns1 = 6 + Math.floor((Math.random() * 6))
for (a = 0; a < turns1; a++) {
document.slots.slot1.src = "" + slotitem[a % 6] + ".png";
}
turns2 = 6 + Math.floor((Math.random() * 6))
for (b = 0; b < turns2; b++) {
document.slots.slot2.src = "" + slotitem[b % 6] + ".png";
}
turns3 = 6 + Math.floor((Math.random() * 6))
for (c = 0; c < turns3; c++) {
document.slots.slot3.src = "" + slotitem[c % 6] + ".png";
}
counter++;
console.log(counter);
if (counter < 25) {
setTimeout("spinem(counter);", 50);
} else {
checkmatch();
}
}
function checkmatch() {
var amt = parseInt(slots.txtCoins.value);
if (amt != 0){
if ((document.slots.slot1.src == document.slots.slot2.src) && (document.slots.slot1.src == document.slots.slot3.src)) {
amt = amt + 1000;
slots.txtCoins.value = amt;
} else if ((document.slots.slot1.src + slotitem == 0 == document.slots.slot2.src + slotitem == 0)
|| (document.slots.slot1.src + slotitem == 0 == document.slots.slot3.src + slotitem == 0)
|| (document.slots.slot2.src + slotitem == 0 == document.slots.slot3.src + slotitem == 0)) {
amt = amt - 10;
slots.txtCoins.value = amt;
} else if ((document.slots.slot1.src == document.slots.slot2)
|| (document.slots.slot1 == document.slots.slot3)
|| (document.slots.slot2 == document.slots.slot3)) {
amt = amt + 100;
slots.txtCoins.value = amt;
} else if ((document.slots.slot1.src != document.slots.slot2.src) && (document.slots.slot1.src != document.slots.slot3.src)){
alert("Попробуйте еще раз!");
}
}
else
alert("Кажется, у вас закончились монетки. Удачи в следующий раз!");
}
/*function checkmatch1(){
var amt = parseInt(slots.tstCoins.value);
var slowpokes,snorlaxes,squirtles,bulbasaures,charmanderes,
picachus;
slowpokes=0;
snorlaxes=0;
squirtls=0;
bulbasaurs=0;
charmanders=0;
picachus=0;
if (amt != 0) {
for (x = 0; x < 3; x++){
switch(){
case "slowpoke.png":
slowpokes++;
break;
case "snorlax.png":
snorlaxes++;
break;
case "squirtle.png":
squirtls++;
break;
case "bulbasaur.png":
bulbasaurs++;
break;
case "charmander.png":
charmanders++;
break;
case "picachu.png":
picachus++;
break;
}
if (picachus == 3){
amt = amt + 1000;
}
else if(charmanders == 3){
amt = amt + 500;
}
else if(bulbasaurs == 3){
amt = amt + 300;
}
else if((squirtls == 3) || (snorlaxes == 3) || (slowpokes == 3)){
amt = amt + 100;
}
}
}
}
*/
body{
background-image: url(pics/backpic.jpg);
background-size: 100% 700%;
}
h1{
font-family: 'Luckiest Guy', cursive;
font-size: 50px;
text-align: center;
color: #F5DA1C;
text-shadow: #5F7DC4 3px 3px 0, #5F7DC4 0px 0px 0,
#5F7DC4 0px 0px 0, #5F7DC4 3px -3px 0;
}
img{
width: 100px;
}
#square {
position:absolute;
left: 215px;
top: 200px;
width: 370px;
height: 180px;
background: #5F7DC4;
}
#roundsquare {
position: absolute;
width: 400px;
height: 310px;
top:150px;
left:200px;
background: #9AC1DA;
border-radius: 50px;
}
#squarebottom {
position: absolute;
width:450px;
height:100px;
top:380px;
left: 175px;
background: #9AC1DA;
border-radius: 30px;
}
#linearm{
position: absolute;
width: 70px;
height: 10px;
background: #BDBDAD;
left: 600px;
top:280px;
}
#linearm2{
position: absolute;
width: 10px;
height: 70px;
background: #BDBDAD;
left: 660px;
top:210px;
}
#arm{
position: absolute;
width: 50px;
height: 100px;
background: #EBEB42;
border-radius: 20px;
left: 640px;
transition: transform 1s ease;
}
.rotate{
transform: rotate(180deg);
}
table{
position:relative;
float:left;
left: 213px;
top: 80px;
background: white;
border: 5px solid #5F7DC4;
border-radius: 10px;
width: 350px;
}
input {
position: relative;
top:275px;
left:-100px;
width: 100px;
height: 50px;
padding-right: 50px;
font-family: 'Luckiest Guy', cursive;
font-size: 35px;
color: #F5DA1C;
text-shadow: #5F7DC4 3px 3px 0, #5F7DC4 0px 0px 0,
#5F7DC4 0px 0px 0, #5F7DC4 3px -3px 0;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pokemon slot machine</title>
<link href="https://fonts.googleapis.com/css?family=Luckiest+Guy" rel="stylesheet">
<title>Dice Game</title>
<link href="slot3styles.css" rel="stylesheet">
<script src="slot3.js" defer></script>
</head>
<body>
<h1>POKEMON SLOT MACHINE</h1>
<form name=slots onsubmit="rollem(); return false;">
<div id="roundsquare"></div>
<div id="square"></div>
<div id="squarebottom"></div>
<div id="linearm"></div>
<div id="slider">
<div id="linearm2"></div>
<div id="arm"></div>
</div>
<table cellspacing=5 cellpadding=2>
<tr>
<td> <img src="picachu.png" name=slot1> </td>
<td> <img src="picachu.png" name=slot2> </td>
<td> <img src="picachu.png" name=slot3> </td>
</tr>
</table>
<tr>
<th>
<td><input type="text" name="txtCoins" value="0" id="coins" readonly></td>
<td> <input class="button" type=submit value="PLAY"> </td>
</th>
</tr>
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire