rendered paste bodyExtrn GetDec:Far, PutDec:Far, PutDec:Far, PutStrng:Far, NewLine:Far ; #include "iostream.h"
Data Segment
;######Game variables#################
Day dw 1
GlassesSold dw ?
PriceperGlass dw ?
Income dw ?
Expenses dw ?
GlassesMade dw ?
AdvertisingMade dw ?
AdvertisingCost dw 15
Profit dw ?
Assets dw ?
CurrentAssets dw 200 ;starting amount
DaystoPlay dw ?
WeatherCond dw ?
CostPerGlass dw ?
;######inputforday function prompts######
OnDay db "On day: " ; length 8
LemonadeCost0 db "The cost to make lemonade is " ; length 29
LemonadeCost1 db " per glass." ; 11
;######Random number function vars#######
RAND_seed dw ?
;######prompts###########################
Intro db "Welcome to Lemonade Stand" ; basic intro prompt 25
Instructions01 db ' Welcome to the wonderful world of Entrepreneurship! ' ; 80
Seperator1 db '* $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ * $ '
Instructions02 db 'You have chosen to run a lemonade stand from 1-30 days in an attempt to make a '
Instructions03 db 'little money. You must take into account your assests, advertising budget and '
Instructions04 db 'the current weather conditions in an attempt to make your stand profitable. '
Instructions05 db ' Good luck in your quest! '
DailyStatement db 'Lemonade stand Daily Statement:' ; daily statement 31
Date db 'On day: ' ; day output 8
Seperator db '******************************' ; seperator 30
Sales db 'Glasses sold: ' ; glasses sold 14
Priceprompt db 'Price per glass: ' ; price per glass 17
Production db 'Glasses made: ' ; glasses made 14
Advertsprompt db 'Signs made: ' ; signs made 12
Profitprompt db 'Profit: ' ; profit prompt 8
AssetsPrompt db 'Assets: ' ; asset prompt 8
GlassesPrompt db 'How many glasses of lemonade do you wish to make? ' ; length 50
AdvertisingPrompt0 db 'How many advertising signs do you wish to make at ' ; 50
AdvertisingPrompt1 db ' cents each? ' ; 13
LemonadePricePrompt db 'What price (in cents) do you wish to charge for lemonade? ' ; 56
DaysPrompt db 'Please enter the number of days to run the stand (1-30): ' ; 57
NumberOutOfRange db 'Number out of range, try again' ; 30
CannotAfford db 'You cannot afford this many ' ; 28
OutOfMoney db 'Game Over - you are out of money' ; 32
;########Weather report##################
Weather0 db "Today's weather is: Hot and Humid " ; 35
Weather1 db "Today's weather is: Sunny " ;
Weather2 db "Today's weather is: Fair " ;
Weather3 db "Today's weather is: Cloudy and Cool" ;
Weather4 db "Today's weather is: Raining " ;
;#######Glasses Sold#####################
MaxPrice dw ? ;max price of lemondade for a given day
MaxGlassesSold dw ? ;max number of glasses sold in one day
GlassMul dw ?
;#######Game Graphics####################
logo01 db ' 888 888 ' ; 80
logo02 db ' 888 888 '
logo03 db ' 888 888 '
logo04 db ' 888 .d88b. 88888b.d88b. .d88b. 88888b. 8888b. .d88888 .d88b. '
logo05 db ' 888 d8P Y8b 888 "888 "88b d88""88b 888 "88b "88b d88" 888 d8P Y8b '
logo06 db ' 888 88888888 888 888 888 888 888 888 888 .d888888 888 888 88888888 '
logo07 db ' 888 Y8b. 888 888 888 Y88..88P 888 888 888 888 Y88b 888 Y8b. '
logo08 db ' 88888888 "Y8888 888 888 888 "Y88P" 888 888 "Y888888 "Y88888 "Y8888 '
logo09 db ' '
logo10 db ' '
logo11 db ' '
logo12 db ' .d8888b. 888 888 '
logo13 db ' d88P Y88b 888 888 '
logo14 db ' Y88b. 888 888 '
logo15 db ' "Y888b. 888888 8888b. 88888b. .d88888 '
logo16 db ' "Y88b. 888 "88b 888 "88b d88" 888 '
logo17 db ' "888 888 .d888888 888 888 888 888 '
logo18 db ' Y88b d88P Y88b. 888 888 888 888 Y88b 888 '
logo19 db ' "Y8888P" "Y888 "Y888888 888 888 "Y88888 '
logo20 db ' Press Enter to Continue... '
;####Game Over###########################
GameOver01 db " _____ ____ _ " ; 80
GameOver02 db " / ____| / __ \ | | "
GameOver03 db " | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __| | "
GameOver04 db " | | |_ |/ _` | '_ ` _ \ / _ \ | | | \ \ / / _ \ '__| | "
GameOver05 db " | |__| | (_| | | | | | | __/ | |__| |\ V / __/ | |_| "
GameOver06 db " \_____|\__,_|_| |_| |_|\___| \____/ \_/ \___|_| (_) "
GameOver07 db " Game Over! - Thank you for playing! "
Data Ends
Code Segment
Assume Cs:Code, Ds:Data, Ss:Sseg
;#####Convert to Dollar##################
;takes 1 value converts it front cents
;to dollars
;Returns Whole # in Ax
;Cents # in DX
@CentsToDollars Proc Near C, @CASH:WORD
push bx
xor dx,dx
mov ax, @Cash
cwd
mov bx, 100
iDiv bx
pop bx
@ctdif:
cmp dx, 0
jl @ctdthen
jmp @ctdendif
@ctdthen:
neg dx
jmp @ctdendif
@ctdendif:
ret
@CentsToDollars Endp
;#####random number generator############
;gets a large number, a seed, and an upper limit
;seed is wiped out initially
;system time is used for seed
;answer is returned in Ax
@RANDOMNUMBER Proc Near C, @high:word
push bx
push cx
push dx
xor ax, ax ;clear AX
mov ah, 2Ch ;load 2Ch into ah
int 21h ;load system time into registers
mov RAND_seed, dx ;dh holds seconds, dl holds ms, move to seed
mov bx, @high
add bx, 1
mov ax, RAND_seed
xor dx,dx
cwd
div bx
mov ax, dx
pop dx
pop cx
pop bx
ret
@RANDOMNUMBER ENDp
;####SetCostPerGlass####################
@SetCostPerGlass Proc Near C
invoke @RandomNumber,5
add ax,2
mov CostPerGlass,Ax
ret
@SetCostPerGlass ENDp
;####SetAdvertisingCost##################
@SetAdvertisingCost Proc Near C
invoke @RandomNumber,10
add ax,5
mov AdvertisingCost,Ax
ret
@SetAdvertisingCost ENDp
@PostDailyInfo Proc Near C
Mov Cx, 8
Lea Di, OnDay
Call PutStrng
mov Ax, Day
call PutDec
mov cx, 30
call NewLine
lea di, Seperator
call PutStrng
call NewLine
call NewLine
ret
@PostDailyInfo ENDp
;####ClearScreen#########################
;clears the screen with a loop
;puts @line # of new lines on the screen
@cLEARSCREEN Proc Near C, @Lines:word
push Bx
mov Bx, @Lines
@CSfor: cmp bx, 0
ja @CSdo
jmp @CSendfor
@CSdo:
call NewLine
dec Bx
jmp @CSfor
@CSendfor:
pop Bx
ret
@CLEARSCREEN ENDp
;######outputs cents formated nicely#####
;outputs -3453 or 300 as $34.53 or $3.00
;input is money in cents
@OutputDollars Proc Near C, @Money:word
push ax
push bx
push cx
push dx
invoke @CentsToDollars, @Money ;break money apart into
;dollars and cents
push ax
push dx
xor ax, ax
xor dx, dx
mov ah, 02h
mov dl, 36
int 21h
pop dx
pop ax
@optif2:
cmp @Money, 0
jl @optand2
jmp @optendif2
@optand2:
cmp @Money, -100
jg @optthen2
jmp @optendif2
@optthen2:
push ax
push dx
xor ax, ax
xor dx, dx
mov ah, 02h
mov dl, 45
int 21h
pop dx
pop ax
jmp @optendif2
@optendif2:
call PutDec
push ax
push dx
xor ax, ax
xor dx, dx
mov ah, 02h
mov dl, 46
int 21h
pop dx
pop ax
mov ax, dx
@optif:
cmp ax, 10
Jb @optthen
jmp @optendif
@optthen:
push ax
mov ax, 0
call PutDec
pop ax
jmp @optendif
@optendif:
call PutDec
pop dx
pop cx
pop bx
pop ax
ret
@outputdollars ENDp
;#########INPUT FOR DAY##################
;gets input for the day
;provides error handling for
;entering data also
;########################################
@InputForDay Proc Near C
push ax
push bx
push cx
push dx
mov cx, 29
lea di, LemonadeCost0
call PutStrng
invoke @OutputDollars, CostPerGlass
mov cx, 11
lea di, LemonadeCost1
call PutStrng
call NewLine
call NewLine
mov cx, 7
lea di, AssetsPrompt
call PutStrng
invoke @OutputDollars, CurrentAssets
call NewLine
@if1:
call NewLine
Mov cx, 50
Lea di, GlassesPrompt
Call PutStrng
call GetDec
mov GlassesMade, Ax
call NewLine
mul CostPerGlass
mov Expenses, ax
cmp ax, Currentassets
jg @then1
jmp @endif1
@then1:
mov cx, 28
lea di, CannotAfford
call PutStrng
invoke @OutputDollars, ax
jmp @if1
@endif1:
@if2:
call NewLine
mov cx, 50
lea di, AdvertisingPrompt0
call PutStrng
mov ax,AdvertisingCost
call PutDec
mov cx, 13
lea di,AdvertisingPrompt1
call PutStrng
call GetDec
mov AdvertisingMade, ax
call NewLine
mul AdvertisingCost
add ax, Expenses
cmp ax, CurrentAssets
jg @then2
jmp @endif2
@then2:
mov cx, 28
lea di, CannotAfford
call PutStrng
invoke @OutputDollars, ax
jmp @if2
@endif2:
mov Cx, 58
lea Di, LemonadePricePrompt
call PutStrng
call GetDec
mov PricePerGlass, ax
call NewLine
pop dx
pop cx
pop bx
pop ax
ret
@InputForDay endp
;#######Asset Statement##################
@AssetStatement Proc Near C
push cx
push ax
mov ax,PricePerGlass
mul GlassesSold
mov Income,ax
mov ax,AdvertisingCost
mul AdvertisingMade
mov Expenses,ax
mov ax,CostPerGlass
mul GlassesMade
add Expenses,ax
mov ax,Income
sub ax,Expenses
mov Profit,ax
add ax,CurrentAssets
mov Assets,ax
mov Currentassets, Ax
invoke @clearscreen,25
mov cx,31
lea di,dailystatement
call PutStrng
mov cx,30
call NewLine
lea di,seperator
call PutStrng
invoke @clearscreen,2
mov cx,8
lea di,date
call PutStrng
mov ax,day
call putdec
call NewLine
mov cx,12
lea di,advertsprompt
call PutStrng
mov ax,AdvertisingMade
call putdec
call NewLine
mov cx,14
lea di,production
call PutStrng
mov ax,GlassesMade
call putdec
call NewLine
mov cx,17
lea di,priceprompt
call PutStrng
invoke @outputdollars,PriceperGlass
call NewLine
mov cx,14
lea di,sales
call PutStrng
mov ax,GlassesSold
call putdec
call NewLine
mov cx,8
lea di,profitprompt
call PutStrng
invoke @outputdollars,Profit
call NewLine
lea di,assetsprompt
call PutStrng
invoke @outputdollars,assets
invoke @clearscreen,3
inc day
pop cx
pop ax
ret
@AssetStatement ENDp
@PromptforDays proc near C
push cx
push ax
@pfdfor:
mov cx,57
lea di,daysprompt
call PutStrng
call getdec
cmp ax,30
jg @pfdtryagain
cmp ax,0
jle @pfdtryagain
jmp @pfdendfor
@pfdtryagain:
mov cx,30
lea di,numberoutofrange
call PutStrng
call NewLine
jmp @pfdfor
@pfdendfor:
mov DaystoPlay,ax
pop cx
pop ax
ret
@promptforDays endp
;########Generate weather report#########
;Generates the weather report for the day
@GenerateWeather Proc near C
push ax
push bx
push cx
push dx
invoke @randomnumber, 4
Mov Cx, 35
@gswitch:
cmp ax, 0
je @gcase0
cmp ax, 1
je @gcase1
cmp ax, 2
je @gcase2
cmp ax, 3
je @gcase3
cmp ax, 4
je @gcase4
jmp @gdefault
@gcase0:
Lea Di, weather0
Call PutStrng
Call NewLine
mov weathercond, 0
jmp @gendswitch
@gcase1:
Lea Di, weather1
Call PutStrng
Call NewLine
mov weathercond, 1
jmp @gendswitch
@gcase2:
Lea Di, weather2
Call PutStrng
Call NewLine
mov weathercond, 2
jmp @gendswitch
@gcase3:
Lea Di, weather3
Call PutStrng
Call NewLine
mov weathercond, 3
jmp @gendswitch
@gcase4:
Lea Di, weather4
Call PutStrng
Call NewLine
mov weathercond, 4
jmp @gendswitch
@gdefault:
@gendswitch:
call NewLine
pop dx
pop cx
pop bx
pop ax
ret
@generateweather endp
;#########Glasses Sold###################
;Figures the #of glasses sold
;Based on the weather, advertising
;and price charged.
@glassessold Proc Near
push ax
push bx
push cx
push dx
invoke @RandomNumber, 20 ;generate the max selling price
mov MaxPrice, ax ;move into max selling variable
mov ax, WeatherCond ;Adjust max price to reflect the weather
;switch changes max price to a percentage multiplier
@mxswitch:
cmp ax, 0
je @mxcase0
cmp ax, 1
je @mxcase1
cmp ax, 2
je @mxcase2
cmp ax, 3
je @mxcase3
cmp ax, 4
je @mxcase4
jmp @mxdefault
@mxcase0:
mov WeatherCond, 40
jmp @mxendswitch
@mxcase1:
mov WeatherCond, 20
jmp @mxendswitch
@mxcase2:
mov WeatherCond, 4
jmp @mxendswitch
@mxcase3:
mov WeatherCond, 2
jmp @mxendswitch
@mxcase4:
mov WeatherCond, 1
jmp @mxendswitch
@mxdefault:
@mxendswitch:
mov Ax, MaxPrice
mov Bx, WeatherCond ;conditions
xor dx,dx ;Divide by weather condition add result to
cwd ;max price
idiv bx ;effect is a higher max price based on higher
add MaxPrice, Ax ;weather condition
invoke @RandomNumber,10 ;generate random number between 0-10
add Ax, 5 ;shifts the range to 5-15
mov MaxGlassesSold, Ax
mov Bx, WeatherCond
xor dx,dx ;Divide by weather condition add result to
cwd ;maxglasses sold
idiv bx ;effect is a higher max glasses sold based on higher
add MaxGlassesSold, Ax ;weather condition
mov ax, AdvertisingMade
@adswitch:
cmp ax, 5
jl @adcase0
cmp ax, 10
jl @adcase1
cmp ax, 15
jl @adcase2
cmp ax, 21
jl @adcase3
jmp @addefault
@adcase0:
mov GlassMul, 15
jmp @adendswitch
@adcase1:
mov GlassMul, 8
jmp @adendswitch
@adcase2:
mov GlassMul, 3
jmp @adendswitch
@adcase3:
mov GlassMul, 1
jmp @adendswitch
@addefault:
@adendswitch:
mov Ax, MaxGlassesSold ;further increase the max # of glasses sold by
;figure the multipier for Glasses based on advertising
mov Bx, GlassMul ;using the advertising multiplier
xor dx, dx
cwd
idiv bx ;divide by the number
add MaxGlassesSold, Ax ;add it to maxglasses sold
invoke @RandomNumber, 10 ; randomly add/subtract from glasses
@adif:
cmp ax, 5
jl @adthen
jmp @adelse
@adthen:
invoke @RandomNumber, 5 ;add a random component from max glasses sold
add MaxGlassesSold, ax
@adelse:
invoke @RandomNumber, 5 ;subtract a random component from max glasses sold
sub MaxGlassesSold, ax
@adendif:
;########################################
;At this point your ideal max glasses sold and ideal maxprice is figured
;so if your price/glass = maxprice you're going to sell all your glasses up to
;maxglassessold
;########################################
mov cx, PricePerGlass
@glif:
cmp cx, MaxPrice ;compare the price/glass to max price
jg @glthen ;if it's greater then glasses sold
jmp @glendif ;will need to be reduced proportionally
@glthen:
mov Ax, PricePerGlass
mov cx, MaxPrice
xor dx, dx
cwd
div cx ;divide priceperglass by max price
mov bx, ax
mov ax, MaxGlassesSold
xor dx, dx
cwd
div bx ;divide by divider
mov MaxGlassesSold, ax ;replace the reduced maxglassessold with
;the divided value
@glendif: ;####END IF
mov bx, MaxGlassesSold
mov GlassesSold, bx ;populate glassessold with final number
mov cx, GlassesMade ;load how many were made into Cx
@gsif:
cmp cx, GlassesSold ;if glasses made > glasses sold then
jl @gsthen
jmp @gsendif
@gsthen:
mov GlassesSold, cx ;glasses sold = glasses made
jmp @gsendif
@gsendif:
call NewLine
;########################################
;glassessold is ultimately the output of this function
;it is a global variable therefore the function is a void
;########################################
pop dx
pop cx
pop bx
pop ax
ret
@glassessold endp
;#####PrintIntro#########################
@PrintIntro Proc Near C
mov Cx, 25
lea Di, Intro
call PutStrng
invoke @ClearScreen,2
mov cx,80
lea di, logo01
call PutStrng
lea di, logo02
call PutStrng
lea di, logo03
call PutStrng
lea di, logo04
call PutStrng
lea di, logo05
call PutStrng
lea di, logo06
call PutStrng
lea di, logo07
call PutStrng
lea di, logo08
call PutStrng
lea di, logo09
call PutStrng
lea di, logo10
call PutStrng
lea di, logo11
call PutStrng
lea di, logo12
call PutStrng
lea di, logo13
call PutStrng
lea di, logo14
call PutStrng
lea di, logo15
call PutStrng
lea di, logo16
call PutStrng
lea di, logo17
call PutStrng
lea di, logo18
call PutStrng
lea di, logo19
call PutStrng
lea di, logo20
call PutStrng
push ax
call GetDec
pop ax
ret
@PrintIntro ENDp
@PrintInstructions Proc Near
mov cx, 80
lea di, Instructions01
call PutStrng
call NewLine
lea di, Seperator1
call NewLine
call PutStrng
call NewLine
lea di, Instructions02
call PutStrng
lea di, Instructions03
call PutStrng
lea di, Instructions04
call PutStrng
call NewLine
lea di, Seperator1
call PutStrng
call NewLine
lea di, Instructions05
call PutStrng
Invoke @ClearScreen, 5
ret
@PrintInstructions ENDp
@GameOver Proc Near
lea di, GameOver01
call PutStrng
lea di, GameOver02
call PutStrng
lea di, GameOver03
call PutStrng
lea di, GameOver04
call PutStrng
lea di, GameOver05
call PutStrng
lea di, GameOver06
call PutStrng
lea di, GameOver07
call PutStrng
ret
@GameOver ENDp
;###########MAIN#########################
main Proc Far
MOV AX,SEG DATA
MOV DS,AX
MOV ES,AX
invoke @ClearScreen, 25
invoke @PrintIntro
invoke @ClearScreen, 25
invoke @PrintInstructions
invoke @PromptForDays
invoke @ClearScreen,25
@for:
cmp DaystoPlay,0
jg @do
jmp @endfor
@do:
invoke @SetCostPerGlass
invoke @SetAdvertisingCost
invoke @PostDailyInfo
invoke @generateweather
invoke @inputforday
invoke @glassessold
invoke @assetstatement
mov ax, CostPerGlass
@if:
cmp CurrentAssets, ax
jl @then
jmp @endif
@then:
mov cx, 32
lea di, OutOfMoney
call PutStrng
call NewLine
jmp @endfor
@endif:
dec DaysToPlay
jmp @for
@endfor:
invoke @GameOver
mov ah, 4ch
int 21h
main ENDp
Code Ends
SSeg Segment STACK
DB 254 dup(?)
SSeg Ends
End main