Dev Shed Lounge
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherDev Shed Lounge

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 8th, 2002, 05:09 AM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 18
Cool Take the weight off your feet and have a game o' cards!

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>&nbsp;</td><td><input name='OUTPUT' value='' size='30'></td></tr>
</table>
</form>
<input type='button' value='Deal' onClick='deal()'>&nbsp;<input type='button' value='Take Card' onClick='take()'><br>
<input type='button' value='Stick' onClick='turn = "cpu";goCPU()'>&nbsp;<input type='button' value='Play Again' onClick='window.location.reload()'>
</body>
</html>


__________________
- Sorted!

www.ppfuk.com - Free Photo Sharing

Reply With Quote
  #2  
Old July 9th, 2002, 03:56 AM
Utopia's Avatar
Utopia Utopia is offline
superficial
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Peterborough, England
Posts: 188 Utopia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 36 m 8 sec
Reputation Power: 7
expected ';' line 99

you the man! good script
__________________
_______________
Matt

Reply With Quote
  #3  
Old July 15th, 2002, 11:53 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
It doesn't work for me either. Tried it under Opera (no surprise on that one though) and IE6 Nothing happens.....

Reply With Quote
  #4  
Old July 16th, 2002, 06:41 AM
charkus charkus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bath, England
Posts: 312 charkus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 14 sec
Reputation Power: 7
Doesn't actually do anything for me either

I take it you're still extrememly bored Binky?
__________________
Charkus

Reply With Quote
  #5  
Old July 16th, 2002, 07:01 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
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

Reply With Quote
  #6  
Old July 21st, 2002, 06:44 AM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 18
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.

Reply With Quote
  #7  
Old July 29th, 2002, 04:00 AM
charkus charkus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: Bath, England
Posts: 312 charkus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 14 sec
Reputation Power: 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?

Reply With Quote
  #8  
Old August 2nd, 2002, 10:48 AM
binky's Avatar
binky binky is offline
Gerbil
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2001
Location: In a Rotastak
Posts: 1,763 binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level)binky User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 12 m 52 sec
Reputation Power: 18
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..

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherDev Shed Lounge > Take the weight off your feet and have a game o' cards!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway