Microsoft Small Basic

Program Listing: ZCF870

' London Monopoly Framework

' Board squares are referenced by a code number from 1 to 40 (inclusive) based on their sequential position: Go = 1 ... Mayfair = 40
' Special squares are referenced by a code number based on the type of special square: i.e. Go = 1, Communiy Chests = 2, Chances = 3, etc.
' Players are referenced by a code number: Player 1 = 1, Player 2 = 2

main()

'-------------------------------------------------------------------------------
Sub Main
TextWindow.WriteLine("Initialsing Game...")
InitialiseGame()
While playing
TakeTurn()
UpdateDisplay()
Continue()
EndWhile
EndSub

'-------------------------------------------------------------------------------

Sub Continue
' See if player is bankrupt
If player_bank[inactive_player] < 0 Then
bankrupt = "true"
playing = "false"
TextWindow.WriteLine("Player " + inactive_player + " went bankrupt!")
TextWindow.WriteLine("")
EndIf
' See if player wants to carry on
TextWindow.WriteLine("Hit Enter to continue or type anything else to quit...")
input = TextWindow.Read()
If input <> "" Then
playing = "false"
EndIf
EndSub

'-------------------------------------------------------------------------------

Sub UpdateDisplay
' Update the game display here
TextWindow.Clear()
'...

' Just dumping stats here for a demo...
TextWindow.WriteLine("Player " + inactive_player + " Rolled " + dice + " on the dice")
TextWindow.WriteLine("")

TextWindow.WriteLine("End of Turn Number: " + turn_number)
TextWindow.WriteLine("")

For i = 1 To 2
TextWindow.Write("Player " + i + " Properties Owned: ")
For j = 1 To 40
If property_owner[j] = i Then
TextWindow.Write(j + " ")
EndIf
EndFor
TextWindow.WriteLine("")
TextWindow.WriteLine("Player " + i + " Bank: £" + player_bank[i])
TextWindow.WriteLine("")
EndFor

EndSub

'-------------------------------------------------------------------------------

Sub TakeTurn

RollDice()

if player_in_jail[active_player] Then
'Player is in jail - determine if he can get out
' ...

' If player is still in jail end turn
if player_in_jail[active_player] Then
Goto END_OF_TURN
EndIf
EndIf

' Advance player on the board
player_position[active_player] = player_position[active_player] + dice

If player_position[active_player] > 40 Then
' Player is on, or has passed, Go
player_position[active_player] = player_position[active_player] - 40
player_bank[active_player] = player_bank[active_player] + 200
EndIf

' Determine what action to take based on which square a player has landed on
If property_special[player_position[active_player]] > 0 Then
' Player is on a special square, work out which one and take action
If property_special[player_position[active_player]] = 2 Then
' Player is on Community Chest
'...

ElseIf property_special[player_position[active_player]] = 3 Then
' Player is on Chance
'...

' Continue with ElseIfs for the rest of the special squares
'...

EndIf
ElseIf property_owner[player_position[active_player]] < 1 Then
' Player is on a free property, offer him the chance to buy it...
'...

'Player bought the property!
property_owner[player_position[active_player]] = active_player
player_bank[active_player] = player_bank[active_player] - property_cost[player_position[active_player]]
ElseIf property_owner[player_position[active_player]] = inactive_player Then
' Player is on a property owned by other player - pay the charge
player_bank[active_player] = player_bank[active_player] - property_charge[player_position[active_player]]
player_bank[inactive_player] = player_bank[inactive_player] + property_charge[player_position[active_player]]
EndIf

END_OF_TURN:

If active_player = 1 Then
active_player = 2
inactive_player = 1
Else
active_player = 1
inactive_player = 2
EndIf

turn_number = turn_number + 1

EndSub

'-------------------------------------------------------------------------------

Sub InitialiseGame
playing = "true"
turn_number = 0
player_position[1] = 0 ' Player 1's position on board
player_position[2] = 0 ' Player 2's position on board
player_in_jail[1] = "false" ' Is player in jail
player_in_jail[2] = "false"
player_bank[1] = 2600 ' How much money player has
player_bank[2] = 2600
active_player = Math.GetRandomNumber(2) ' Player whose turn it is
If active_player = 1 Then
inactive_player = 2
Else
inactive_player = 1
EndIf
InitialiseCosts()
InitialiseCharges()
InitialiseSpecials()
EndSub

'-------------------------------------------------------------------------------

Sub InitialiseCosts
' Set the intial cost for buying each property
property_cost[2] = 60 ' Old Kent Road
property_cost[4] = 60 ' Whitechapel Road
property_cost[6] = 200 ' Kings Cross Station
' ... Set the rest of the property charges here
'...

' Just setting some random costs here for the sake of a quick demo
For i = 1 To 40
property_cost[i] = Math.GetRandomNumber(400)
EndFor

EndSub

'-------------------------------------------------------------------------------

Sub InitialiseCharges
' Set the intial charge for landing on an owned property
property_charge[2] = 10 ' Old Kent Road
property_charge[4] = 12 ' Whitechapel Road
property_charge[6] = 20 ' Kings Cross Station
' ... Set the rest of the property charges here
'...

' Just setting some random charges here for the sake of a quick demo
For i = 1 To 40
property_charge[i] = Math.GetRandomNumber(100)
EndFor

EndSub

'-------------------------------------------------------------------------------

Sub InitialiseSpecials
' Set which squares are special
property_special[1] = 1 ' Go
property_special[3] = 2 ' Community Chest
property_special[8] = 3 ' Chance
' ... Set the rest of the special square codes here
'...

EndSub

'-------------------------------------------------------------------------------

Sub RollDice
die_1 = Math.GetRandomNumber(6)
die_2 = Math.GetRandomNumber(6)
dice = die_1 + die_2
EndSub