programming language
' ************************************************************************* ' ' Script Name: SlotMachine.bas (The Slot Machine Game) ' Version: 1.0 ' Author: Jerry Lee Ford, Jr. ' Date: March 1, 2007 ' ' Description: This game is a simulation of a Las Vegas-styled slot ' machine. The objective of the game is for the player to ' win as much money as possible and not go broke. ' ' ************************************************************************* nomainwin 'Suppress the display of the default text window 'Assign default values to global variables global iteration, account, gamesPlayed iteration = 0 'Used to control the display of animation account = 20 'Represents the amount of money in the player's account gamesPlayed = 0 'Keeps track of the total number of games played call ManageGamePlay 'Call the subroutine responsible for managing game play wait 'Pause the application and wait for the player's instruction 'This subroutine displays the game board and controls interaction with the 'player sub ManageGamePlay WindowWidth = 500 'Set the width of the window to 500 pixels WindowHeight = 500 'Set the height of the window to 500 pixels loadbmp "Cherry", "C:\images\Cherry.bmp" 'Load the specified bitmap 'file into memory loadbmp "Apple", "C:\images\Apple.bmp" 'Load the specified bitmap 'file into memory loadbmp "Pear", "C:\images\Pear.bmp" 'Load the specified bitmap 'file into memory 'Define the format of statictext controls displayed on the window statictext #play.statictext1, "S L O T M A C H I N E", 77, 20, 440, 30 statictext #play.statictext2, "Copyright 2007", 345, 55, 80, 20 'Add the controls used to graphically display slot machine values graphicbox #play.pic1, 50, 100, 93, 93 graphicbox #play.pic2, 200, 100, 93, 93 graphicbox #play.pic3, 350, 100, 93, 93 'Add a control that will be used to announce the results of each play textbox #play.textbox1 130, 230, 240, 50 'Add a button control to operate the slot machine button #play.button1 "Spin", AnimateDisplay, UL, 200, 300, 100, 30 'Add a groupbox control at the bottom of the window groupbox #play.groupbox1 "Stats:", 60, 350, 380, 100 'Use statictext controls to display 2 labels inside the groupbox control statictext #play.statictext3, "No of Games Played:", 90, 372, 105, 20 statictext #play.statictext4, "Account:", 290, 372, 50, 20 'Add 2 textbox controls inside the groupbox control for displaying 'game statistics textbox #play.textbox2 90, 395, 100, 20 textbox #play.textbox3 290, 395, 100, 20 'Open the window with no frame and a handle of #play open "Slot Machine" for window_nf as #play 'Set up the trapclose event for the window print #play, "trapclose ClosePlay" 'Set the font type, size, and attributes print #play.statictext1, "!font Arial 24 bold" print #play.textbox1, "!font Arial 24 bold" 'Display the initial values representing the number of games played and 'the value of the player's account print #play.textbox3, str$(account) print #play.textbox2, str$(gamesPlayed) print #play.button1, "!setfocus"; 'Set focus to the button control 'Pause the application and wait for the player's instruction wait end sub 'This subroutine is responsible for controlling the timing involved in 'displaying the slot machine's animation sub AnimateDisplay handle$ timer 333, DisplayImages 'Call the DisplayImages subroutine every '.333 seconds end sub 'This subroutine displays a different set of bitmap image files in the 'game's 3 bmpcontrols each time it is called. sub DisplayImages iteration = iteration + 1 'Keep track of how many times this subroutine 'has been called 'Display a different set of bitmap images upon each call if iteration = 1 then call UpdateDisplay "Apple", "Cherry", "Pear" if iteration = 2 then call UpdateDisplay "Cherry", "Pear", "Cherry" if iteration = 3 then call UpdateDisplay "Pear", "Apple", "Pear" if iteration = 4 then call UpdateDisplay "Apple", "Pear", "Cherry" if iteration = 5 then call UpdateDisplay "Pear", "Cherry", "Apple" 'Turn the timer control off on the 6th iteration if iteration = 6 then timer 0 'Turn the timer off iteration = 0 'Reset this value to zero call RandomSelection 'Call the subroutine that generates the slot end if 'machine's 6th spin end sub 'This subroutine loads the specified bitmap files into the game's 3 'bmpbutton controls sub UpdateDisplay x$, y$, z$ print #play.pic1, "drawbmp " + x$ + " 1 1" 'Load first image print #play.pic2, "drawbmp " + y$ + " 1 1" 'Load second image print #play.pic3, "drawbmp " + z$ + " 1 1" 'Load third image 'Use the flush command to make sure the images stick print #play.pic1, "flush" print #play.pic2, "flush" print #play.pic3, "flush" 'Let's make a little noise at the end of each spin playwave "ding.wav", asynch end sub 'This subroutine is responsible for determining which bitmap images should 'be displayed for the slot machine's 6th and final spin sub RandomSelection RandomNumber = int(rnd(1)*3) + 1 'Retrieve a number between 1 and 3 'Select the image to be displayed on the first bmpbutton control SELECT CASE RandomNumber CASE 1 print #play.pic1, "drawbmp Cherry 1 1" 'Display the Cherry bitmap firstPic = 1 'Set a numeric value representing the selection CASE 2 print #play.pic1, "drawbmp Apple 1 1" 'Display the Apple bitmap firstPic = 2 'Set a numeric value representing the selection CASE 3 print #play.pic1, "drawbmp Pear 1 1" 'Display the Pear bitmap firstPic = 3 'Set a numeric value representing the selection END SELECT RandomNumber = int(rnd(1)*3) + 1 'Retrieve a number between 1 and 3 'Select the image to be displayed on the second bmpbutton control SELECT CASE RandomNumber CASE 1 print #play.pic2, "drawbmp Cherry 1 1" 'Display the Cherry bitmap secondPic = 1 'Set a numeric value representing the selection CASE 2 print #play.pic2, "drawbmp Apple 1 1" 'Display the Apple bitmap secondPic = 2 'Set a numeric value representing the selection CASE 3 print #play.pic2, "drawbmp Pear 1 1" 'Display the Pear bitmap secondPic = 3 'Set a numeric value representing the selection END SELECT RandomNumber = int(rnd(1)*3) + 1 'Retrieve a number between 1 and 3 'Select the image to be displayed on the third bmpbutton control SELECT CASE RandomNumber CASE 1 print #play.pic3, "drawbmp Cherry 1 1" 'Display the Cherry bitmap thirdPic = 1 'Set a numeric value representing the selection CASE 2 print #play.pic3, "drawbmp Apple 1 1" 'Display the Apple bitmap thirdPic = 2 'Set a numeric value representing the selection CASE 3 print #play.pic3, "drawbmp Pear 1 1" 'Display the Pear bitmap thirdPic = 3 'Set a numeric value representing the selection END SELECT 'Let's make a little noise and display the results of the game playwave "ding.wav", asynch 'Tabulate the value representing the results of the 6th spin result = firstPic + secondPic + thirdPic 'Look to see if 3 cherries or 3 pears were displayed if (result = 3) or (result = 9) then print #play.textbox1, "Jackpot!" account = account + 3 'Add 3 dollars to the player's account end if 'A value of 6 means either 3 apples were displayed or 3 separate 'values were displayed if result = 6 then if firstPic = secondPic then 'Look for three apples print #play.textbox1, "Jackpot!" account = account + 3 'Add 3 dollars to the player's account else 'A cherry, apple, and pear were displayed print #play.textbox1, "You lose!" account = account - 5 'Subtract 5 dollars from the player's account end if end if 'A value other than 3, 6, or 9 means that 2 of a kind was displayed if (result <> 3) and (result <> 6) and (result <> 9) then print #play.textbox1, "Two of a kind!" account = account + 1 'Add 1 dollar to the player's account end if if account < 0 then 'End the game if the player goes broke notice "You have gone broke. Game Over!" 'Tell the player first close #play 'Close the window end 'Terminate the game end if 'Keep track of the total number of games played gamesPlayed = gamesPlayed + 1 'Update the display of game statistics print #play.textbox2, str$(gamesPlayed) print #play.textbox3, str$(account) end sub 'This subroutine is called when the player closes the #play window 'and is responsible for ending the game sub ClosePlay handle$ 'Get confirmation before terminating program execution confirm "Are you sure you want quit?"; answer$ if answer$ = "yes" then 'The player clicked on Yes close #play 'Close the #play window end 'Terminate the game end if end sub