Author Topic: Rock Paper Scissors (Lizard Spock) Game by TempodiBasic  (Read 7668 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Rock Paper Scissors (Lizard Spock) Game by TempodiBasic
« on: May 01, 2020, 05:09:04 am »
[Inform] Rock Paper Scissors (Lizard Spock) Game

Author: @TempodiBasic - Developed on the suggestion of Pete & Bplus
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=682.0
Version: 2
Tags: [InForm], [Game of Chance]

Description:
The Inform version of Rock Paper Scissor (Lizard Spock variant). Building it in Inform has been interesting to re-think some ideas under the light of event-driven coding.

Source Code:
Code given here for reference.  You will need all the files in the zip/rar.
Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 7
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - [member=2]FellippeHeitor[/member]
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. REM NOTICE: THIS FORM HAS BEEN RECENTLY EDITED
  9. '>> The controls in the list below may have been added or renamed,
  10. '>> and previously existing controls may have been deleted since
  11. '>> this program's structure was first generated.
  12. '>> Make sure to check your code in the events SUBs so that
  13. '>> you can take your recent edits into consideration.
  14. ': ---------------------------------------------------------------------------------
  15.  
  16. CONST paper = 1, rock = 2, scissor = 3, spok = 4, lizard = 5, draws = 2, looses = 3, wins = 1
  17. DIM SHARED PlayerChoose AS INTEGER ' flag for user choice
  18. DIM SHARED RockHandScissor AS LONG
  19. DIM SHARED Frame1 AS LONG
  20. DIM SHARED Frame2 AS LONG
  21. DIM SHARED ScoreLB AS LONG
  22. DIM SHARED StartBT AS LONG
  23. DIM SHARED ExitBT AS LONG
  24. DIM SHARED HelpBT AS LONG
  25. DIM SHARED ROCKPAPERSCISSORGAMELB AS LONG
  26. DIM SHARED ChooseYourMoveAndWaitAIsOneLB AS LONG
  27. DIM SHARED assetscartajpegPX AS LONG
  28. DIM SHARED assetssassojpegPX AS LONG
  29. DIM SHARED assetsforbicepngPX AS LONG
  30. DIM SHARED assetsRPSLS_helpjpgPX AS LONG
  31. DIM SHARED assetsspokpngPX AS LONG
  32. DIM SHARED assetslizardpngPX AS LONG
  33.  
  34.  
  35. '$INCLUDE:'InForm\InForm.ui'
  36. '$INCLUDE:'InForm\xp.uitheme'
  37. '$INCLUDE:'RockHandScissor.frm'
  38.  
  39. ': Event procedures: ---------------------------------------------------------------
  40. SUB __UI_BeforeInit
  41.  
  42.  
  43. SUB __UI_OnLoad
  44.     Caption(LB) = "0000"
  45.     PlayerChoose = 0
  46.     Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = True ' hide help label
  47.     Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = True
  48.     Control(Frame2).Hidden = True ' hide frame2
  49.     Control(Frame2).Disabled = True
  50.  
  51. SUB __UI_BeforeUpdateDisplay
  52.     'This event occurs at approximately 30 frames per second.
  53.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  54.  
  55.  
  56.     IF PlayerChoose = 20 THEN ' wait 2 sec
  57.         in! = TIMER
  58.         DO WHILE TIMER - in! < 2
  59.         LOOP
  60.         restoreGame
  61.     END IF
  62.     IF PlayerChoose THEN PlayerChoose = PlayerChoose + 1 ' here we pass one time(20 frames) into sub_Display before to reset the game
  63.  
  64. SUB __UI_BeforeUnload
  65.     'If you set __UI_UnloadSignal = False here you can
  66.     'cancel the user's request to close.
  67.  
  68.  
  69. SUB __UI_Click (id AS LONG)
  70.     SELECT CASE id
  71.         CASE assetscartajpegPX
  72.             ' user chooses to play paper
  73.             Control(assetssassojpegPX).Disabled = True ' hide images of rock and scissor
  74.             Control(assetsforbicepngPX).Disabled = True
  75.             Control(assetsspokpngPX).Disabled = True
  76.             Control(assetslizardpngPX).Disabled = True
  77.             Control(assetssassojpegPX).Hidden = True
  78.             Control(assetsforbicepngPX).Hidden = True
  79.             Control(assetsspokpngPX).Hidden = True
  80.             Control(assetslizardpngPX).Hidden = True
  81.             Control(assetsRPSLS_helpjpgPX).Disabled = True ' hide AI's choice
  82.             Control(assetsRPSLS_helpjpgPX).Hidden = True
  83.             playAI paper
  84.         CASE assetssassojpegPX
  85.             ' user chooses to play rock
  86.             Control(assetscartajpegPX).Disabled = True ' hide paper and scissor
  87.             Control(assetsforbicepngPX).Disabled = True
  88.             Control(assetsspokpngPX).Disabled = True
  89.             Control(assetslizardpngPX).Disabled = True
  90.             Control(assetsspokpngPX).Hidden = True
  91.             Control(assetslizardpngPX).Hidden = True
  92.             Control(assetscartajpegPX).Hidden = True
  93.             Control(assetsforbicepngPX).Hidden = True
  94.             Control(assetsRPSLS_helpjpgPX).Disabled = True ' hide AI's choice
  95.             Control(assetsRPSLS_helpjpgPX).Hidden = True
  96.             playAI rock
  97.         CASE assetsforbicepngPX
  98.             'user chooses to play scissor
  99.             Control(assetssassojpegPX).Disabled = True ' hide  rock and paper
  100.             Control(assetscartajpegPX).Disabled = True
  101.             Control(assetsspokpngPX).Disabled = True
  102.             Control(assetslizardpngPX).Disabled = True
  103.             Control(assetsspokpngPX).Hidden = True
  104.             Control(assetslizardpngPX).Hidden = True
  105.             Control(assetssassojpegPX).Hidden = True
  106.             Control(assetscartajpegPX).Hidden = True
  107.             Control(assetsRPSLS_helpjpgPX).Disabled = True ' hide AI's choice
  108.             Control(assetsRPSLS_helpjpgPX).Hidden = True
  109.             playAI scissor
  110.         CASE assetsspokpngPX
  111.             Control(assetssassojpegPX).Disabled = True ' hide  rock and paper
  112.             Control(assetscartajpegPX).Disabled = True
  113.             Control(assetsforbicepngPX).Disabled = True
  114.             Control(assetslizardpngPX).Disabled = True
  115.             Control(assetsforbicepngPX).Hidden = True
  116.             Control(assetslizardpngPX).Hidden = True
  117.             Control(assetssassojpegPX).Hidden = True
  118.             Control(assetscartajpegPX).Hidden = True
  119.             playAI spok
  120.         CASE assetslizardpngPX
  121.             Control(assetssassojpegPX).Disabled = True ' hide  rock and paper
  122.             Control(assetscartajpegPX).Disabled = True
  123.             Control(assetsspokpngPX).Disabled = True
  124.             Control(assetsforbicepngPX).Disabled = True
  125.             Control(assetsspokpngPX).Hidden = True
  126.             Control(assetsforbicepngPX).Hidden = True
  127.             Control(assetssassojpegPX).Hidden = True
  128.             Control(assetscartajpegPX).Hidden = True
  129.             playAI lizard
  130.         CASE RockHandScissor
  131.  
  132.         CASE ScoreLB
  133.  
  134.         CASE Frame1
  135.  
  136.         CASE StartBT
  137.             Control(HelpBT).Disabled = True
  138.             Control(Frame2).Hidden = False ' show frame2
  139.             Control(Frame2).Disabled = False
  140.             Control(assetssassojpegPX).Disabled = False ' show and activate 3 image buttons for user
  141.             Control(assetsforbicepngPX).Disabled = False
  142.             Control(assetscartajpegPX).Disabled = False
  143.             Control(assetsspokpngPX).Disabled = False
  144.             Control(assetslizardpngPX).Disabled = False
  145.             Control(assetssassojpegPX).Hidden = False
  146.             Control(assetsforbicepngPX).Hidden = False
  147.             Control(assetscartajpegPX).Hidden = False
  148.             Control(assetsspokpngPX).Hidden = False
  149.             Control(assetslizardpngPX).Hidden = False
  150.  
  151.             Control(assetsRPSLS_helpjpgPX).Hidden = True ' hide help/AI image
  152.             Control(assetsRPSLS_helpjpgPX).Disabled = True
  153.             Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = True ' hide help label
  154.             Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = True
  155.  
  156.         CASE ExitBT
  157.             SYSTEM ' exit from program
  158.         CASE HelpBT
  159.  
  160.             IF Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = False THEN
  161.                 ' here we reactivate the game
  162.                 Control(StartBT).Disabled = False
  163.                 Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = True ' hide help label
  164.                 Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = True
  165.                 Caption(ChooseYourMoveAndWaitAIsOneLB) = "Choose your move and wait AI's one"
  166.                 Control(Frame2).Hidden = True ' hide frame2
  167.                 Control(Frame2).Disabled = True
  168.                 Control(assetssassojpegPX).Disabled = False ' activate 5 image button for user
  169.                 Control(assetsforbicepngPX).Disabled = False
  170.                 Control(assetscartajpegPX).Disabled = False
  171.                 Control(assetsspokpngPX).Disabled = False
  172.                 Control(assetslizardpngPX).Disabled = False
  173.                 Control(assetssassojpegPX).Hidden = False
  174.                 Control(assetsforbicepngPX).Hidden = False
  175.                 Control(assetscartajpegPX).Hidden = False
  176.                 Control(assetsspokpngPX).Hidden = False
  177.                 Control(assetslizardpngPX).Hidden = False
  178.  
  179.             ELSE
  180.                 ' here we show the help
  181.                 Control(StartBT).Disabled = True 'disable help button
  182.                 Caption(ChooseYourMoveAndWaitAIsOneLB) = "Choose your move and wait AI's one"
  183.                 Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = False ' show help label
  184.                 Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = False
  185.                 Control(assetssassojpegPX).Disabled = True ' hide 5 image button for user
  186.                 Control(assetsforbicepngPX).Disabled = True
  187.                 Control(assetscartajpegPX).Disabled = True
  188.                 Control(assetsspokpngPX).Disabled = True
  189.                 Control(assetslizardpngPX).Disabled = True
  190.                 Control(assetssassojpegPX).Hidden = True
  191.                 Control(assetsforbicepngPX).Hidden = True
  192.                 Control(assetscartajpegPX).Hidden = True
  193.                 Control(assetsspokpngPX).Hidden = True
  194.                 Control(assetslizardpngPX).Hidden = True
  195.                 Control(Frame2).Hidden = False 'show frame2
  196.                 Control(Frame2).Disabled = False
  197.                 LoadImage Control(assetsRPSLS_helpjpgPX), "assets\RPSLS_help.jpg" ' load and show help picture
  198.                 Control(assetsRPSLS_helpjpgPX).Redraw = True
  199.             END IF
  200.         CASE LB
  201.  
  202.         CASE ROCKHANDSCISSORGAMELB
  203.  
  204.         CASE ChooseYourMoveAndWaitAIsOneLB
  205.  
  206.     END SELECT
  207.  
  208. SUB restoreGame
  209.     Control(assetssassojpegPX).Disabled = False 'activate 5 image buttons for user
  210.     Control(assetsforbicepngPX).Disabled = False
  211.     Control(assetscartajpegPX).Disabled = False
  212.     Control(assetsspokpngPX).Disabled = False
  213.     Control(assetslizardpngPX).Disabled = False
  214.     Control(assetsspokpngPX).Hidden = False
  215.     Control(assetslizardpngPX).Hidden = False
  216.     Control(assetssassojpegPX).Hidden = False
  217.     Control(assetsforbicepngPX).Hidden = False
  218.     Control(assetscartajpegPX).Hidden = False
  219.     Control(HelpBT).Disabled = False ' activate help button
  220.     Control(assetsRPSLS_helpjpgPX).Redraw = True ' force to show AI's choice
  221.     PlayerChoose = 0 ' reset the chooser game
  222.  
  223. SUB results (result AS INTEGER)
  224.     'here there is the output sound + images for user
  225.     ' and adjourn  score of game
  226.     Control(assetsRPSLS_helpjpgPX).Hidden = False ' show image of ai's choice
  227.     Control(assetsRPSLS_helpjpgPX).Disabled = False
  228.     Control(assetsRPSLS_helpjpgPX).Redraw = True ' force to show image of ai's choice
  229.     SELECT CASE result
  230.         CASE wins
  231.             Caption(LB) = STR$(VAL(Caption(LB)) + 10)
  232.             Caption(ChooseYourMoveAndWaitAIsOneLB) = " YOU WIN!! "
  233.         CASE draws
  234.             Caption(LB) = STR$(VAL(Caption(LB)) + 5)
  235.             Caption(ChooseYourMoveAndWaitAIsOneLB) = " YOU DRAW!! "
  236.         CASE looses
  237.             Caption(LB) = STR$(VAL(Caption(LB)) - 10)
  238.             Caption(ChooseYourMoveAndWaitAIsOneLB) = " YOU LOOSE!! "
  239.     END SELECT
  240.     Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = False 'show result as text in helplabel
  241.     Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = False
  242.  
  243. SUB playAI (choose AS INTEGER)
  244.     PlayerChoose = 1 ' the user has made his choice
  245.     DIM choosen AS INTEGER
  246.     choosen = INT(RND * 5) + 1 ' ai chooses
  247.     Control(ChooseYourMoveAndWaitAIsOneLB).Hidden = True ' hide help label
  248.     Control(ChooseYourMoveAndWaitAIsOneLB).Disabled = True
  249.     LoadImage Control(assetsRPSLS_helpjpgPX), "" ' reset to null image of ai's choice
  250.  
  251.     SELECT CASE choosen
  252.         CASE paper
  253.             ' AI chooses to play paper
  254.             LoadImage Control(assetsRPSLS_helpjpgPX), "assets\carta.jpg"
  255.             SELECT CASE choose
  256.                 CASE paper
  257.                     'draw
  258.                     results draws
  259.                 CASE rock
  260.                     ' failure
  261.                     results looses
  262.                 CASE scissor
  263.                     ' victory
  264.                     results wins
  265.                 CASE spok
  266.                     ' failure
  267.                     results looses
  268.                 CASE lizard
  269.                     ' victory
  270.                     results wins
  271.             END SELECT
  272.  
  273.         CASE rock
  274.             ' AI chooses to play rock
  275.             LoadImage Control(assetsRPSLS_helpjpgPX), "assets\sasso.jpg"
  276.             SELECT CASE choose
  277.                 CASE paper
  278.                     'victory
  279.                     results wins
  280.                 CASE rock
  281.                     ' draw
  282.                     results draws
  283.                 CASE scissor
  284.                     ' loose
  285.                     results looses
  286.                 CASE spok
  287.                     'victory
  288.                     results wins
  289.                 CASE lizard
  290.                     ' loose
  291.                     results looses
  292.             END SELECT
  293.  
  294.         CASE scissor
  295.             ' AI chooses to play scissor
  296.             LoadImage Control(assetsRPSLS_helpjpgPX), "assets\forbice.png"
  297.             SELECT CASE choose
  298.                 CASE paper
  299.                     'failure
  300.                     results looses
  301.                 CASE rock
  302.                     ' victory
  303.                     results wins
  304.                 CASE scissor
  305.                     ' draw
  306.                     results draws
  307.                 CASE spok
  308.                     ' victory
  309.                     results wins
  310.                 CASE lizard
  311.                     'failure
  312.                     results looses
  313.             END SELECT
  314.         CASE spok
  315.             ' AI chooses to play spok
  316.             LoadImage Control(assetsRPSLS_helpjpgPX), "assets\Spok.png"
  317.             SELECT CASE choose
  318.                 CASE paper
  319.                     ' victory
  320.                     results wins
  321.                 CASE rock
  322.                     'failure
  323.                     results looses
  324.                 CASE scissor
  325.                     'failure
  326.                     results looses
  327.                 CASE spok
  328.                     ' draw
  329.                     results draws
  330.                 CASE lizard
  331.                     ' victory
  332.                     results wins
  333.             END SELECT
  334.         CASE lizard
  335.             'AI chooses to play lizard
  336.             LoadImage Control(assetsRPSLS_helpjpgPX), "assets\lizard.png"
  337.             SELECT CASE choose
  338.                 CASE paper
  339.                     'failure
  340.                     results looses
  341.                 CASE rock
  342.                     ' victory
  343.                     results wins
  344.                 CASE scissor
  345.                     ' victory
  346.                     results wins
  347.                 CASE spok
  348.                     'failure
  349.                     results looses
  350.                 CASE lizard
  351.                     ' draw
  352.                     results draws
  353.             END SELECT
  354.     END SELECT
  355.  
  356.  
  357. SUB __UI_MouseEnter (id AS LONG)
  358.     SELECT CASE id
  359.         CASE RockHandScissor
  360.  
  361.         CASE ScoreLB
  362.  
  363.         CASE Frame1
  364.  
  365.         CASE StartBT
  366.  
  367.         CASE ExitBT
  368.  
  369.         CASE HelpBT
  370.  
  371.         CASE ScoreNLB
  372.  
  373.         CASE ROCKHANDSCISSORGAMELB
  374.  
  375.  
  376.  
  377.     END SELECT
  378.  
  379. SUB __UI_MouseLeave (id AS LONG)
  380.     SELECT CASE id
  381.         CASE RockHandScissor
  382.  
  383.         CASE ScoreLB
  384.  
  385.         CASE Frame1
  386.  
  387.         CASE StartBT
  388.  
  389.         CASE ExitBT
  390.  
  391.         CASE HelpBT
  392.  
  393.         CASE ScoreNLB
  394.  
  395.         CASE ROCKHANDSCISSORGAMELB
  396.  
  397.         CASE ChooseYourMoveAndWaitAIsOneLB
  398.  
  399.     END SELECT
  400.  
  401. SUB __UI_FocusIn (id AS LONG)
  402.     SELECT CASE id
  403.         CASE StartBT
  404.  
  405.         CASE ExitBT
  406.  
  407.         CASE HelpBT
  408.  
  409.     END SELECT
  410.  
  411. SUB __UI_FocusOut (id AS LONG)
  412.     'This event occurs right before a control loses focus.
  413.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  414.     SELECT CASE id
  415.         CASE StartBT
  416.  
  417.         CASE ExitBT
  418.  
  419.         CASE HelpBT
  420.  
  421.     END SELECT
  422.  
  423. SUB __UI_MouseDown (id AS LONG)
  424.     SELECT CASE id
  425.         CASE RockHandScissor
  426.  
  427.         CASE ScoreLB
  428.  
  429.         CASE Frame1
  430.  
  431.         CASE StartBT
  432.  
  433.         CASE ExitBT
  434.  
  435.         CASE HelpBT
  436.  
  437.         CASE ScoreNLB
  438.  
  439.         CASE ROCKHANDSCISSORGAMELB
  440.  
  441.         CASE HelpHLB
  442.  
  443.     END SELECT
  444.  
  445. SUB __UI_MouseUp (id AS LONG)
  446.     SELECT CASE id
  447.         CASE RockHandScissor
  448.  
  449.         CASE ScoreLB
  450.  
  451.         CASE Frame1
  452.  
  453.         CASE StartBT
  454.  
  455.         CASE ExitBT
  456.  
  457.         CASE HelpBT
  458.  
  459.         CASE ScoreNLB
  460.  
  461.         CASE ROCKHANDSCISSORGAMELB
  462.  
  463.         CASE HelpHLB
  464.  
  465.     END SELECT
  466.  
  467. SUB __UI_KeyPress (id AS LONG)
  468.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  469.     'You can change it and even cancel it by making it = 0
  470.     SELECT CASE id
  471.         CASE StartBT
  472.  
  473.         CASE ExitBT
  474.  
  475.         CASE HelpBT
  476.  
  477.     END SELECT
  478.  
  479. SUB __UI_TextChanged (id AS LONG)
  480.     SELECT CASE id
  481.     END SELECT
  482.  
  483. SUB __UI_ValueChanged (id AS LONG)
  484.     SELECT CASE id
  485.     END SELECT
  486.  
  487. SUB __UI_FormResized
  488.  
  489.  

 
RockPaperScissors_Game Working Screenshot.jpg


 
RockPaperScissors_Help Screenshot.jpg

* [Inform] RockPaperScissorsSpockLizardGame.zip (Filesize: 497.33 KB, Downloads: 451)
* [Inform] RockPaperScissorsSpockLizardGame.rar (Filesize: 496.75 KB, Downloads: 489)
« Last Edit: May 01, 2020, 05:11:32 am by Qwerkey »