Advertisement
Prithak

QB64 Somethin' Somethin'

Nov 7th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. Screen _newimage(_desktopwidth, _desktopheight, 32)
  2. Color _rgb32(0,0,0)
  3. Color , _rgb32(255,255,255)
  4. Resx = _desktopwidth
  5. Resy = _desktopheight
  6. _fullscreen
  7. Main:
  8. Do
  9. While _mouseinput
  10. If mouseclick(Resx/2-100,Resy/2-100,Resx/2+100,Resy/2+100) then
  11. Goto game
  12. Elseif mouseclick(Resx/2-100,Resy/2-200,Resx/2+100,Resy/2+200) then
  13. Goto addcard
  14. End if
  15. Wend
  16. Line (Resx/2-100,Resy/2-100)-(Resx/2+100,Resy/2+100),_rgb32(100,200,255),B
  17. _printstring(Resx/2-100,Resy/2-50),"Play"
  18. Line (Resx/2-100,Resy/2-200)-(Resx/2+100,Resy/2+200),_rgb32(100,200,255),B
  19. _printstring(Resx/2-100,Resy/2-150),"Add a Card to your collection!"
  20. _display
  21. Cls
  22. Loop
  23.  
  24. Addcard:
  25. Cls
  26. If download("","cards.txt",20) then
  27. Print "Success in Downloading FIle!"
  28. Open "cards.txt" for input as #1
  29. Input "Enter the code no. For your card....";code$
  30. Do while not eof(1)
  31. Input #1, line$
  32. If code$ = line$ then
  33. Input #1, card$
  34. Input #1, loc$
  35. Print "You have chosen the ";card$;" card!!!"
  36. Print "Please wait till we find out where it's data is lying around..."
  37. Open "mycard.txt" for append as #2
  38. Print #2, card$
  39. Print #2, loc$
  40. Close #2
  41. End if
  42. Loop
  43. Close #1
  44. Else
  45. Print "Failed in Downloading The File...."
  46. Print "Please try again later...."
  47. Sleep
  48. Goto main
  49. Endif
  50. System
  51. Game:
  52.  
  53.  
  54. Function mouseclick(x1,y1,x2,y2)
  55. Mx = _mousex
  56. My = _mousey
  57. Mb = _mousebutton(1)
  58.  
  59. If mx >= x1 and mx <= x2 and my >= y1 and my <= y2 and mb then
  60. Mouseclick = -1
  61. End if
  62. End function
  63.  
  64.  
  65. FUNCTION Download (url$, file$, timelimit) ' returns -1 if successful, 0 if not
  66. url2$ = url$
  67. x = INSTR(url2$, "/")
  68. IF x THEN url2$ = LEFT$(url$, x - 1)
  69. client = _OPENCLIENT("TCP/IP:80:" + url2$)
  70. IF client = 0 THEN EXIT FUNCTION
  71. e$ = CHR$(13) + CHR$(10) ' end of line characters
  72. url3$ = RIGHT$(url$, LEN(url$) - x + 1)
  73. x$ = "GET " + url3$ + " HTTP/1.1" + e$
  74. x$ = x$ + "Host: " + url2$ + e$ + e$
  75. PUT #client, , x$
  76. t! = TIMER ' start time
  77. DO
  78. _DELAY 0.05 ' 50ms delay (20 checks per second)
  79. GET #client, , a2$
  80. a$ = a$ + a2$
  81. i = INSTR(a$, "Content-Length:")
  82. IF i THEN
  83. i2 = INSTR(i, a$, e$)
  84. IF i2 THEN
  85. l = VAL(MID$(a$, i + 15, i2 - i -14))
  86. i3 = INSTR(i2, a$, e$ + e$)
  87. IF i3 THEN
  88. i3 = i3 + 4 'move i3 to start of data
  89. IF (LEN(a$) - i3 + 1) = l THEN
  90. CLOSE client ' CLOSE CLIENT
  91. d$ = MID$(a$, i3, l)
  92. fh = FREEFILE
  93. OPEN file$ FOR OUTPUT AS #fh: CLOSE #fh 'Warning! Clears data from existing file
  94. OPEN file$ FOR BINARY AS #fh
  95. PUT #fh, , d$
  96. CLOSE #fh
  97. Download = -1 'indicates download was successfull
  98. EXIT FUNCTION
  99. END IF ' availabledata = l
  100. END IF ' i3
  101. END IF ' i2
  102. END IF ' i
  103. LOOP UNTIL TIMER > t! + timelimit ' (in seconds)
  104. CLOSE client
  105. END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement