home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / tstcon / scripts / simon.dsm next >
Encoding:
Text File  |  1998-03-27  |  4.7 KB  |  190 lines

  1. Private Sub InitAgent()
  2.    Dim objGenie
  3.          
  4.    Agent.Connected = True
  5.    Agent.Characters.Load "Genie", "C:\Program Files\Microsoft Agent\Characters\Genie.acs"
  6.    Set objGenie = Agent.Characters( "Genie" )
  7.  
  8.    objGenie.Show
  9.  
  10.    objGenie.Commands.Caption = "Simon"
  11.    objGenie.Commands.Add "Play", "Play", "play", True, True
  12.    objGenie.Commands.Add "Hello", "Hello", "hello", True, True
  13.    objGenie.Commands.Add "Red", "Red", "red", True, True
  14.    objGenie.Commands.Add "Blue", "Blue", "blue", True, True
  15.    objGenie.Commands.Add "Green", "Green", "green", True, True
  16.    objGenie.Commands.Add "Yellow", "Yellow", "yellow", True, True
  17. End Sub
  18.  
  19. Dim intTick  ' How many timer ticks have gone by for this move?
  20. Dim intMoves  ' How many moves in this sequence?
  21. Dim blnRunning  ' Playing sequence for player
  22. Dim blnWaiting  ' Waiting for player to move
  23. Dim intHighlightedColor  ' Which color is currently highlighted
  24. Dim intMove  ' Current move
  25. Dim intSpeed  ' Number of ms in one timer tick
  26. Dim aintMoves( 20 )  ' The sequence of moves
  27.  
  28. intTick = 0
  29. intMove = 0
  30. intMoves = 1
  31. intMaxMoves = 6
  32. intSpeed = 1000
  33. blnRunning = False
  34. blnWaiting = False
  35. intDoneTurn = 0
  36. intHighlightedColor = 0
  37. InitAgent
  38.  
  39. Private Sub EndTurn()
  40.    Timer.Interval = 0
  41.    blnWaiting = False
  42.    If intMoves = intMaxMoves Then
  43.       EndGame( True )
  44.    Else
  45.       intMoves = intMoves+1
  46.       Agent.Characters( "Genie" ).Speak "My turn"
  47.       intTick = 0
  48.       intMove = 0
  49.       Timer.Interval = intSpeed
  50.       blnRunning = True
  51.    End If
  52. End Sub
  53.  
  54. Private Sub EndGame( ByVal blnWin )
  55.    Timer.Interval = 0
  56.    blnWaiting = False
  57.    blnRunning = False
  58.    If blnWin Then
  59.       Agent.Characters( "Genie" ).Speak "You win!"
  60.       Agent.Characters( "Genie" ).Speak "Kick ass!"
  61.    Else
  62.       Agent.Characters( "Genie" ).Speak "You lose!"
  63.    End If
  64. End Sub
  65.  
  66. Private Sub MakeMove( ByVal intColor )
  67.    If aintMoves( intMove ) = intColor Then
  68.       intMove = intMove+1
  69.       intTick = 0
  70.       If intMove = intMoves Then
  71.          intDoneTurn = 2
  72.       End If
  73.    Else
  74.       EndGame( False )
  75.    End If
  76. End Sub
  77.  
  78. Sub Red_Click()
  79.    If blnWaiting Then
  80.       MakeMove( 0 )
  81.    End If
  82. End Sub
  83.  
  84. Sub Green_Click()
  85.    If blnWaiting Then
  86.       MakeMove( 1 )
  87.    End If
  88. End Sub
  89.  
  90. Sub Blue_Click()
  91.    If blnWaiting Then
  92.       MakeMove( 2 )
  93.    End If
  94. End Sub
  95.  
  96. Sub Yellow_Click()
  97.    If blnWaiting Then
  98.       MakeMove( 3 )
  99.    End If
  100. End Sub
  101.  
  102. Sub Play_Click()
  103.    If (Not blnRunning) And (Not blnWaiting) Then
  104.       intTick = 0
  105.       intMove = 0
  106.  
  107.       Randomize()
  108.       blnRunning = True
  109.       Timer.Interval = intSpeed
  110.    End If
  111. End Sub
  112.  
  113. Sub Agent_Command( ByVal objUserInput )
  114.    If objUserInput.Name = "Red" Then
  115.       Red_Click
  116.    ElseIf objUserInput.Name = "Green" Then
  117.       Green_Click
  118.    ElseIf objUserInput.Name = "Blue" Then
  119.       Blue_Click
  120.    ElseIf objUserInput.Name = "Yellow" Then
  121.       Yellow_Click
  122.    ElseIf objUserInput.Name = "Play" Then
  123.       Play_Click
  124.    ElseIf objUserInput.Name = "Hello" Then
  125.       Agent.Characters( "Genie" ).Speak "Hey, how's it going?"
  126.    End If
  127. End Sub
  128.  
  129. Sub Timer_Timer()
  130.    Dim intColor
  131.  
  132.    If intDoneTurn > 0 Then
  133.       intDoneTurn = intDoneTurn-1
  134.       If intDoneTurn = 0 Then
  135.          EndTurn
  136.       End If
  137.    ElseIf blnRunning Then
  138.       If intTick = 0 Then
  139.          If intMove < intMoves-1 Then
  140.             intColor = aintMoves( intMove )
  141.          Else
  142.             intColor = Int( 4*Rnd )
  143.          End If
  144.          Select Case intColor
  145.             Case 0
  146.                Red.BackColor = vbRed
  147.                intHighlightedColor = 0
  148.             Case 1
  149.                Green.BackColor = vbGreen
  150.                intHighlightedColor = 1
  151.             Case 2
  152.                Blue.BackColor = vbBlue
  153.                intHighlightedColor = 2
  154.             Case 3
  155.                Yellow.BackColor = vbYellow
  156.                intHighlightedColor = 3
  157.          End Select
  158.          aintMoves( intMove ) = intColor
  159.       ElseIf intTick = 1 Then
  160.          Select Case intHighlightedColor
  161.             Case 0
  162.                Red.BackColor = vbWhite
  163.             Case 1
  164.                Green.BackColor = vbWhite
  165.             Case 2
  166.                Blue.BackColor = vbWhite
  167.             Case 3
  168.                Yellow.BackColor = vbWhite
  169.          End Select
  170.          intMove = intMove+1
  171.       End If
  172.       intTick = intTick+1
  173.       If intTick >= 3 Then 
  174.          intTick = 0
  175.       End If
  176.       If intMove = intMoves Then
  177.          blnRunning = False
  178.          intMove = 0
  179.          Agent.Characters( "Genie" ).Speak "Your turn"
  180.          blnWaiting = True
  181.          intTick = 0
  182.       End If
  183.    ElseIf blnWaiting Then
  184.       intTick = intTick+1
  185.       If intTick = 6 Then
  186.          EndGame( False )
  187.       End If
  188.    End If
  189. End Sub
  190.