Acey Ducey - An exciting Card Game

Started by geecee, March 31, 2009, 02:28:51 AM

Previous topic - Next topic

geecee

Hi there!

Are you a betting person?

Here then is Acey Ducey, an exciting card game, in which you are dealt two cards and are invited to place or not to place a bet depending on whether or not you think the next card dealt will fall between your two cards.

You nominate your starting bank [minimum of 100 dollars] and it fluctuates according to the result of your bet.

Should you decide not to bet and a win is possible, you will lose 10 dollars.

The game lasts a maximum of 17 hands x 3 cards or
until you lose all your money or
until you terminate the game.

The attached .zip file contains the necessary media required to run the programme ...... Download it to the same folder/location as this programme should you decide to try it out.

It's possible the programme can be improved ...... I don't know.

I have picked up ideas and bits and pieces from various postings in the forums and, if you read through the programme, you'll probably recognise something that you contributed to the forums.

The reason for posting the code separately and attaching a media .zip file is a personal preference ...... I like to view the code this way as I find it easier to follow.

PlayBASIC Code: [Select]
remstart
================================================================

ACEY DUCEY CARD GAME
*************************************************************
Author: geecee
Originally written for Dark Basic - June 2007
Rewritten for Play Basic - March 2009
*************************************************************

================================================================
remend


` Call procedures to set everything up and display Intro Screen
gosub setup
gosub intro

` Main programme loop
do
gosub play
gosub playagain
loop

` End programme
end

` ****************************************************************
` Set up
` ****************************************************************

setup:

` Tell PB to include the input support library
#include "Input"

`Set up array/s
Dim CardTable$(13)
Dim SuitTable$(4)
Dim ValueTable$(15)
Dim randomseries(52)
Dim card(52)
Dim intro$(22)
Dim value(52)
Dim a(52)
Dim card$(52)
Count=SplitToArray("Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King,Ace",",",CardTable$(),0)
Count=SplitToArray("Hearts,Clubs,Diamonds,Spades",",",SuitTable$(),0)
Count=SplitToArray("02,03,04,05,06,07,08,09,10,11,12,13,14",",",valuetable$(),0)

` Pre-Load Required Fonts
global Arial20 =loadNewfont("arial bold",20,0)
global Arial30 =loadNewfont("arial bold",30,0)

` Pre-load media
global BackdropImage = loadnewImage("Backdrop.bmp")
global Card1Image =LoadNewImage("1H.bmp")
global Card2Image =LoadNewImage("2H.bmp")
global card3Image =LoadNewImage("3H.bmp")
global Card4Image =LoadNewImage("4H.bmp")
global Card5Image =LoadNewImage("5H.bmp")
global Card6Image =LoadNewImage("6H.bmp")
global Card7Image =LoadNewImage("7H.bmp")
global Card8Image =LoadNewImage("8H.bmp")
global Card9Image =LoadNewImage("9H.bmp")
global Card10Image =LoadNewImage("10H.bmp")
global Card11Image =LoadNewImage("JH.bmp")
global Card12Image =LoadNewImage("QH.bmp")
global Card13Image =LoadNewImage("KH.bmp")
global Card14Image =LoadNewImage("1C.bmp")
global Card15Image =LoadNewImage("2C.bmp")
global Card16Image =LoadNewImage("3C.bmp")
global Card17Image =LoadNewImage("4C.bmp")
global Card18Image =LoadNewImage("5C.bmp")
global Card19Image =LoadNewImage("6C.bmp")
global Card20Image =LoadNewImage("7C.bmp")
global Card21Image =LoadNewImage("8C.bmp")
global Card22Image =LoadNewImage("9C.bmp")
global Card23Image =LoadNewImage("10C.bmp")
global Card24Image =LoadNewImage("JC.bmp")
global Card25Image =LoadNewImage("QC.bmp")
global Card26Image =LoadNewImage("KC.bmp")
global Card27Image =LoadNewImage("1D.bmp")
global Card28Image =LoadNewImage("2D.bmp")
global Card29Image =LoadNewImage("3D.bmp")
global Card30Image =LoadNewImage("4D.bmp")
global Card31Image =LoadNewImage("5D.bmp")
global Card32Image =LoadNewImage("6D.bmp")
global Card33Image =LoadNewImage("7D.bmp")
global Card34Image =LoadNewImage("8D.bmp")
global Card35Image =LoadNewImage("9D.bmp")
global Card36Image =LoadNewImage("10D.bmp")
global Card37Image =LoadNewImage("JD.bmp")
global Card38Image =LoadNewImage("QD.bmp")
global Card39Image =LoadNewImage("KD.bmp")
global Card40Image =LoadNewImage("1S.bmp")
global Card41Image =LoadNewImage("2S.bmp")
global Card42Image =LoadNewImage("3S.bmp")
global Card43Image =LoadNewImage("4S.bmp")
global Card44Image =LoadNewImage("5S.bmp")
global Card45Image =LoadNewImage("6S.bmp")
global Card46Image =LoadNewImage("7S.bmp")
global Card47Image =LoadNewImage("8S.bmp")
global Card48Image =LoadNewImage("9S.bmp")
global Card49Image =LoadNewImage("10S.bmp")
global Card50Image =LoadNewImage("JS.bmp")
global Card51Image =LoadNewImage("QS.bmp")
global Card52Image =LoadNewImage("KS.bmp")

