Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;--------------------------------------------------------------------------------------------------------
- ; PROCEDURE TO DECIDE THE COMPUTER'S MOVES
- ;--------------------------------------------------------------------------------------------------------
- ; GOTO PLAYER2TURN
- player2Turn PROC
- mov esi, offset player1board
- cmp computerguess, 0
- je guessUp
- cmp computerguess, 1
- je guessDown
- cmp computerguess, 2
- je guessLeft
- cmp computerguess, 3
- je guessRight
- jmp generatePoints
- guessUp:
- cmp ypoint, 0
- je generatePoints
- inc ypoint
- call checkHitOrNot
- guessDown:
- cmp ypoint, 9
- je generatePoints
- dec ypoint
- call checkHitOrNot
- guessLeft:
- cmp xpoint, 9
- je generatePoints
- inc xpoint
- call checkHitOrNot
- guessRight:
- cmp xpoint, 0
- je generatePoints
- dec xpoint
- call checkHitOrNot
- ; Gets a random number from 0 - 9 as the x and y points
- generatePoints:
- mov eax, 10
- call RandomRange
- mov xpoint, al
- call RandomRange
- mov ypoint, al
- ; Checks if the point was a hit or not
- checkHitOrNot:
- call coordinateToIndex
- mov ebx, 0
- movzx ebx, shipindex
- add esi, ebx
- ; If its not ASCII 176 (empty spot), randomizes the points again
- mov bl, 176
- cmp [esi], bl
- jne itsAlreadyPicked
- ; If there is a ship, calls player2Hits. If not, calls player2Misses
- mov bl, 254
- cmp [esi], bl
- je player2Hits
- jmp player2Misses
- ; If the spot has already been picked
- itsAlreadyPicked:
- jmp generatePoints
- player2Hits:
- inc player2score
- mov ebx, 0
- mov bl, 88
- mov [esi], bl
- cmp player2score, 17
- je player2Wins
- jmp endOfTurn
- player2Misses:
- mov ebx, 0
- mov bl, 79
- mov [esi], bl
- jmp endOfTurn
- player2Wins:
- ; CALL THE LOSE WINDOW
- endOfTurn:
- call displayPlayer1Board
- ret
- ret
- player2Turn ENDP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement