Created
July 28, 2010 15:56
-
-
Save XQYZ/494986 to your computer and use it in GitHub Desktop.
This is Guess the Number as a word macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Log(Text) | |
Selection.TypeText (Text) | |
Selection.TypeParagraph | |
End Sub | |
Function RandomG(Max) | |
RandomG = Int(Rnd * Max) | |
End Function | |
Sub RandomGame() | |
Application.StatusBar = "Random Game (c) 2009 by Patrick Lerner" | |
ActiveDocument.Select | |
Selection.TypeBackspace | |
Dim result As String | |
' Logging on or off? | |
Logging = MsgBox("Should the game be logged into a word document?", vbYesNo + vbQuestion) = vbYes | |
Harcore = MsgBox("Do you want to have the game cursing about wrong results?", vbYesNo + vbQuestion) = vbYes | |
Randomize | |
Game = 0 | |
If Logging Then | |
With Selection | |
With .Font | |
.Color = RGB(0, 0, 255) | |
.Bold = msoTrue | |
.StrikeThrough = msoFalse | |
.Size = 25 | |
.Name = "Arial" | |
End With | |
.ParagraphFormat.Alignment = wdAlignParagraphCenter | |
Log ("RandomGame") | |
With .Font | |
.Color = RGB(0, 0, 0) | |
.Size = 10 | |
.Bold = msoFalse | |
.Name = "Times New Roman" | |
.Italic = msoTrue | |
End With | |
Log ("(c) 2009 by Patrick Lerner [[email protected]]") | |
.Font.Italic = msoFalse | |
.Font.Size = 12 | |
.ParagraphFormat.Alignment = wdAlignParagraphLeft | |
End With | |
End If | |
Do | |
Game = Game + 1 | |
If Logging Then | |
Selection.Font.Bold = True | |
Log (" GAME " & Game) | |
Selection.Font.Bold = False | |
End If | |
Number = Int(Int(Rnd * 1001) + 1) | |
Guess = -1 | |
Turns = 0 | |
Do Until Guess = Number | |
Guess = InputBox("Guess the random number between 1 and 1000:", "RandomGame (Game " & Game & ", Turn " & (Turns + 1) & ")") | |
If ((Guess = "exit") Or (Guess = "quit") Or (Guess = vbNullString)) Then | |
Exit Sub | |
Else | |
If Guess = "cheat" Then | |
If Hardcore Then | |
MsgBox ("Here you go, sucker: " & Number) | |
Else | |
MsgBox ("Ok, the number is " & Number) | |
End If | |
If Logging Then | |
If Harcore Then | |
Select Case RandomG(3) | |
Case 0 | |
Log ("Turn " & Turns & ": You turned out to be a fracking cheater.") | |
Case 1 | |
Log ("Turn " & Turns & ": No way you din't just cheat, did you?") | |
Case 2 | |
Log ("Turn " & Turns & ": You do know what they say about cheaters, don't you?") | |
End Select | |
Else | |
Log ("Turn " & Turns & ": You cheated!") | |
End If | |
End If | |
Else | |
Guess = Int(Guess) | |
Turns = Turns + 1 | |
result = "" | |
If ((Guess > 1000) Or (Guess < 1)) Then | |
If Harcore Then | |
Select Case RandomG(7) | |
Case 0 | |
result = "EPIC FAIL!" | |
Case 1 | |
result = "The number has to be beween 1 and 1000, so way to go, dipshit." | |
Case 2 | |
result = "Didn't I mention it has to be between 1 and 1000? Hell yeah I did." | |
Case 3 | |
result = "Are you stupid? I said a number between 1 and 1000." | |
Case 4 | |
result = "I wonder what would happen if I devided this by zero ... oh shi-" | |
Case 5 | |
result = "Et tu " & (Environ$("Username")) & "? You failed me. Epically that is - of course." | |
Case 6 | |
result = "Obviously someone didn't get the 'between 1 and 1000' part of the question..." | |
End Select | |
Else | |
Select Case RandomG(3) | |
Case 0 | |
result = "The number needs to be beween 1 and 1000." | |
Case 1 | |
result = "Numbers are only valid beween 1 and 1000." | |
Case 2 | |
result = "As the text clearly stated you're guess had to be beween 1 and 1000." | |
End Select | |
End If | |
Else | |
If Guess > Number Then | |
If Harcore Then | |
Select Case RandomG(3) | |
Case 0 | |
result = "Too fracking big, man!" | |
Case 1 | |
result = "Way to go... it's too big." | |
Case 2 | |
result = "$MY_NUMBER < $YOUR_STUPID_GUESS" ' wish this was php not frackin' vbs (BSG rules btw, just fyi) | |
End Select | |
Else | |
Select Case RandomG(3) | |
Case 0 | |
result = "That's too big." | |
Case 1 | |
result = "We need something smaller here." | |
Case 2 | |
result = "Not bad, but try something a bit smaller." | |
End Select | |
End If | |
Else | |
If Guess < Number Then | |
If Harcore Then | |
Select Case RandomG(3) | |
Case 0 | |
result = "You got to be kidding me, that's WAY too small" | |
Case 1 | |
result = "TOO SMALL! Damn it." | |
Case 2 | |
result = "Wow, that's too small." | |
End Select | |
Else | |
Select Case RandomG(3) | |
Case 0 | |
result = "That's too small." | |
Case 1 | |
result = "You know what they say? The bigger, the better. Try it here!" | |
Case 2 | |
result = "We need a bigger number here." | |
End Select | |
End If | |
End If | |
End If | |
End If | |
If result <> "" Then | |
MsgBox (result) | |
End If | |
If Logging Then | |
If result <> "" Then | |
result = " - " & result | |
End If | |
Log ("Turn " & Turns & ": You guessed " & Guess & result) | |
End If | |
End If | |
End If | |
Loop | |
MsgBox ("Yeah, that's it! It took you " & Turns & " turns.") | |
If Logging Then | |
If Hardcore Then | |
Select Case RandomG(4) | |
Case 0 | |
Log ("Turn " & Turns & ": Look at that, you got it ... EVENTUALLY") | |
Case 1 | |
Log ("Turn " & Turns & ": Oh you GOT to be kidding me ... what took you so long?") | |
Case 2 | |
Log ("Turn " & Turns & ": You really let me down back there; how can anyone take so long for such a simple task?") | |
Case 3 | |
Log ("Turn " & Turns & ": Speed up next time.") | |
End Select | |
Else | |
Select Case RandomG(3) | |
Case 0 | |
Log ("Turn " & Turns & ": You got it right!") | |
Case 1 | |
Log ("Turn " & Turns & ": That's it! Good job there, buddy.") | |
Case 2 | |
Log ("Turn " & Turns & ": That's right, nicely done.") | |
End Select | |
End If | |
Log ("") | |
End If | |
Loop Until MsgBox("Game finished. Do you want to play another round?", vbYesNo + vbQuestion) = vbNo | |
If Logging Then | |
If MsgBox("Do you want to clear the game log?", vbYesNo + vbQuestion) = vbYes Then | |
ActiveDocument.Select | |
Selection.TypeBackspace | |
End If | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment