Advertisement
Guest User

GuessGame

a guest
Jan 31st, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1
  4.    BorderStyle     =   4  'Fixed ToolWindow
  5.   Caption         =   "Gæt et tal mellem 1 og 100"
  6.    ClientHeight    =   4275
  7.    ClientLeft      =   45
  8.    ClientTop       =   285
  9.    ClientWidth     =   6075
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.   MinButton       =   0   'False
  13.   ScaleHeight     =   4275
  14.    ScaleWidth      =   6075
  15.    ShowInTaskbar   =   0   'False
  16.   StartUpPosition =   2  'CenterScreen
  17.   Begin VB.Frame Frame3
  18.       Caption         =   "Cheats"
  19.       Height          =   975
  20.       Left            =   240
  21.       TabIndex        =   23
  22.       Top             =   3120
  23.       Width           =   3015
  24.       Begin VB.CheckBox Check1
  25.          Caption         =   "Se facit"
  26.          Height          =   195
  27.          Left            =   960
  28.          TabIndex        =   24
  29.          Top             =   240
  30.          Width           =   975
  31.       End
  32.       Begin VB.CommandButton Command6
  33.          Caption         =   "&OK"
  34.          Height          =   285
  35.          Left            =   2040
  36.          TabIndex        =   27
  37.          Top             =   480
  38.          Visible         =   0   'False
  39.         Width           =   495
  40.       End
  41.       Begin VB.TextBox Text1
  42.          Alignment       =   2  'Center
  43.         Enabled         =   0   'False
  44.         Height          =   285
  45.          Left            =   480
  46.          TabIndex        =   26
  47.          Text            =   "000"
  48.          Top             =   480
  49.          Visible         =   0   'False
  50.         Width           =   1455
  51.       End
  52.       Begin VB.TextBox Text3
  53.          Height          =   285
  54.          IMEMode         =   3  'DISABLE
  55.         Left            =   480
  56.          PasswordChar    =   "*"
  57.          TabIndex        =   25
  58.          Text            =   "test"
  59.          Top             =   480
  60.          Visible         =   0   'False
  61.         Width           =   1455
  62.       End
  63.       Begin VB.Label Label12
  64.          Caption         =   "indtast password"
  65.          Height          =   255
  66.          Left            =   480
  67.          TabIndex        =   28
  68.          Top             =   240
  69.          Visible         =   0   'False
  70.         Width           =   1335
  71.       End
  72.    End
  73.    Begin VB.Frame Frame2
  74.       Caption         =   "Stats"
  75.       Height          =   1215
  76.       Left            =   3480
  77.       TabIndex        =   18
  78.       Top             =   480
  79.       Width           =   2415
  80.       Begin VB.Label Label4
  81.          Caption         =   "Antal Gæt:"
  82.          BeginProperty Font
  83.             Name            =   "MS Sans Serif"
  84.             Size            =   9.75
  85.             Charset         =   0
  86.             Weight          =   700
  87.             Underline       =   0   'False
  88.            Italic          =   0   'False
  89.            Strikethrough   =   0   'False
  90.         EndProperty
  91.          Height          =   255
  92.          Left            =   360
  93.          TabIndex        =   22
  94.          Top             =   360
  95.          Width           =   1215
  96.       End
  97.       Begin VB.Label Label5
  98.          Caption         =   "Antal Spil:"
  99.          BeginProperty Font
  100.             Name            =   "MS Sans Serif"
  101.             Size            =   9.75
  102.             Charset         =   0
  103.             Weight          =   700
  104.             Underline       =   0   'False
  105.            Italic          =   0   'False
  106.            Strikethrough   =   0   'False
  107.         EndProperty
  108.          Height          =   255
  109.          Left            =   360
  110.          TabIndex        =   21
  111.          Top             =   600
  112.          Width           =   1095
  113.       End
  114.       Begin VB.Label Label10
  115.          Caption         =   "0"
  116.          BeginProperty Font
  117.             Name            =   "MS Sans Serif"
  118.             Size            =   9.75
  119.             Charset         =   0
  120.             Weight          =   700
  121.             Underline       =   0   'False
  122.            Italic          =   0   'False
  123.            Strikethrough   =   0   'False
  124.         EndProperty
  125.          Height          =   255
  126.          Left            =   1560
  127.          TabIndex        =   20
  128.          Top             =   600
  129.          Width           =   615
  130.       End
  131.       Begin VB.Label Label11
  132.          Caption         =   "0"
  133.          BeginProperty Font
  134.             Name            =   "MS Sans Serif"
  135.             Size            =   9.75
  136.             Charset         =   0
  137.             Weight          =   700
  138.             Underline       =   0   'False
  139.            Italic          =   0   'False
  140.            Strikethrough   =   0   'False
  141.         EndProperty
  142.          Height          =   255
  143.          Left            =   1560
  144.          TabIndex        =   19
  145.          Top             =   360
  146.          Width           =   615
  147.       End
  148.    End
  149.    Begin MSComDlg.CommonDialog CommonDialog1
  150.       Left            =   4440
  151.       Top             =   240
  152.       _ExtentX        =   847
  153.       _ExtentY        =   847
  154.       _Version        =   393216
  155.    End
  156.    Begin VB.Timer Timer2
  157.       Left            =   3480
  158.       Top             =   240
  159.    End
  160.    Begin VB.Timer Timer1
  161.       Left            =   3960
  162.       Top             =   240
  163.    End
  164.    Begin VB.TextBox Text5
  165.       Height          =   285
  166.       Left            =   3480
  167.       TabIndex        =   5
  168.       Text            =   "Game.txt"
  169.       Top             =   1920
  170.       Width           =   2415
  171.    End
  172.    Begin VB.TextBox Text4
  173.       Height          =   285
  174.       Left            =   240
  175.       MaxLength       =   10
  176.       TabIndex        =   4
  177.       Text            =   "Player1"
  178.       Top             =   720
  179.       Width           =   3015
  180.    End
  181.    Begin VB.CommandButton Command7
  182.       Caption         =   "Hent Game"
  183.       Height          =   375
  184.       Left            =   4680
  185.       TabIndex        =   3
  186.       Top             =   2280
  187.       Width           =   1215
  188.    End
  189.    Begin VB.CommandButton Command5
  190.       Caption         =   "A&bout"
  191.       Height          =   375
  192.       Left            =   3480
  193.       TabIndex        =   2
  194.       Top             =   3720
  195.       Width           =   855
  196.    End
  197.    Begin VB.CommandButton Command4
  198.       Caption         =   "Gem resultat"
  199.       Height          =   375
  200.       Left            =   3480
  201.       TabIndex        =   1
  202.       Top             =   2280
  203.       Width           =   1095
  204.    End
  205.    Begin VB.CommandButton Command2
  206.       Caption         =   "E&xit"
  207.       Height          =   375
  208.       Left            =   5040
  209.       TabIndex        =   0
  210.       Top             =   3720
  211.       Width           =   855
  212.    End
  213.    Begin VB.Frame Frame1
  214.       Caption         =   "Spil"
  215.       Height          =   1815
  216.       Left            =   240
  217.       TabIndex        =   12
  218.       Top             =   1200
  219.       Width           =   3015
  220.       Begin VB.CommandButton Command1
  221.          Caption         =   "Ny Tal (PC)"
  222.          Height          =   255
  223.          Left            =   1320
  224.          TabIndex        =   16
  225.          Top             =   240
  226.          Width           =   1095
  227.       End
  228.       Begin VB.CommandButton Command3
  229.          Caption         =   "Passer tallet"
  230.          Enabled         =   0   'False
  231.         Height          =   255
  232.          Left            =   480
  233.          TabIndex        =   15
  234.          Top             =   600
  235.          Width           =   1935
  236.       End
  237.       Begin VB.TextBox Text2
  238.          Enabled         =   0   'False
  239.         Height          =   285
  240.          IMEMode         =   3  'DISABLE
  241.         Left            =   480
  242.          MaxLength       =   3
  243.          TabIndex        =   14
  244.          Text            =   "1"
  245.          Top             =   240
  246.          Width           =   735
  247.       End
  248.       Begin VB.HScrollBar HScroll1
  249.          Enabled         =   0   'False
  250.         Height          =   255
  251.          Left            =   480
  252.          Max             =   100
  253.          Min             =   1
  254.          TabIndex        =   13
  255.          Top             =   960
  256.          Value           =   1
  257.          Width           =   1935
  258.       End
  259.       Begin VB.Label Label3
  260.          Alignment       =   2  'Center
  261.         BorderStyle     =   1  'Fixed Single
  262.         Caption         =   "Tillykke Player1, du gættede rigtigt"
  263.          Height          =   375
  264.          Left            =   120
  265.          TabIndex        =   17
  266.          Top             =   1320
  267.          Width           =   2775
  268.       End
  269.    End
  270.    Begin VB.Label Label8
  271.       Caption         =   "Intast dit navn:"
  272.       Height          =   255
  273.       Left            =   240
  274.       TabIndex        =   10
  275.       Top             =   480
  276.       Width           =   1095
  277.    End
  278.    Begin VB.Image Image1
  279.       Height          =   900
  280.       Left            =   3360
  281.       Picture         =   "Form1.frx":0000
  282.       Top             =   2760
  283.       Visible         =   0   'False
  284.      Width           =   960
  285.    End
  286.    Begin VB.Label Label9
  287.       Caption         =   "Filenavn:"
  288.       Height          =   255
  289.       Left            =   3480
  290.       TabIndex        =   11
  291.       Top             =   1680
  292.       Width           =   735
  293.    End
  294.    Begin VB.Label Label7
  295.       Caption         =   "##"
  296.       Height          =   255
  297.       Left            =   5400
  298.       TabIndex        =   9
  299.       Top             =   3000
  300.       Width           =   375
  301.    End
  302.    Begin VB.Label Label6
  303.       Caption         =   "##"
  304.       Height          =   255
  305.       Left            =   4560
  306.       TabIndex        =   8
  307.       Top             =   3000
  308.       Width           =   375
  309.    End
  310.    Begin VB.Label Label2
  311.       Caption         =   "Gæt et tal mellem 1 og 100"
  312.       BeginProperty Font
  313.          Name            =   "MS Sans Serif"
  314.          Size            =   8.25
  315.          Charset         =   0
  316.          Weight          =   700
  317.          Underline       =   0   'False
  318.         Italic          =   0   'False
  319.         Strikethrough   =   0   'False
  320.      EndProperty
  321.       Height          =   255
  322.       Left            =   1680
  323.       TabIndex        =   7
  324.       Top             =   120
  325.       Width           =   2415
  326.    End
  327.    Begin VB.Label Label1
  328.       Caption         =   "Label1"
  329.       Height          =   255
  330.       Left            =   4320
  331.       TabIndex        =   6
  332.       Top             =   3840
  333.       Width           =   855
  334.    End
  335.    Begin VB.Shape Shape2
  336.       BackColor       =   &H000040C0&
  337.       BackStyle       =   1  'Opaque
  338.      BorderStyle     =   6  'Inside Solid
  339.      FillColor       =   &H0000FFFF&
  340.       Height          =   855
  341.       Left            =   5280
  342.       Shape           =   2  'Oval
  343.      Top             =   2760
  344.       Width           =   615
  345.    End
  346.    Begin VB.Shape Shape1
  347.       BackColor       =   &H000000C0&
  348.       BackStyle       =   1  'Opaque
  349.      FillStyle       =   7  'Diagonal Cross
  350.      Height          =   855
  351.       Left            =   4440
  352.       Top             =   2760
  353.       Width           =   615
  354.    End
  355. End
  356. Attribute VB_Name = "Form1"
  357. Attribute VB_GlobalNameSpace = False
  358. Attribute VB_Creatable = False
  359. Attribute VB_PredeclaredId = True
  360. Attribute VB_Exposed = False
  361. Public number As Integer
  362. Public guesstotal As Integer
  363. Public totalgame As Integer
  364. Dim guessnumber As Integer
  365. Dim guess As Integer
  366. Dim pcnumber As Integer
  367.  
  368. Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias _
  369. "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As _
  370. Long) As Long
  371. Const SND_SYNC = &H0
  372. Const SND_ASYNC = &H1
  373. Const SND_NODEFAULT = &H2
  374. Const SND_LOOP = &H8
  375. Const SND_NOSTOP = &H10
  376.  
  377. Private Sub Check1_Click()
  378. If Check1.Value = 1 Then
  379.     Check1.Visible = False
  380.     Label12.Visible = True
  381.     Text3.Visible = True
  382.     Command6.Visible = True
  383.     Command6.Enabled = True
  384.     Text3.SetFocus
  385.     Else
  386.     Text1.Visible = False
  387.     Command6.Visible = False
  388.     End If
  389. End Sub
  390.  
  391. Private Sub Command1_Click()
  392. Randomize Timer
  393. pcnumber = Int(Rnd * 100) + 1
  394. Text1.Text = pcnumber
  395.  
  396. Command1.Enabled = False
  397. Command3.Enabled = True
  398. HScroll1.Enabled = True
  399. Text2.Enabled = True
  400.  
  401. Text2.Text = "1"
  402. HScroll1.Value = 1
  403. Label3.Caption = ""
  404. totalgame = totalgame + 1
  405. Label10.Caption = totalgame
  406. guess = 0
  407. Label11.Caption = 0
  408. Image1.Visible = False
  409. End Sub
  410.  
  411. Private Sub Command2_Click()
  412. Dim choice As Integer
  413. 'Exit promt
  414. choice = MsgBox("Exit?", vbOKCancel + vbExclamation, "Gæt et tal mellem 1 og 100")
  415. If choice = vbOK Then
  416.     choice = MsgBox("Er du sikker på du vil afslutte programmet?", vbYesNo + vbInformation, "Gæt et tal mellem 1 og 100")
  417.     If choice = vbNo Then
  418.     GoTo 200
  419.     Else
  420.     End
  421.     End If
  422.     Else
  423.     End If
  424. 200
  425. End Sub
  426.  
  427. Private Sub Command3_Click()
  428. guessnumber = Val(Text2.Text)
  429. 'If no number is present
  430. If guessnumber = 0 Or guesstotal > 100 Then
  431.     MsgBox "Du skal indtaste et tal mellem 1 og 100"
  432.     'Text2.Text = ""
  433.    Else
  434.     'if a guess number is present check to see if to high, more then +5
  435.    If guessnumber > pcnumber + 5 Then
  436.     Label3.Caption = "Du gættede alt for højt"
  437.     Else
  438.     'guess number is close
  439.    If guessnumber > pcnumber Then
  440.     Label3.Caption = "Nu er du tæt på, men stadig for højt"
  441.     End If
  442.     End If
  443.    
  444. If guessnumber = pcnumber Then
  445.    SoundName$ = "C:\WINDOWS\Media\tada.wav" 'Win XP/7
  446.   wFlags% = SND_ASYNC Or SND_NODEFAULT
  447.    X% = sndPlaySound(SoundName$, wFlags%)
  448.     Label3.Caption = "Tillykke " + Text4.Text + ", du gættede rigtigt"
  449.     Command1.Enabled = True
  450.     Command3.Enabled = False
  451.     Image1.Visible = True
  452.     Text2.Enabled = False
  453.     End If
  454.    
  455. If guessnumber < pcnumber - 5 Then
  456.     Label3.Caption = "de gættede for lavt"
  457.     Else
  458.     If guessnumber < pcnumber Then
  459.     Label3.Caption = "Nu er du tæt på, men stadig for lavt"
  460.     End If
  461.     End If
  462.    
  463.     guess = guess + 1
  464.     guesstotal = guesstotal + 1
  465.     Label11.Caption = guess
  466.     End If
  467. End Sub
  468.  
  469. Private Sub Command4_Click()
  470. 'Set flags
  471. CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
  472. 'Set filters
  473. CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|"
  474. 'Display the Save dialog box
  475. CommonDialog1.FileName = "Game.txt"
  476. CommonDialog1.ShowSave
  477. Open CommonDialog1.FileName For Output As #1
  478. Write #1, Text4.Text; "Antal gæt i alt"; guesstotal; "Antal Spil"; Label10.Caption
  479. 'Text4.Text; ": "; "Antal gæt i alt"; " "; guesstotal; " "; "Antal Spil"; " "; Label10.Caption
  480. Close
  481. 'Set the label values
  482. Text5.Text = CommonDialog1.FileName
  483. 'Open Text5.Text For Output As #1
  484. 'Print #1, Text4.Text; ": "; "Antal gæt i alt"; " "; guesstotal; " "; "Antal Spil"; " "; Label10.Caption
  485. 'Print #1, guesstotal
  486. 'Print #1, totalgame
  487. 'Print #1, Text4.Text
  488. End Sub
  489.  
  490. Private Sub Command5_Click()
  491. Load Form2
  492. Form2.Show
  493. Form2.Label2.Caption = guesstotal
  494. Form2.Label4.Caption = totalgame
  495.  
  496. If Label10.Caption > 0 Then
  497.  Form2.Label7.Caption = guesstotal / totalgame
  498.  number = guesstotal / totalgame
  499.  End If
  500.  
  501. 'write on form2
  502. Select Case number
  503.  Case 0
  504.   Form2.Label8.Caption = "Du har ikke gættet tallet endnu"
  505.    Case 1 To 2
  506.     Form2.Label8.Caption = "Super, har du gættet passwordet?"
  507.      Case 3, 4
  508.       Form2.Label8.Caption = "Expert"
  509.        Case 5, 6
  510.         Form2.Label8.Caption = "okay, men det kunne være bedre"
  511.          Case Else
  512.           Form2.Label8.Caption = "Skidt, Prøv med halveringsmetoden"
  513.           End Select
  514. End Sub
  515.  
  516. Private Sub Command6_Click()
  517. If Text3.Text = "test" Then
  518.     Text1.Visible = True
  519.     Label12.Visible = False
  520.     Text3.Visible = False
  521.     Command6.Enabled = False
  522.     Check1.Visible = True
  523.     Else
  524.     Text1.Visible = False
  525.     Label12.Visible = False
  526.     Text3.Visible = False
  527.     Command6.Visible = False
  528.     Check1.Visible = True
  529.     Check1.Value = 0
  530.     End If
  531. End Sub
  532.  
  533. Private Sub Command7_Click()
  534. On Error GoTo errhandler
  535.     CommonDialog1.CancelError = False
  536.     ' Set flags
  537.    CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist
  538.     ' Set filters
  539.    CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*|"
  540.    
  541.     ' Display the Save dialog box
  542.    CommonDialog1.FileName = ""
  543.     CommonDialog1.ShowOpen
  544.     ' Set the label values
  545.    Text5.Text = CommonDialog1.FileName
  546.     Exit Sub
  547. errhandler:
  548.     Select Case Err
  549.     Case 32755 '  Dialog Cancelled
  550.        MsgBox "you cancelled the dialog box"
  551.     Case Else
  552.         MsgBox "Unexpected error. Err " & Err & " : " & Error
  553.     End Select
  554. 'Open Text5.Text For Input As #1
  555. 'Line Input #1, inputdata 'Read line of data (first line no need)
  556. 'Line Input #1, inputdata 'Total guess
  557. 'guesstotal = inputdata
  558. 'Line Input #1, inputdata 'read total game
  559. 'totalgame = inputdata
  560. 'Line Input #1, inputdata 'read name of player
  561. 'Text4.Text = inputdata
  562. 'Label10.Caption = totalgame
  563. 'Label11.Caption = guesstotal
  564. End Sub
  565.  
  566. Private Sub Form_Load()
  567. Label3.Caption = ""
  568. End Sub
  569.  
  570. Private Sub HScroll1_scroll()
  571. Text2.Text = HScroll1.Value
  572. End Sub
  573.  
  574. Private Sub HScroll1_Change()
  575. Text2.Text = HScroll1.Value
  576. End Sub
  577.  
  578. Private Sub Image1_Click()
  579.    SoundName$ = "C:\WINDOWS\Media\tada.wav" 'Win XP/7
  580.   wFlags% = SND_ASYNC Or SND_NODEFAULT
  581.    X% = sndPlaySound(SoundName$, wFlags%)
  582. End Sub
  583.  
  584. Private Sub Text2_KeyPress(KeyAscii As Integer)
  585. If KeyAscii = vbKeyReturn Then
  586.  Call Command3_Click
  587.  End If
  588. End Sub
  589.  
  590. Private Sub Text2_Change()
  591. 'HScroll1.Value = Text2.Text
  592. If Text2.Text = 0 Or Text2.Text > 100 Then
  593.     MsgBox "Du skal indtaste et tal mellem 1 og 100"
  594.     End If
  595. End Sub
  596.  
  597. Private Sub Timer1_Timer()
  598. Label6.Visible = False
  599. Label7.Visible = True
  600. Label7.Caption = Int(Rnd * 100)
  601. Shape1.Visible = False
  602. Shape2.Visible = True
  603. Timer1.Enabled = False
  604. Timer2.Enabled = True
  605. End Sub
  606.  
  607. Private Sub Timer2_Timer()
  608. Label7.Visible = False
  609. Label6.Visible = True
  610. Label6.Caption = Int(Rnd * 100)
  611. Shape2.Visible = False
  612. Shape1.Visible = True
  613. Timer2.Enabled = False
  614. Timer1.Enabled = True
  615. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement