home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxdemo.zip / MINDGAME.$$$ / WINDOW1.VRX < prev    next >
Text File  |  1993-06-18  |  11KB  |  513 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         aboutMenuItem_Click
  67. */
  68. aboutMenuItem_Click:
  69.     call window2 VRWindow()
  70. return
  71.  
  72. /*:VRX         Fini
  73. */
  74. Fini:
  75.     window = VRWindow()
  76.     call VRSet window, "Visible", 0
  77.     drop window
  78. return 0
  79. /*:VRX         game_button
  80. */
  81. game_button:
  82.  
  83.     row = arg( 1 )
  84.     col = arg( 2 )
  85.  
  86.     if( row < current_row ) then do
  87.         tmp_color = VRGet( 'r' || row || 'c' || col, 'backcolor' )
  88.         call VRSet 'r' || current_row || 'c' || col, 'backcolor', tmp_color
  89.       end
  90.     else do
  91.         call VRSet 'r' || row || 'c' || col, 'backcolor', color.current
  92.       end
  93.  
  94.     /* Turn on the current column */
  95.     button.col = 1
  96.     guess_on = 1
  97.     do i = 1 to 4 by 1
  98.         if( button.i = 0 ) then guess_on = 0
  99.     end
  100.     if( guess_on = 1 ) then call VRSet 'pb_guess', 'enabled', 'true'
  101.  
  102. return
  103. /*:VRX         Halt
  104. */
  105. Halt:
  106.     signal _VREHalt
  107. return
  108.  
  109. /*:VRX         Init
  110. */
  111. Init:
  112.     color.1 = 'BLUE'
  113.     color.2 = 'RED'
  114.     color.3 = 'GREEN'
  115.     color.4 = 'PINK'
  116.     color.5 = 'CYAN'
  117.     color.6 = 'YELLOW'
  118.     color.current = color.1
  119.  
  120.     current_row = 1
  121.  
  122.     call VRSet "pb_current_color", "BackColor", color.current
  123.     call newMenuItem_Click
  124.  
  125.     window = VRWindow()
  126.     call VRMethod window, "CenterWindow"
  127.     call VRSet window, "Visible", 1
  128.     call VRMethod window, "Activate"
  129.     drop window
  130. return
  131.  
  132. /*:VRX         newMenuItem_Click
  133. */
  134. newMenuItem_Click:
  135.     /*
  136.      * Reset the game board.
  137.      */
  138.     call VRSet 'pb_peek', 'enabled', 'false'
  139.     call VRSet 'pb_guess', 'enabled', 'false'
  140.     call VRSet 'pb_new', 'enabled', 'false'
  141.  
  142.     do x = current_row to 2 by -1
  143.         call VRSet 'dt' || x, 'caption', ''
  144.         do y = 4 to 1 by -1
  145.             call VRSet 'r' || x || 'c' || y, 'visible', 'false'
  146.             call VRSet 'r' || x || 'c' || y, 'backcolor', '<default>'
  147.         end
  148.     end
  149.  
  150.  
  151.     do y = 1 to 4 by 1
  152.         call VRSet 'r1c' || y, 'backcolor', '<default>'
  153.         call VRSet 'r0c' || y, 'backcolor', '<default>'
  154.         button.y = 0
  155.     end
  156.  
  157.     /* Set current row */
  158.     current_row = 1
  159.  
  160.     /* Set the game solution */
  161.     do i = 1 to 4 by 1
  162.         j = RANDOM( 1, 6 )
  163.         sol.i = color.j
  164.     end
  165.  
  166.     /* Make the pointer */
  167.     arrow = "<==="
  168.     call VRSet 'dt1', 'caption', arrow
  169.  
  170. /*    call VRSet 'pb_guess', 'enabled', 'true' */
  171.     call VRSet 'pb_peek', 'enabled', 'true'
  172.     call VRSet 'pb_new', 'enabled', 'true'
  173.  
  174. return
  175.  
  176. /*:VRX         pb_color1_Click
  177. */
  178. pb_color1_Click:
  179.     color.current = color.1
  180.     call VRSet 'pb_current_color', 'backcolor', color.current
  181. return
  182. /*:VRX         pb_color2_Click
  183. */
  184. pb_color2_Click:
  185.     color.current = color.2
  186.     call VRSet 'pb_current_color', 'backcolor', color.current
  187. return
  188. /*:VRX         pb_color3_Click
  189. */
  190. pb_color3_Click:
  191.     color.current = color.3
  192.     call VRSet 'pb_current_color', 'backcolor', color.current
  193. return
  194. /*:VRX         pb_color4_Click
  195. */
  196. pb_color4_Click:
  197.     color.current = color.4
  198.     call VRSet 'pb_current_color', 'backcolor', color.current
  199. return
  200. /*:VRX         pb_color5_Click
  201. */
  202. pb_color5_Click:
  203.     color.current = color.5
  204.     call VRSet 'pb_current_color', 'backcolor', color.current
  205. return
  206. /*:VRX         pb_color6_Click
  207. */
  208. pb_color6_Click:
  209.     color.current = color.6
  210.     call VRSet 'pb_current_color', 'backcolor', color.current
  211. return
  212. /*:VRX         pb_guess_Click
  213. */
  214. pb_guess_Click:
  215.  
  216.     correct = 0
  217.     almost_correct = 0
  218.  
  219.     call VRSet 'pb_guess', 'enabled', 'false'
  220.  
  221.     /* Reintialize the sol_count and guess_count arrays */
  222.     do i = 1 to 6 by 1
  223.         sol_count.i = 0
  224.         guess_count.i = 0
  225.     end
  226.  
  227.     /* Find the number of correct matches */
  228.     do i = 1 to 4 by 1
  229.         button.i = 0
  230.         guess = VRGet( 'r' || current_row || 'c' || i, 'backcolor' )
  231.         guess = Translate( guess )
  232.         if( guess = sol.i )then correct = correct + 1
  233.         do j = 1 to 6 by 1
  234.             if( guess = color.j ) then guess_count.j = guess_count.j + 1
  235.             if( sol.i = color.j ) then sol_count.j = sol_count.j + 1
  236.         end
  237.     end
  238.  
  239.     /* Find number of almost correct guesses */
  240.     do i = 1 to 6 by 1
  241.         if( guess_count.i < sol_count.i ) then
  242.             almost_correct = almost_correct + guess_count.i
  243.         else
  244.             almost_correct = almost_correct + sol_count.i
  245.     end
  246.     almost_correct = almost_correct - correct
  247.  
  248.     /* Make answer guess string */
  249.     guess_string = ""
  250.     if( correct > 0 ) then
  251.         do i = 1 to correct by 1
  252.             guess_string = guess_string || "X"
  253.         end
  254.     if( almost_correct > 0 ) then
  255.         do i = 1 to almost_correct by 1
  256.             guess_string = guess_string || "O"
  257.         end
  258.     call VRSet 'dt' || current_row, 'caption', guess_string
  259.  
  260.     /* Update current row */
  261.     current_row = current_row + 1
  262.  
  263.     /* Check for a winner */
  264.     if( guess_string = "XXXX" ) then do
  265.         call Show_solution
  266.         call VRMessage VRWindow(), 'Congratulations! You guessed the right combination in' current_row - 1 'turns.', 'YOU WIN!', 'information'
  267.       end
  268.  
  269.     /* Check for end of game */
  270.     else if( current_row > 10 ) then do
  271.         call Show_solution
  272.         call VRMessage VRWindow(), 'Sorry, but you have run out of turns.', 'You Lose.', 'information'
  273.       end
  274.  
  275.     /* Continue game with a new guess */
  276.     else do
  277.         do i = 1 to 4
  278.             call VRSet 'r' || current_row || 'c' || i, 'visible', 'true'
  279.         end
  280.         call VRSet 'dt' || current_row, 'caption', arrow
  281.       end
  282.  
  283. return
  284. /*:VRX         peekMenuItem_Click
  285. */
  286. peekMenuItem_Click:
  287.     call Show_solution
  288.     call VRMessage VRWindow(), 'Sorry, the game cannot continue since you peeked at the solution.',,
  289.                     'You Peeked!', 'Information'
  290. return
  291.  
  292. /*:VRX         Quit
  293. */
  294. Quit:
  295.     window = VRWindow()
  296.     call VRSet window, "Shutdown", 1
  297.     drop window
  298. return
  299. /*:VRX         r10c1_Click
  300. */
  301. r10c1_Click:
  302.     call game_button 10, 1
  303. return
  304. /*:VRX         r10c2_Click
  305. */
  306. r10c2_Click:
  307.     call game_button 10, 2
  308. return
  309. /*:VRX         r10c3_Click
  310. */
  311. r10c3_Click:
  312.     call game_button 10, 3
  313. return
  314. /*:VRX         r10c4_Click
  315. */
  316. r10c4_Click:
  317.     call game_button 10, 4
  318. return
  319. /*:VRX         r1c1_Click
  320. */
  321. r1c1_Click:
  322.     call game_button 1, 1
  323. return
  324. /*:VRX         r1c2_Click
  325. */
  326. r1c2_Click:
  327.     call game_button 1, 2
  328. return
  329. /*:VRX         r1c3_Click
  330. */
  331. r1c3_Click:
  332.     call game_button 1, 3
  333. return
  334. /*:VRX         r1c4_Click
  335. */
  336. r1c4_Click:
  337.     call game_button 1, 4
  338. return
  339. /*:VRX         r2c1_Click
  340. */
  341. r2c1_Click:
  342.     call game_button 2, 1
  343. return
  344. /*:VRX         r2c2_Click
  345. */
  346. r2c2_Click:
  347.     call game_button 2, 2
  348. return
  349. /*:VRX         r2c3_Click
  350. */
  351. r2c3_Click:
  352.     call game_button 2, 3
  353. return
  354. /*:VRX         r2c4_Click
  355. */
  356. r2c4_Click:
  357.     call game_button 2, 4
  358. return
  359. /*:VRX         r3c1_Click
  360. */
  361. r3c1_Click:
  362.     call game_button 3, 1
  363. return
  364. /*:VRX         r3c2_Click
  365. */
  366. r3c2_Click:
  367.     call game_button 3, 2
  368. return
  369. /*:VRX         r3c3_Click
  370. */
  371. r3c3_Click:
  372.     call game_button 3, 3
  373. return
  374. /*:VRX         r3c4_Click
  375. */
  376. r3c4_Click:
  377.     call game_button 3, 4
  378. return
  379. /*:VRX         r4c1_Click
  380. */
  381. r4c1_Click:
  382.     call game_button 4, 1
  383. return
  384. /*:VRX         r4c2_Click
  385. */
  386. r4c2_Click:
  387.     call game_button 4, 2
  388. return
  389. /*:VRX         r4c3_Click
  390. */
  391. r4c3_Click:
  392.     call game_button 4, 3
  393. return
  394. /*:VRX         r4c4_Click
  395. */
  396. r4c4_Click:
  397.     call game_button 4, 4
  398. return
  399. /*:VRX         r5c1_Click
  400. */
  401. r5c1_Click:
  402.     call game_button 5, 1
  403. return
  404. /*:VRX         r5c2_Click
  405. */
  406. r5c2_Click:
  407.     call game_button 5, 2
  408. return
  409. /*:VRX         r5c3_Click
  410. */
  411. r5c3_Click:
  412.     call game_button 5, 3
  413. return
  414. /*:VRX         r5c4_Click
  415. */
  416. r5c4_Click:
  417.     call game_button 5, 4
  418. return
  419. /*:VRX         r6c1_Click
  420. */
  421. r6c1_Click:
  422.     call game_button 6, 1
  423. return
  424. /*:VRX         r6c2_Click
  425. */
  426. r6c2_Click:
  427.     call game_button 6, 2
  428. return
  429. /*:VRX         r6c3_Click
  430. */
  431. r6c3_Click:
  432.     call game_button 6, 3
  433. return
  434. /*:VRX         r6c4_Click
  435. */
  436. r6c4_Click:
  437.     call game_button 6, 4
  438. return
  439. /*:VRX         r7c1_Click
  440. */
  441. r7c1_Click:
  442.     call game_button 7, 1
  443. return
  444. /*:VRX         r7c2_Click
  445. */
  446. r7c2_Click:
  447.     call game_button 7, 2
  448. return
  449. /*:VRX         r7c3_Click
  450. */
  451. r7c3_Click:
  452.     call game_button 7, 3
  453. return
  454. /*:VRX         r7c4_Click
  455. */
  456. r7c4_Click:
  457.     call game_button 7, 4
  458. return
  459. /*:VRX         r8c1_Click
  460. */
  461. r8c1_Click:
  462.     call game_button 8, 1
  463. return
  464. /*:VRX         r8c2_Click
  465. */
  466. r8c2_Click:
  467.     call game_button 8, 2
  468. return
  469. /*:VRX         r8c3_Click
  470. */
  471. r8c3_Click:
  472.     call game_button 8, 3
  473. return
  474. /*:VRX         r8c4_Click
  475. */
  476. r8c4_Click:
  477.     call game_button 8, 4
  478. return
  479. /*:VRX         r9c1_Click
  480. */
  481. r9c1_Click:
  482.     call game_button 9, 1
  483. return
  484. /*:VRX         r9c2_Click
  485. */
  486. r9c2_Click:
  487.     call game_button 9, 2
  488. return
  489. /*:VRX         r9c3_Click
  490. */
  491. r9c3_Click:
  492.     call game_button 9, 3
  493. return
  494. /*:VRX         r9c4_Click
  495. */
  496. r9c4_Click:
  497.     call game_button 9, 4
  498. return
  499. /*:VRX         Show_solution
  500. */
  501. Show_solution:
  502.     call VRSet 'pb_guess', 'Enabled', '0'
  503.     call VRSet 'pb_peek', 'Enabled', '0'
  504.     do i = 1 to 4 by 1
  505.         call VRSet 'r0c' || i, 'Backcolor', sol.i
  506.     end
  507. return
  508. /*:VRX         Window1_Close
  509. */
  510. Window1_Close:
  511.     call Quit
  512. return
  513.