` This command will hide mouse pointer
mouse off

` Determine centre of screen width
screencentre=getscreenwidth()/2

` Display image/s
drawimage backdropimage,0,0,false

` Set ink colour
ink rgb(255,217,128)

return

` ****************************************************************
` Introduction
` ****************************************************************

intro:

` Set text style and size
setfont arial30

` Write text to screen
centertext screencentre,60,"ACEY DUCEY CARD GAME"

` Refresh the display so the user can see it
sync

` A short wait before proceeding
wait 1000

` Set down coordinate
down=100

` Set text style, size and height
setfont arial20
height= gettextheight("X")

` Define the introduction strings.
intro$(1)="Acey Ducey is played in the following manner."
Login required to view complete source code


:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin

#1
 Way too many globals, there's absolutely no need for them.   Use an array to store sets of information.. IE

PlayBASIC Code: [Select]
      // The path (folder) where the media is  
Path$ ="some folder on the your computer"

Dim CardImages(52)

LoadMedia(Path$)
cls 0

For lp=1 to 52
ThisImage=CardImages(lp)
Width=GetImageWidth(ThisImage)

Xpos2=Xpos+Width+5

if (Xpos2)=>GetScreenWidth()
Xpos=0
Xpos2=0
Ypos=Ypos+GetImageHeight(ThisImage)+5
endif
DrawImage ThisIMage,Xpos,Ypos,False
Xpos=Xpos2
next

Sync
waitkey





//
Function LoadMedia(Path$)

// this string holds the suits letters,
Suits$="HCDS"

// card names in this string
names$=" 1 2 3 4 5 6 7 8 910 J Q K"

// index of the first card will be 1
CardIndex=1

// loop through the suits
For Suit=0 to Len(Suits$)-1
Suit$=mid$(Suits$,1+Suit,1)

// Loop throuigh the 13 cards
For Card=0 to 12
// Grab the Card Name from the names$ string
File$=Mid$(names$,1+(Card*2),2)
// Cut off any spaces that might be preceeding the name
File$=trim$(File$," ")

// Add the card name + suit namne and file type to construct the file name
File$=file$+Suit$+".bmp"

// Load it and store it's handle in our card images array
CardImages(CardIndex)=LoadnewIMage(path$+File$)

// Bump the Card index to the next slot in the array
inc CardIndex

next


next
EndFunction







geecee

#2
Thanks for your reply kevin.

