Where to begin
1. Declare your variables , prevents misspellings e.g. Foreground as opposed to Forground
2. Reusable code should always be put in functions.
3. Never have loose code after your Main loop bad coding practice.
Here is a quick example
I quickly broke down your code into function calls, to make it easier to follow the flow of the code.
Code should be readable and reusable. You should have no duplicate code. Duplicate code should be put in a function.
EDIT:Excuse large indents Pasting code in code snippet block seems to increase the indenting.
Rem Project: Slot Machine
Rem Created: Thursday, June 21, 2012
Rem Executable File: SlotMachine.dba
Rem Version: 1.0
Rem Author: Eric Phillips
Rem Description: This game simulates a Las Vegas Slot Machine
Rem ***** Main Source File *****
Rem Assign 10 dollars to the players account
global AccountBalance as integer : AccountBalance = 40
global ForegroundColor as dword
global BackgroundColor as dword
global DialOne as integer
global DialTwo as integer
global DialThree as integer
global DialFour as integer
global DialFive as integer
global FiveKind as integer
global FourKind as integer
global ThreeKind as integer
WelcomeScreen()
InstructionsScreen()
DO
ForegroundColor = RGB(0, 0, 160) `Set the foreground to Blue
BackgroundColor = RGB(255, 255, 255) `Set the background to White
INK ForegroundColor, BackgroundColor `Apply the color settings
FOR i = 1 TO 19 `Iterate 19 times
CLS RGB(255, 255, 255) `Set the background color to White
SET TEXT SIZE 36 `Set the text size
CENTER TEXT 320, 60, "Eric's Slot Machine Game"
CENTER TEXT 320, 90, "__________________________________"
SET TEXT SIZE 72 `Set the text size
Rem Display random numbers to simulate slot machine dials
CENTER TEXT 320, 150, STR$(RND(4) + 1) + " " + STR$(RND(4) + 1) + " " + STR$(RND(4) + 1) + " " + STR$(RND(4) + 1) + " " + STR$(RND(4) + 1)
SET TEXT SIZE 36 `Set the text size
CENTER TEXT 320, 210, "__________________________________"
SLEEP 200 `Pause game for a 5th of a second
NEXT i
SET TEXT SIZE 72 `Set the text size
CLS RGB(255, 255,255) `Set the background color to white
Rem Generate the final set of number representing the values
DialOne = RND(4) + 1
DialTwo = RND(4) + 1
DialThree = RND(4) + 1
DialFour = RND(4) + 1
DialFive = RND(4) + 1
FiveKind = 0
FourKind = 0
ThreeKind = 0
SET TEXT SIZE 36 `Set the text size
CENTER TEXT 320, 60, "Eric's Slot Machine Game"
CENTER TEXT 320, 90, "__________________________________"
SET TEXT SIZE 72 `Set the text size
Rem Display random numbers to simulate slot machine dials
CENTER TEXT 320, 150, STR$(DialOne) + " " + STR$(DialTwo) + " " + STR$(DialThree) + " " + STR$(DialFour) + " " + STR$(DialFive)
SET TEXT SIZE 36 `Set the text size
CENTER TEXT 320, 210, "__________________________________"
Rem Add up the final result from the dials
Rem Result = DialOne + DialTwo + DialThree + DialFour + DialFive * Pointless Variable
SET TEXT SIZE 36 `Set the text size
GameLogic()
UpdatePlayersAccount()
Rem End gameplay if the player has gone broke
IF AccountBalance <= 0
GameOverScreen()
ClosingScreen()
ENDIF
WAIT KEY `Wait until the player presses a key
LOOP
function ClosingScreen()
CLS RGB(255, 255, 255) `Set the background color to White
ForegroundColor = RGB(0, 0, 160) `Set the foreground to Blue
INK ForegroundColor, BackgroundColor `Apply the color settings
SET TEXT SIZE 24 `Set the text size
Rem Display the game's closing message
CENTER TEXT 320, 150, "Thanks for playing Eric's Slot Machine Game!"
SET TEXT SIZE 16 `Set the text size
CENTER TEXT 320, 240, "Developed by Eric Phillips"
CENTER TEXT 320, 260, "Copyright 2012"
CENTER TEXT 320, 280, "http://www.bigdoggamestudios.com"
SET TEXT SIZE 18 `Set the text size
CENTER TEXT 320, 380, "Press any key to continue"
WAIT KEY `Wait for a key to be pressed
END `End the game
endfunction
function WelcomeScreen()
CLS RGB(255, 255, 255) `Set the background to White
SET TEXT FONT "Arial" `Set the font
SET TEXT SIZE 48 `Set the font size
ForegroundColor = RGB(0, 0, 160) `Set the foreground color to Blue
BackgroundColor = RGB(255, 255, 255) `Set the background color to White
INK ForegroundColor, BackgroundColor `Apply the color settings
CENTER TEXT 320, 150, "Welcome to" `Display the welcome message
CENTER TEXT 320, 220, "Eric's Slot Machine Game"
SET TEXT SIZE 18 `Set the text size
CENTER TEXT 320, 380, "Press any key to continue" `Display instructions
WAIT KEY `Wait for the player to press a key
endfunction
function InstructionsScreen()
CLS RGB(255, 255, 255) `Set the background to White
SET TEXT SIZE 24 `Set the text size
TEXT 100, 120, "Instructions:" `Begin the instructions
TEXT 100, 160, "Press any key to place a bet."
TEXT 100, 190, "5 of a kind adds 4 dollars to your account"
TEXT 100, 220, "4 of a kind adds 3 dollars to your account"
TEXT 100, 250, "3 of a kind adds 2 dollars to your account"
TEXT 100, 280, "Note: 4 and 3 of a kind wins must be in a row"
TEXT 100, 310, "No matches subtracts 3 dollars from your account"
SET TEXT SIZE 18 `Set the text size
CENTER TEXT 320, 380, "Press any key to continue" `Give Instructions
WAIT KEY `Wait for the player to press a key
endfunction
function GameLogic()
ThreeOfAKind()
FourOfAKind()
FiveOFAKind()
endfunction
function UpdatePlayersAccount()
SET TEXT SIZE 24 `Set the text size
Rem Display the Player's account balance
TEXT 75, 30, "Account Balance: " + STR$(AccountBalance) `Display the account balance
SET TEXT SIZE 18 `Set the text size
Rem Display instructions for continuing
CENTER TEXT 320, 420, "Press escape to quit or any other key to continue."
endfunction
function GameOverScreen()
SET TEXT SIZE 24 `Set the text size
ForegroundColor = RGB(255, 0, 0) `Set foreground to Blue
BackgroundColor = RGB(255, 255, 255) `Set background to White
INK ForegroundColor, BackgroundColor `Apply the color settings
Rem Notify the Player that the game is over
CENTER TEXT 320, 310, "G A M E O V E R"
CENTER TEXT 320, 350, "You have gone broke!"
WAIT KEY `Wait for the player to press a key
endfunction
function FourOfAKind()
Rem ************************************ Four of a Kind *******************************************
Rem Look for a jackpot made of four 1s
IF DialOne = 1 AND DialTwo = 1 AND DialThree = 1 AND DialFour = 1 AND FiveKind = 0 OR DialTwo = 1 AND DialThree = 1 AND DialFour = 1 AND DialFive = 1 AND FiveKind = 0
CENTER TEXT 320, 260, "Four of a kind - Winner!"
Rem Add 3 dollars to the player's account
AccountBalance = AccountBalance + 3
FourKind = 1
ENDIF
Rem Look for a jackpot made of four 2s
IF DialOne = 2 AND DialTwo = 2 AND DialThree = 2 AND DialFour = 2 AND FiveKind = 0 OR DialTwo = 2 AND DialThree = 2 AND DialFour = 2 AND DialFive = 2 AND FiveKind = 0
CENTER TEXT 320, 260, "Four of a kind - Winner!"
Rem Add 3 dollars to the player's account
AccountBalance = AccountBalance + 3
FourKind = 1
ENDIF
Rem Look for a jackpot made of four 3s
IF DialOne = 3 AND DialTwo = 3 AND DialThree = 3 AND DialFour = 3 AND FiveKind = 0 OR DialTwo = 3 AND DialThree = 3 AND DialFour = 3 AND DialFive = 3 AND FiveKind = 0
CENTER TEXT 320, 260, "Four of a kind - Winner!"
Rem Add 3 dollars to the player's account
AccountBalance = AccountBalance + 3
FourKind = 1
ENDIF
Rem Look for a jackpot made of four 4s
IF DialOne = 4 AND DialTwo = 4 AND DialThree = 4 AND DialFour = 4 AND FiveKind = 0 OR DialTwo = 4 AND DialThree = 4 AND DialFour = 4 AND DialFive = 4 AND FiveKind = 0
CENTER TEXT 320, 260, "Four of a kind - Winner!"
Rem Add 3 dollars to the player's account
AccountBalance = AccountBalance + 3
FourKind = 1
ENDIF
Rem Look for a jackpot made of four 5s
IF DialOne = 5 AND DialTwo = 5 AND DialThree = 5 AND DialFour = 5 AND FiveKind = 0 OR DialTwo = 5 AND DialThree = 5 AND DialFour = 5 AND DialFive = 5 AND FiveKind = 0
CENTER TEXT 320, 260, "Four of a kind - Winner!"
Rem Add 3 dollars to the player's account
AccountBalance = AccountBalance + 3
FourKind = 1
ENDIF
endfunction
function ThreeOfAKind()
Rem ************************************* Three of a Kind ********************************************
Rem Look for a jackpot made of Three 1s
IF DialOne = 1 AND DialTwo = 1 AND DialThree = 1 AND FourKind = 0 AND FiveKind = 0 OR DialTwo = 1 AND DialThree = 1 AND DialFour = 1 AND FourKind = 0 AND FiveKind = 0 OR DialThree = 1 AND DialFour = 1 AND DialFive = 1 AND FourKind = 0 AND FiveKind = 0
CENTER TEXT 320, 260, "Three of a kind - Winner!"
Rem Add 2 dollars to the player's account
AccountBalance = AccountBalance + 2
ThreeKind = 1
ENDIF
Rem Look for a jackpot made of Three 2s
IF DialOne = 2 AND DialTwo = 2 AND DialThree = 2 AND FourKind = 0 AND FiveKind = 0 OR DialTwo = 2 AND DialThree = 2 AND DialFour = 2 AND FourKind = 0 AND FiveKind = 0 OR DialThree = 2 AND DialFour = 2 AND DialFive = 2 AND FourKind = 0 AND FiveKind = 0
CENTER TEXT 320, 260, "Three of a kind - Winner!"
Rem Add 2 dollars to the player's account
AccountBalance = AccountBalance + 2
ThreeKind = 1
ENDIF
Rem Look for a jackpot made of Three 3s
IF DialOne = 3 AND DialTwo = 3 AND DialThree = 3 AND FourKind = 0 AND FiveKind = 0 OR DialTwo = 3 AND DialThree = 3 AND DialFour = 3 AND FourKind = 0 AND FiveKind = 0 OR DialThree = 3 AND DialFour = 3 AND DialFive = 3 AND FourKind = 0 AND FiveKind = 0
CENTER TEXT 320, 260, "Three of a kind - Winner!"
Rem Add 2 dollars to the player's account
AccountBalance = AccountBalance + 2
ThreeKind = 1
ENDIF
Rem Look for a jackpot made of Three 4s
IF DialOne = 4 AND DialTwo = 4 AND DialThree = 4 AND FourKind = 0 AND FiveKind = 0 OR DialTwo = 4 AND DialThree = 4 AND DialFour = 4 AND FourKind = 0 AND FiveKind = 0 OR DialThree = 4 AND DialFour = 4 AND DialFive = 4 AND FourKind = 0 AND FiveKind = 0
CENTER TEXT 320, 260, "Three of a kind - Winner!"
Rem Add 2 dollars to the player's account
AccountBalance = AccountBalance + 2
ThreeKind = 1
ENDIF
Rem Look for a jackpot made of Three 5s
IF DialOne = 5 AND DialTwo = 5 AND DialThree = 5 AND FourKind = 0 AND FiveKind = 0 OR DialTwo = 5 AND DialThree = 5 AND DialFour = 5 AND FourKind = 0 AND FiveKind = 0 OR DialThree = 5 AND DialFour = 5 AND DialFive = 5 AND FourKind = 0 AND FiveKind = 0
CENTER TEXT 320, 260, "Three of a kind - Winner!"
Rem Add 2 dollars to the player's account
AccountBalance = AccountBalance + 2
ThreeKind = 1
ENDIF
IF (FiveKind = 0) AND (FourKind = 0) AND (ThreeKind = 0)
CENTER TEXT 320, 260, "No matches - You Lose!"
Rem subtract 3 dollars from the player's account
AccountBalance = AccountBalance - 4
ENDIF
endfunction
function FiveOFAKind()
Rem **************************** Five of a Kind ***********************************
Rem Look for a jackpot made of five 1s
IF DialOne = 1 AND DialTwo = 1 AND DialThree = 1 AND DialFour = 1 AND DialFive = 1
CENTER TEXT 320, 260, "Five of a kind - Jackpot!"
Rem Add 4 dollars to the player's account
AccountBalance = AccountBalance + 4
FiveKind = 1
ENDIF
Rem Look for a jackpot made of five 2s
IF DialOne = 2 AND DialTwo = 2 AND DialThree = 2 AND DialFour = 2 AND DialFive = 2
CENTER TEXT 320, 260, "Five of a kind - Jackpot!"
Rem Add 4 dollars to the player's account
AccountBalance = AccountBalance + 4
FiveKind = 1
ENDIF
Rem Look for a jackpot made of five 3s
IF DialOne = 3 AND DialTwo = 3 AND DialThree = 3 AND DialFour = 3 AND DialFive = 3
CENTER TEXT 320, 260, "Five of a kind - Jackpot!"
Rem Add 4 dollars to the player's account
AccountBalance = AccountBalance + 4
FiveKind = 1
ENDIF
Rem Look for a jackpot made of five 4s
IF DialOne = 4 AND DialTwo = 4 AND DialThree = 4 AND DialFour = 4 AND DialFive = 4
CENTER TEXT 320, 260, "Five of a kind - Jackpot!"
Rem Add 4 dollars to the player's account
AccountBalance = AccountBalance + 4
FiveKind = 1
ENDIF
Rem Look for a jackpot made of five 5s
IF DialOne = 5 AND DialTwo = 5 AND DialThree = 5 AND DialFour = 5 AND DialFive = 5
CENTER TEXT 320, 260, "Five of a kind - Jackpot!"
Rem Add 4 dollars to the player's account
AccountBalance = AccountBalance + 4
FiveKind = 1
ENDIF
endfunction
[img]
[/img]
WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.