Microsoft Small Basic

Program Listing: DFZ772
nextgame = "True"
' Declare arrays for the squares, chance and community chest
InitBoard()
While nextgame
' Prepare the game
playerpos[1] = 1 ' start position for player 1
playerpos[2] = 1 ' start position for player 2
DrawBoard()
' Start the game
continue = "True"
While continue
' Play by player 1
player = 1
Play()
If continue Then
' Play by player 2
player = 2
Play()
EndIf
EndWhile
' Game ending
' Ask next game
EndWhile

Sub InitBoard
colmax = 11
rowmax = 11
playercolor[1] = "Yellow"
playercolor[2] = "Cyan"
posmax = (colmax + rowmax - 2) * 2
For i = 1 To posmax
If (1 <= i) And (i < rowmax) Then
colpos[i] = 1
rowpos[i] = rowmax + 1 - i
ElseIf (rowmax <= i) And (i <= rowmax + colmax - 2) Then
colpos[i] = i - rowmax + 1
rowpos[i] = 1
ElseIf (colmax + rowmax - 1 <= i) And (i <= 2 * rowmax + colmax - 2) Then
colpos[i] = colmax
rowpos[i] = i - rowmax - colmax + 2
ElseIf (2 * colmax + rowmax - 1 <= i) And (i <= posmax) Then
colpos[i] = posmax - i + 2
rowpos[i] = rowmax
EndIf
EndFor
EndSub

Sub DrawBoard
For pos = 1 To posmax
DrawSquare()
EndFor
EndSub

Sub DrawSquare
' param pos
col = colpos[pos]
row = rowpos[pos]
left = (col - 1) * 7
top = (row - 1) * 2
' Draw top row
TextWindow.CursorLeft = left
TextWindow.CursorTop = top
TextWindow.Write("+------+")
top = top + 1
' Draw center row
TextWindow.CursorLeft = left
TextWindow.CursorTop = top
TextWindow.Write("|")
If pos = 1 Then
TextWindow.Write("GO")
Else
If pos < 10 Then
TextWindow.Write(" ")
EndIf
TextWindow.Write(pos)
EndIf
TextWindow.ForegroundColor = playercolor[1]
TextWindow.Write(" ") ' reserved for player 1
If playerpos[1] = pos Then
TextWindow.Write("o")
Else
TextWindow.Write(" ")
EndIf
TextWindow.ForegroundColor = playercolor[2]
TextWindow.Write(" ") ' reserved for player 2
If playerpos[2] = pos Then
TextWindow.Write("o")
Else
TextWindow.Write(" ")
EndIf
TextWindow.ForegroundColor = "Gray"
TextWindow.Write("|")
top = top + 1
' Draw bottom row
TextWindow.CursorLeft = left
TextWindow.CursorTop = top
TextWindow.Write("+------+")
top = top + 1
EndSub

Sub Play
' Input some key to roll the dice
TextWindow.CursorLeft = 0
TextWindow.CursorTop = rowmax * 2 + 1
TextWindow.ForegroundColor = playercolor[player]
TextWindow.Write("Player " + player +" --> ")
TextWindow.ForegroundColor = "Gray"
TextWindow.Write("Press enter...")
TextWindow.Read()
TextWindow.CursorLeft = 13
TextWindow.CursorTop = TextWindow.CursorTop - 1
' Role the dice
d = Math.GetRandomNumber(6)
TextWindow.ForegroundColor = playercolor[player]
TextWindow.WriteLine(d + " ")
TextWindow.ForegroundColor = "Gray"
For i = 1 To d
MoveToNext()
DrawBoard()
Sound.PlayClickAndWait()
EndFor
' Show the player's tactics
' If the new position is owned by the other player
' Try to deduct the rent
' If player has no rent
' Sell one of his properties
' Calculate the remainder
' Judge of game end
EndSub

Sub MoveToNext
p = playerpos[player]
p = p + 1
If p > posmax Then
p = 1
EndIf
playerpos[player] = p
EndSub