Once again very helpful information.

I have rewritten the programme incorporating your suggestion and have reposted here.

For anyone who wishes to try it out please note ONE MAJOR CHANGE ...... Where it says

Path$ ="some folder on the your computer"

you will have to enter the path (folder) where you have stored the media in order for the programme to work.

PlayBASIC Code: [Select]
remstart
================================================================

ACEY DUCEY CARD GAME
*************************************************************
Author: geecee
Originally written for Dark Basic - June 2007
Rewritten for Play Basic - March 2009
*************************************************************

================================================================
remend


` Call procedures to set everything up and display Intro Screen
gosub setup
gosub intro

` Main programme loop
do
gosub play
gosub playagain
loop

` End programme
end

` ****************************************************************
` Set up
` ****************************************************************

setup:

` Tell PB to include the input support library
#include "Input"

`Set up array/s
Dim CardTable$(13)
Dim SuitTable$(4)
Dim ValueTable$(15)
Dim randomseries(52)
Dim card(52)
Dim intro$(22)
Dim value(52)
Dim a(52)
Dim card$(52)
Dim CardImages(52)
Count=SplitToArray("Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King,Ace",",",CardTable$(),0)
Count=SplitToArray("Hearts,Clubs,Diamonds,Spades",",",SuitTable$(),0)
Count=SplitToArray("02,03,04,05,06,07,08,09,10,11,12,13,14",",",valuetable$(),0)

` Pre-Load Required Fonts
global Arial20 =loadNewfont("arial bold",20,0)
global Arial30 =loadNewfont("arial bold",30,0)

` Pre-load media
global BackdropImage = loadnewImage("Backdrop.bmp")

` The path (folder) where the remaining media is
Path$ ="some folder on the your computer"

` Call function to pre-load remaining media
LoadMedia(Path$)

` This command will hide mouse pointer
mouse off

` Determine centre of screen width
screencentre=getscreenwidth()/2

` Display image/s
drawimage backdropimage,0,0,false

` Set ink colour
ink rgb(255,217,128)

return

` ****************************************************************
` Introduction
` ****************************************************************

intro:

` Set text style and size
setfont arial30

` Write text to screen
centertext screencentre,60,"ACEY DUCEY CARD GAME"

` Refresh the display so the user can see it
sync

` A short wait before proceeding
wait 1000

` Set down coordinate
down=100

` Set text style, size and height
setfont arial20
height= gettextheight("X")

` Define the introduction strings.
intro$(1)="Acey Ducey is played in the following manner."
intro$(3)="Cards are valued 2 - Ace(14)."
intro$(5)="You are dealt two cards face up. You have an option to bet"
intro$(6)="or not to bet depending on whether or not you feel the next"
intro$(7)="card dealt will have a value between the first two."
intro$(9)="If your option is not to bet, input a 0. Note, however, should"
intro$(10)="you opt not to bet, and a win is possible, you will lose 10"
intro$(11)="dollars."
intro$(13)="Your initial bank is set to the amount you nominate - minimum"
intro$(14)="100 dollars."
intro$(16)="The game lasts:"
intro$(17)="A maximum of 17 hands x 3 cards or"
intro$(18)="Until you lose all your money or"
intro$(19)="Until you terminate the game"
intro$(22)="Press any key to begin."

` Determine text width of longest introduction string
tw=gettextwidth("Your initial bank is set to the amount you nominate - minimum")

` Write introduction strings to screen
for n=1 to 22

` Set across and down coordinates
across=screencentre-tw/2
down=down+height*1

text across,down,intro$(n)
next n

` Refresh the display so the user can see it
sync

` Wait for keypress
waitnokey
waitkey

` Draw a box to hide previous text at location and set ink colour
boxc 2,91,798,599,1,rgb(255,0,0)

return

` ****************************************************************
` Play
` ****************************************************************

play:
Login required to view complete source code



:)
Enjoy
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)