|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Wanna shuffle the deck?
Blackjack made simple, courtesy of Binky. Code:
<html>
<head>
<style type="text/css">
</style>
<script type="text/javascript">
var chosen = new Array()
var cardArray = new Array('A','2','3','4','5','6','7','8','9','10','J','Q','K')
var compArray = new Array()
var cpuArray = new Array()
var turn = 'comp'
var p = 0; c = 0
function deal() {
if (document.forms[0].CPU.value == "") {
while (compArray.length != 2) {
match = false
card = Math.floor(Math.random() * 13)
suit = Math.floor(Math.random() * 4)
for (x = 0; x < chosen.length; x++) {
if (chosen[x] == card + "_" + suit) {
match = true
}
}
if (!match) {
card = cardArray[card]
compArray[p] = card
document.forms[0].ONEUP.value = document.forms[0].ONEUP.value + card + " "
}
p++
}
testScore()
while (cpuArray.length != 2) {
match = false
card = Math.floor(Math.random() * 13)
suit = Math.floor(Math.random() * 4)
for (x = 0; x < chosen.length; x++) {
if (chosen[x] == card + "_" + suit) {
match = true
}
}
if (!match) {
card = cardArray[card]
cpuArray[c] = card
document.forms[0].CPU.value = document.forms[0].CPU.value + "* "
}
c++
}
}
}
function take() {
match = false
card = Math.floor(Math.random() * 13)
suit = Math.floor(Math.random() * 4)
for (x = 0; x < chosen.length; x++) {
if (chosen[x] == card + "_" + suit) {
match = true
}
}
if (match) {
take()
} else {
card = cardArray[card]
if (turn == 'comp') {
compArray[p] = card
document.forms[0].ONEUP.value = document.forms[0].ONEUP.value + card + " "
p++
testScore()
} else {
cpuArray[c] = card
document.forms[0].CPU.value = document.forms[0].CPU.value + card + " "
c++
goCPU()
}
}
}
function testScore() {
compScore = 0
for (p = 0; p < compArray.length; p++) {
for (x = 0; x < cardArray.length; x++) {
if (cardArray[x] == compArray[p]) {
if (x >= 9) {
compScore = compScore + 10
} else if (x != 0) {
compScore = compScore + x + 1
}
}
}
}
for (p = 0; p <compArray.length; p++) {
if (compArray[p] == 'A') {
if (compScore + 11 > 21) {
compScore++
} else {
compScore = compScore + 11
}
}
}
if (compScore > 21) {
document.forms[0].OUTPUT.value = 'You\'re over, computer wins!'
turn = 'cpu'
}
}
function goCPU() {
reveal()
if (document.forms[0].OUTPUT.value == "") {
cpuScore = 0
for (c = 0; c < cpuArray.length; c++) {
for (x = 0; x < cardArray.length; x++) {
if (cardArray[x] == cpuArray[c]) {
if (x > 9) {
cpuScore = cpuScore + 10
} else if (x != 0){
cpuScore = cpuScore + x + 1
}
}
}
}
for (c = 0; c <cpuArray.length; c++) {
if (cpuArray[c] == 'A') {
if (cpuScore + 11 > 21) {
cpuScore++
} else {
cpuScore = cpuScore + 11
}
}
}
if (cpuScore > 21) {
document.forms[0].OUTPUT.value = 'Computer is over, player wins!'
reveal()
} else if (cpuScore >= compScore) {
document.forms[0].OUTPUT.value = 'Computer wins!'
reveal()
} else {
setTimeout("take()",500)
}
}
}
function reveal() {
document.forms[0].CPU.value = ""
for (c = 0; c < cpuArray.length; c++) {
document.forms[0].CPU.value = document.forms[0].CPU.value + cpuArray[c] + " "
}
}
</script>
</head>
<body>
<form>
<table border='0'>
<tr><td>You</td><td><input name='ONEUP' value='' size='30'></td></tr>
<tr><td>Computer</td><td><input name='CPU' value='' size='30'></td></tr>
<tr><td> </td><td><input name='OUTPUT' value='' size='30'></td></tr>
</table>
</form>
<input type='button' value='Deal' onClick='deal()'> <input type='button' value='Take Card' onClick='take()'><br>
<input type='button' value='Stick' onClick='turn = "cpu";goCPU()'> <input type='button' value='Play Again' onClick='window.location.reload()'>
</body>
</html>
![]() |
|
#2
|
||||
|
||||
|
expected ';' line 99
you the man! good script
__________________
_______________ Matt |
|
#3
|
||||
|
||||
|
It doesn't work for me either. Tried it under Opera (no surprise on that one though) and IE6
Nothing happens..... |
|
#4
|
|||
|
|||
|
Doesn't actually do anything for me either
![]() I take it you're still extrememly bored Binky? ![]()
__________________
Charkus |
|
#5
|
||||
|
||||
|
Hey Binky.. if you're still looking for something other than a clock or Tetris-game to program... go program a decent open-source HTML WYSIWYG editor for Windoze... I'll bet a lot of people would go for that
|
|
#6
|
||||
|
||||
|
Worked in my version of IE6, but maybe that version is kind on errors. Don't know, just spent five minutes doing it then got back to some proper work. Unfortunately I have a report to write up, then holiday (not unfortunately) so I'll not have much time on my hands.
Nice to see you're back Charkus. WYSIWYG editor for windows, hmmm, I have plans on the WYSIWYG front that involves a web based version that can be clicked and dragged a la Dreamweaver/Homesite etc.. I've worked how to do the dragging borders and other stuff like that, .... in fact that gives me an idea, but keeping shtum at the mo. |
|
#7
|
|||
|
|||
|
I was back, but then I had a holiday.....
Back at work again now ![]() That WYSIWYG editor sounds like a good idea, should take you too long Binky ![]() Of course, you'll make it PHP friendly won't you? |
|
#8
|
||||
|
||||
|
My turn to be on holiday.
The WYSIWYG editor idea is going to be much more than that... but it'll take a good while when it gets going. HTML/JavaScript/PHP/CSS all intergrated in one package! Stay tooned.. |
![]() |
| Viewing: Dev Shed Forums > Other > Dev Shed Lounge > Take the weight off your feet and have a game o' cards! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|