Microsoft Small Basic

Program Listing: DFZ772-0
' Monopoly Like Game 0.2a
' Program ID DFZ772-0
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