Dim waitingItem(3) As String Dim receivedItem(3) As String Dim onBoat As String Dim iCounter As Integer Dim boatEmpty As Boolean Dim boatLeft As Boolean Sub startGame() reset 'reset message Range("F22").Value = ""
boatLeft = True readWaitingItem readReceivedItem clearBoat boatEmpty = True End Sub Sub acrossRiver() MoveBoat If boatLeft Then checkReceivedValid Else checkWaitingValid checkWin End If End Sub Sub checkWin() If receivedItem(0) = "Cabbage"And receivedItem(1) = "Sheep"And receivedItem(2) = "Wolf" Then 'winning message Range("F22").Value = "Mission completed!" End If End Sub Sub checkWaitingValid() If waitingItem(0) = "Cabbage"And waitingItem(1) = "Sheep" Then MsgBox "Sheep ate the Cabbage!", vbCritical, "Cross The River" endGame End If If waitingItem(1) = "Sheep"And waitingItem(2) = "Wolf" Then MsgBox "Wolf ate the Sheep!", vbCritical, "Cross The River" endGame End If End Sub Sub checkReceivedValid() If receivedItem(0) = "Cabbage"And receivedItem(1) = "Sheep" Then MsgBox "Sheep ate the Cabbage!" endGame End If If receivedItem(1) = "Sheep"And receivedItem(2) = "Wolf" Then MsgBox "Wolf ate the Sheep!", vbCritical, "Cross The River" endGame End If End Sub Sub endGame() Range("F22").Value = "Mission not complete!" reset End Sub Sub reset() 'clear waiting andreceived area Range("D4").Value = "Cabbage" Range("D9").Value = "Sheep" Range("D14").Value = "Wolf" Range("L4").ClearContents Range("L9").ClearContents Range("L14").ClearContents 'clear boat Range("F8").Value = "TheBoat" Range("F9").ClearContents Range("F8").Interior.ColorIndex = 44 Range("F9").Interior.ColorIndex = 2 Range("G8:I9").ClearContents Range("G8:I9").Interior.ColorIndex = 49 End Sub Sub clearBoat() onBoat = "" If boatLeft Then Range("F9").Value = "" Else Range("I9").Value = "" End If End Sub Sub addCabbage() If boatEmpty = False Then MsgBox "The boat is full already" Else If boatLeft Then waitingItem(0) = "" receivedItem(0) = "Cabbage" onBoat = "Cabbage" Range("D4").Value = "" Else receivedItem(0) = "" waitingItem(0) = "Cabbage" onBoat = "Cabbage" Range("L4").Value = "" End If boatEmpty = False printBoat End If End Sub Sub removeCabbage() If boatEmpty Then MsgBox "boat is empty already" Else If boatLeft Then If waitingItem(0) = "Cabbage" Then MsgBox "Cabbage is removed already" Else receivedItem(0) = "" Range("D4").Value = "Cabbage" waitingItem(0) = "Cabbage" End If Else If receivedItem(0) = "Cabbage" Then MsgBox "Cabbage is removed already" Else waitingItem(0) = "" Range("L4").Value = "Cabbage" receivedItem(0) = "Cabbage" End If End If onBoat = "" boatEmpty = True printBoat End If End Sub
Sub addSheep() If boatEmpty = False Then MsgBox "The boat is full already" Else If boatLeft Then waitingItem(1) = "" receivedItem(1) = "Sheep" onBoat = "Sheep" Range("D9").Value = "" Else receivedItem(1) = "" waitingItem(1) = "Sheep" onBoat = "Sheep" Range("L9").Value = "" End If boatEmpty = False printBoat End If End Sub Sub removeSheep() If boatEmpty Then MsgBox "boat is empty already" Else If boatLeft Then If waitingItem(1) = "Sheep" Then MsgBox "Sheep is removed already" Else receivedItem(1) = "" Range("D9").Value = "Sheep" waitingItem(1) = "Sheep" End If Else If receivedItem(1) = "Sheep" Then MsgBox "Sheep is removed already" Else waitingItem(1) = "" Range("L9").Value = "Sheep" receivedItem(1) = "Sheep" End If End If onBoat = "" boatEmpty = True printBoat End If End Sub Sub addWolf() If boatEmpty = False Then MsgBox "The boat is full already" Else If boatLeft Then waitingItem(2) = "" receivedItem(2) = "Wolf" onBoat = "Wolf" Range("D14").Value = "" Else receivedItem(2) = "" waitingItem(2) = "Wolf" onBoat = "Wolf" Range("L14").Value = "" End If boatEmpty = False printBoat End If End Sub Sub removeWolf() If boatEmpty = True Then MsgBox "The boat is empty already" Else If boatLeft Then If waitingItem(2) = "Wolf" Then MsgBox "Wolf is removed already" Else receivedItem(2) = "" Range("D14").Value = "Wolf" waitingItem(2) = "Wolf" End If Else If receivedItem(2) = "Wolf" Then MsgBox "Wolf is removed already" Else waitingItem(2) = "" Range("L14").Value = "Wolf" receivedItem(2) = "Wolf" End If End If onBoat = "" boatEmpty = True printBoat End If End Sub Sub printBoat() If boatLeft Then Range("F9").Value = onBoat Else Range("I9").Value = onBoat End If End Sub Sub readWaitingItem() For iCounter = 0 To 2 waitingItem(iCounter) = Cells(4 + iCounter * 5, 4).Value Next iCounter
End Sub Sub readReceivedItem() For iCounter = 0 To 2 receivedItem(iCounter) = Cells(4 + iCounter * 5, 12).Value Next iCounter
End Sub Sub MoveBoat() If boatLeft Then Range("F8:F9").Select Selection.Cut Range("I8").Select ActiveSheet.Paste Application.CutCopyMode = False Range("F8:F9").Interior.ColorIndex = 49 boatLeft = False Else Range("I8:I9").Select Selection.Cut Range("F8").Select ActiveSheet.Paste Application.CutCopyMode = False Range("I8:I9").Interior.ColorIndex = 49 boatLeft = True End If dropItem End Sub Sub dropItem() clearBoat boatEmpty = True printWaiting printReceived End Sub Sub printWaiting() If waitingItem(0) = "Cabbage" Then Range("D4").Value = "Cabbage" End If If waitingItem(1) = "Sheep" Then Range("D9").Value = "Sheep" End If If waitingItem(2) = "Wolf" Then Range("D14").Value = "Wolf" End If End Sub Sub printReceived() If receivedItem(0) = "Cabbage" Then Range("L4").Value = "Cabbage" End If If receivedItem(1) = "Sheep" Then Range("L9").Value = "Sheep" End If If receivedItem(2) = "Wolf" Then Range("L14").Value = "Wolf" End If End Sub ''''''''''''''''''''testing functions''''''''''''''''''''
Sub testWaitingIterm() For iCounter = 0 To 2 MsgBox waitingItem(iCounter) Next iCounter End Sub Sub testreceivedIterm() For iCounter = 0 To 2 MsgBox receivedItem(iCounter) Next iCounter End Sub Sub testonBoatIterm() MsgBox onBoat MsgBox boatEmpty End Sub