Author Topic: Genius  (Read 4776 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
Genius
« on: June 26, 2021, 07:06:05 pm »
Genius (you may call it Simon... we call it Genius in Brazil ;-) has already been implemented in QB64, brilliantly written by Terry Ritchie (see it at https://www.qb64.org/forum/index.php?topic=2263.msg114988#msg114988) and also by Cobalt (see it at https://www.qb64.org/forum/index.php?topic=984.msg101822#msg101822)

But this is a minimalist (minimalistic?) version. There's no awesome technique I wanna showcase or point I want to make with this: it's just a weekend free time bonus project.

Code: QB64: [Select]
  1.  
  2. CONST true = -1, false = 0
  3.  
  4. DIM SHARED AS LONG boardX, boardY
  5. boardX = 0
  6. boardY = _FONTHEIGHT
  7.  
  8.  
  9. TYPE blocks
  10.     AS INTEGER x, y, w, h
  11.     AS _UNSIGNED LONG low, high
  12.     AS STRING note
  13.  
  14. DIM SHARED AS blocks block(1 TO 4)
  15. DIM SHARED AS LONG canvas, gameScreen
  16.  
  17.  
  18. gameScreen = _NEWIMAGE(400, 400 + _FONTHEIGHT, 32)
  19. canvas = _NEWIMAGE(400, 400, 32)
  20.  
  21. SCREEN gameScreen
  22. _TITLE "Genius"
  23.  
  24. FOR i = 1 TO 4
  25.     block(i).w = _WIDTH(canvas) \ 2
  26.     block(i).h = _HEIGHT(canvas) \ 2
  27.  
  28. i = 0
  29. i = i + 1: block(i).x = 0: block(i).y = 0
  30. block(i).note = "o3c" 'green
  31. block(i).high = _RGB32(0, 155, 0)
  32. block(i).low = _RGB32(0, 78, 0)
  33.  
  34. i = i + 1: block(i).x = 0: block(i).y = _HEIGHT(canvas) \ 2
  35. block(i).note = "o2e" 'red
  36. block(i).high = _RGB32(227, 0, 0)
  37. block(i).low = _RGB32(78, 0, 0)
  38.  
  39. i = i + 1: block(i).x = _WIDTH(canvas) \ 2: block(i).y = 0
  40. block(i).note = "o2g" 'yellow
  41. block(i).high = _RGB32(194, 194, 0)
  42. block(i).low = _RGB32(161, 116, 0)
  43.  
  44. i = i + 1: block(i).x = _WIDTH(canvas) \ 2: block(i).y = _HEIGHT(canvas) \ 2
  45. block(i).note = "o2b" 'blue
  46. block(i).high = _RGB32(0, 105, 233)
  47. block(i).low = _RGB32(0, 0, 78)
  48.  
  49.  
  50. DIM SHARED AS _BYTE gameOver, inGame
  51. DIM SHARED sequence$, goal AS INTEGER
  52. CONST initialGoal = 3
  53. goal = initialGoal
  54.  
  55.     IF gameOver THEN
  56.         gameOver = false
  57.         inGame = false
  58.         goal = initialGoal
  59.     END IF
  60.  
  61.     IF inGame THEN
  62.         resetSequence
  63.         DO 'main game
  64.             DIM AS INTEGER x, y
  65.  
  66.             IF LEN(sequence$) \ 2 = goal THEN
  67.                 COLOR _RGB32(0, 222, 0)
  68.                 _PRINTSTRING (x, y), STRING$(goal, 1)
  69.                 _DISPLAY
  70.                 goal = goal + 2
  71.                 EXIT DO
  72.             END IF
  73.  
  74.             CLS
  75.             addNote
  76.             y = boardY - _FONTHEIGHT
  77.             x = (_WIDTH - _PRINTWIDTH(STRING$(goal, 254))) \ 2
  78.             COLOR _RGB32(78)
  79.             _PRINTSTRING (x, y), STRING$(goal, 254)
  80.             COLOR _RGB32(255)
  81.             _PRINTSTRING (x, y), STRING$(LEN(sequence$) \ 2, 254)
  82.             playSequence
  83.             getSequence
  84.         LOOP UNTIL gameOver
  85.         IF gameOver THEN resetSequence
  86.     ELSE
  87.         showMenu
  88.     END IF
  89.  
  90. SUB showMenu
  91.     DIM m$
  92.     DIM AS LONG x, y, mx, my
  93.     DIM AS _BYTE mouseIsDown, mouseDownOnStart, startButtonHovered
  94.  
  95.     m$ = "< Start >"
  96.     y = boardY - _FONTHEIGHT
  97.     x = (_WIDTH - _PRINTWIDTH(m$)) \ 2
  98.     DO
  99.         CLS
  100.         drawBoard
  101.  
  102.         WHILE _MOUSEINPUT: WEND
  103.         mx = _MOUSEX: my = _MOUSEY
  104.  
  105.         startButtonHovered = (mx >= x AND mx <= x + _PRINTWIDTH(m$) AND my >= y AND my <= y + _FONTHEIGHT)
  106.  
  107.         IF startButtonHovered THEN
  108.             COLOR _RGB32(0), _RGB32(255)
  109.         ELSE
  110.             COLOR _RGB32(255), _RGB32(0)
  111.         END IF
  112.  
  113.         _PRINTSTRING (x, y), m$
  114.         COLOR , _RGB32(0)
  115.  
  116.         IF _MOUSEBUTTON(1) THEN
  117.             IF mouseIsDown = false THEN
  118.                 mouseIsDown = true
  119.                 mouseDownOnStart = false
  120.                 IF startButtonHovered THEN mouseDownOnStart = true
  121.             ELSE
  122.             END IF
  123.         ELSE
  124.             IF mouseIsDown THEN
  125.                 IF mouseDownOnStart AND startButtonHovered THEN
  126.                     inGame = true
  127.                     CLS
  128.                     EXIT SUB
  129.                 END IF
  130.             END IF
  131.             mouseIsDown = false
  132.         END IF
  133.         _DISPLAY
  134.         _LIMIT 30
  135.  
  136. SUB getSequence STATIC
  137.     DIM AS LONG i, index, mouseDownOn, mx, my, check
  138.     DIM AS INTEGER x, y
  139.     DIM AS _BYTE mouseIsDown
  140.     DIM start!
  141.  
  142.     x = (_WIDTH - _PRINTWIDTH(STRING$(goal, 254))) \ 2
  143.     y = boardY - _FONTHEIGHT
  144.     index = 0
  145.     mouseIsDown = false
  146.     mouseDownOn = 0
  147.     start! = TIMER
  148.     DO
  149.         IF timeElapsedSince(start!) > 3 THEN
  150.             gameOver = true
  151.             COLOR _RGB32(127, 0, 0)
  152.             _PRINTSTRING (x, y), STRING$(goal, 254)
  153.             EXIT DO
  154.         END IF
  155.  
  156.         drawBoard
  157.         WHILE _MOUSEINPUT: WEND
  158.         mx = _MOUSEX - boardX: my = _MOUSEY - boardY
  159.         IF _MOUSEBUTTON(1) THEN
  160.             start! = TIMER
  161.             IF mouseIsDown = false THEN
  162.                 mouseIsDown = true
  163.                 FOR i = 1 TO 4
  164.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  165.                         mouseDownOn = i
  166.                         EXIT FOR
  167.                     END IF
  168.                 NEXT
  169.             ELSE
  170.                 FOR i = 1 TO 4
  171.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  172.                         IF mouseDownOn = i THEN drawSquare mouseDownOn, 2
  173.                         EXIT FOR
  174.                     END IF
  175.                 NEXT
  176.             END IF
  177.         ELSE
  178.             IF mouseIsDown = true THEN
  179.                 FOR i = 1 TO 4
  180.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  181.                         IF i = mouseDownOn THEN
  182.                             'click
  183.                             index = index + 1
  184.                             IF index < LEN(sequence$) \ 2 THEN
  185.                                 COLOR _RGB32(238, 166, 0)
  186.                             ELSE
  187.                                 COLOR _RGB32(0, 166, 238)
  188.                             END IF
  189.                             _PRINTSTRING (x, y), STRING$(index, 254)
  190.  
  191.                             check = CVI(MID$(sequence$, index * 2 - 1, 2))
  192.                             drawBoard
  193.                             drawSquare i, 2
  194.                             PLAY "l16" + block(i).note + "l4"
  195.                             _DISPLAY
  196.                             IF i = check THEN
  197.                                 IF index = LEN(sequence$) \ 2 THEN
  198.                                     drawBoard
  199.                                     _DISPLAY
  200.                                     _DELAY .5
  201.                                     EXIT DO
  202.                                 END IF
  203.                             ELSE
  204.                                 'error - restart
  205.                                 gameOver = true
  206.                                 COLOR _RGB32(127, 0, 0)
  207.                                 _PRINTSTRING (x, y), STRING$(goal, 254)
  208.                                 EXIT DO
  209.                             END IF
  210.                         END IF
  211.                         EXIT FOR
  212.                     END IF
  213.                 NEXT
  214.             ELSE
  215.                 'hover
  216.                 'FOR i = 1 TO 4
  217.                 '    IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  218.                 '        LINE (boardX + block(i).x, boardY + block(i).y)-STEP(block(i).w - 1, block(i).h - 1), _RGB32(255, 50), BF
  219.                 '        EXIT FOR
  220.                 '    END IF
  221.                 'NEXT
  222.             END IF
  223.             mouseIsDown = false
  224.         END IF
  225.         _DISPLAY
  226.     LOOP
  227.  
  228. SUB addNote
  229.     DIM i AS LONG
  230.     i = _CEIL(RND * 4)
  231.     sequence$ = sequence$ + MKI$(i)
  232.  
  233. SUB playSequence
  234.     DIM AS LONG j, i
  235.     FOR j = 1 TO LEN(sequence$) \ 2
  236.         drawBoard
  237.         _DISPLAY
  238.         _DELAY .05
  239.         i = CVI(MID$(sequence$, j * 2 - 1, 2))
  240.         drawSquare i, 2
  241.         _DISPLAY
  242.         _DELAY .2
  243.         PLAY block(i).note
  244.     NEXT
  245.  
  246. SUB resetSequence
  247.     DIM AS LONG j, i
  248.     sequence$ = ""
  249.  
  250.     IF NOT gameOver THEN
  251.         PLAY "mbT240l16aebcbedfcaebl4"
  252.         'animation
  253.         FOR j = 1 TO 12
  254.             i = i + 1
  255.             IF i = 5 THEN i = 1
  256.             drawBoard
  257.             drawSquare i, 2
  258.             _DISPLAY
  259.             _LIMIT 20
  260.         NEXT
  261.         PLAY "T120mf"
  262.     ELSE
  263.         FOR i = 1 TO 4
  264.             drawSquare i, 2
  265.         NEXT
  266.         _DISPLAY
  267.         PLAY "t120mfl2o1cl4"
  268.     END IF
  269.     drawBoard
  270.     _DISPLAY
  271.     _DELAY .5
  272.  
  273. SUB drawBoard
  274.     STATIC board AS LONG
  275.     DIM AS LONG i
  276.  
  277.     IF board = 0 THEN
  278.         board = _NEWIMAGE(_WIDTH(canvas), _HEIGHT(canvas), 32)
  279.         FOR i = 1 TO 4
  280.             drawSquare i, 1
  281.         NEXT
  282.         _PUTIMAGE (0, 0), , board, (boardX, boardY)-STEP(_WIDTH(canvas) - 1, _HEIGHT(canvas) - 1)
  283.     ELSE
  284.         _PUTIMAGE (boardX, boardY), board
  285.     END IF
  286.  
  287.  
  288. SUB drawSquare (this AS INTEGER, c AS INTEGER)
  289.     DIM thisColor AS _UNSIGNED LONG
  290.     IF c = 1 THEN thisColor = block(this).low ELSE thisColor = block(this).high
  291.     LINE (boardX + block(this).x, boardY + block(this).y)-STEP(block(this).w - 1, block(this).h - 1), thisColor, BF
  292.  
  293. FUNCTION timeElapsedSince! (startTime!)
  294.     IF startTime! > TIMER THEN startTime! = startTime! - 86400
  295.     timeElapsedSince! = TIMER - startTime!
  296.  

 
Captura de Tela 2021-06-26 às 20.05.41.png
« Last Edit: June 27, 2021, 12:51:28 pm by FellippeHeitor »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Genius
« Reply #1 on: June 26, 2021, 07:26:39 pm »
Wow, pretty good!

As things seem to be Tiny or Minimalistic(spelled right but still flagged??) around here lately, perhaps you should make the touch areas 1 pixel!
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Genius
« Reply #2 on: June 26, 2021, 07:32:01 pm »
Hahahha, it's a thought :-D

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Genius
« Reply #3 on: June 26, 2021, 09:32:02 pm »
Genius (you may call it Simon... we call it Genius in Brazil ;-) has already been implemented in QB64, brilliantly written by Terry Ritchie (see it at https://www.qb64.org/forum/index.php?topic=2263.msg114988#msg114988) and also by Cobalt (see it at https://www.qb64.org/forum/index.php?topic=984.msg101822#msg101822)

But this is a minimalist (minimalistic?) version. There's no awesome technique I wanna showcase or point I want to make with this: it's just a weekend free time bonus project.

Code: QB64: [Select]
  1.  
  2. CONST true = -1, false = 0
  3.  
  4. DIM SHARED AS LONG boardX, boardY
  5. boardX = 0
  6. boardY = _FONTHEIGHT
  7.  
  8.  
  9. TYPE blocks
  10.     AS INTEGER x, y, w, h
  11.     AS _UNSIGNED LONG low, high
  12.     AS STRING note
  13.  
  14. DIM SHARED AS blocks block(1 TO 4)
  15. DIM SHARED AS LONG canvas, gameScreen
  16.  
  17.  
  18. gameScreen = _NEWIMAGE(400, 400 + _FONTHEIGHT, 32)
  19. canvas = _NEWIMAGE(400, 400, 32)
  20.  
  21. SCREEN gameScreen
  22. _TITLE "Genius"
  23.  
  24. FOR i = 1 TO 4
  25.     block(i).w = _WIDTH(canvas) \ 2
  26.     block(i).h = _HEIGHT(canvas) \ 2
  27.  
  28. i = 0
  29. i = i + 1: block(i).x = 0: block(i).y = 0
  30. block(i).note = "o3c" 'green
  31. block(i).high = _RGB32(0, 155, 0)
  32. block(i).low = _RGB32(0, 78, 0)
  33.  
  34. i = i + 1: block(i).x = 0: block(i).y = _HEIGHT(canvas) \ 2
  35. block(i).note = "o2e" 'red
  36. block(i).high = _RGB32(227, 0, 0)
  37. block(i).low = _RGB32(78, 0, 0)
  38.  
  39. i = i + 1: block(i).x = _WIDTH(canvas) \ 2: block(i).y = 0
  40. block(i).note = "o2g" 'yellow
  41. block(i).high = _RGB32(194, 194, 0)
  42. block(i).low = _RGB32(161, 116, 0)
  43.  
  44. i = i + 1: block(i).x = _WIDTH(canvas) \ 2: block(i).y = _HEIGHT(canvas) \ 2
  45. block(i).note = "o2b" 'blue
  46. block(i).high = _RGB32(0, 105, 233)
  47. block(i).low = _RGB32(0, 0, 78)
  48.  
  49.  
  50. DIM SHARED AS _BYTE gameOver, inGame
  51. DIM SHARED sequence$, goal AS INTEGER
  52. CONST initialGoal = 3
  53. goal = initialGoal
  54.  
  55.     IF gameOver THEN
  56.         gameOver = false
  57.         inGame = false
  58.         goal = initialGoal
  59.     END IF
  60.  
  61.     IF inGame THEN
  62.         resetSequence
  63.         DO 'main game
  64.             DIM AS INTEGER x, y
  65.  
  66.             IF LEN(sequence$) \ 2 = goal THEN
  67.                 COLOR _RGB32(0, 222, 0)
  68.                 _PRINTSTRING (x, y), STRING$(goal, 1)
  69.                 _DISPLAY
  70.                 goal = goal + 2
  71.                 EXIT DO
  72.             END IF
  73.  
  74.             CLS
  75.             addNote
  76.             y = boardY - _FONTHEIGHT
  77.             x = (_WIDTH - _PRINTWIDTH(STRING$(goal, 254))) \ 2
  78.             COLOR _RGB32(78)
  79.             _PRINTSTRING (x, y), STRING$(goal, 254)
  80.             COLOR _RGB32(255)
  81.             _PRINTSTRING (x, y), STRING$(LEN(sequence$) \ 2, 254)
  82.             playSequence
  83.             getSequence
  84.         LOOP UNTIL gameOver
  85.         IF gameOver THEN resetSequence
  86.     ELSE
  87.         showMenu
  88.     END IF
  89.  
  90. SUB showMenu
  91.     DIM m$
  92.     DIM AS LONG x, y, mx, my
  93.     DIM AS _BYTE mouseIsDown, mouseDownOnStart, startButtonHovered
  94.  
  95.     m$ = "< Start >"
  96.     y = boardY - _FONTHEIGHT
  97.     x = (_WIDTH - _PRINTWIDTH(m$)) \ 2
  98.     DO
  99.         CLS
  100.         drawBoard
  101.  
  102.         WHILE _MOUSEINPUT: WEND
  103.         mx = _MOUSEX: my = _MOUSEY
  104.  
  105.         startButtonHovered = (mx >= x AND mx <= x + _PRINTWIDTH(m$) AND my >= y AND my <= y + _FONTHEIGHT)
  106.  
  107.         IF startButtonHovered THEN
  108.             COLOR _RGB32(0), _RGB32(255)
  109.         ELSE
  110.             COLOR _RGB32(255), _RGB32(0)
  111.         END IF
  112.  
  113.         _PRINTSTRING (x, y), m$
  114.         COLOR , _RGB32(0)
  115.  
  116.         IF _MOUSEBUTTON(1) THEN
  117.             IF mouseIsDown = false THEN
  118.                 mouseIsDown = true
  119.                 mouseDownOnStart = false
  120.                 IF startButtonHovered THEN mouseDownOnStart = true
  121.             ELSE
  122.             END IF
  123.         ELSE
  124.             IF mouseIsDown THEN
  125.                 IF mouseDownOnStart AND startButtonHovered THEN
  126.                     inGame = true
  127.                     CLS
  128.                     EXIT SUB
  129.                 END IF
  130.             END IF
  131.             mouseIsDown = false
  132.         END IF
  133.         _DISPLAY
  134.         _LIMIT 30
  135.  
  136. SUB getSequence STATIC
  137.     DIM AS LONG i, index, mouseDownOn, mx, my, check
  138.     DIM AS INTEGER x, y
  139.     DIM AS _BYTE mouseIsDown
  140.     DIM start!
  141.  
  142.     x = (_WIDTH - _PRINTWIDTH(STRING$(goal, 254))) \ 2
  143.     y = boardY - _FONTHEIGHT
  144.     index = 0
  145.     mouseIsDown = false
  146.     mouseDownOn = 0
  147.     start! = TIMER
  148.     DO
  149.         IF timeElapsedSince(start!) > 3 THEN
  150.             gameOver = true
  151.             COLOR _RGB32(127, 0, 0)
  152.             _PRINTSTRING (x, y), STRING$(goal, 254)
  153.             EXIT DO
  154.         END IF
  155.  
  156.         drawBoard
  157.         WHILE _MOUSEINPUT: WEND
  158.         mx = _MOUSEX - boardX: my = _MOUSEY - boardY
  159.         IF _MOUSEBUTTON(1) THEN
  160.             start! = TIMER
  161.             IF mouseIsDown = false THEN
  162.                 mouseIsDown = true
  163.                 FOR i = 1 TO 4
  164.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  165.                         mouseDownOn = i
  166.                         EXIT FOR
  167.                     END IF
  168.                 NEXT
  169.             ELSE
  170.                 FOR i = 1 TO 4
  171.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  172.                         IF mouseDownOn = i THEN drawSquare mouseDownOn, 2
  173.                         EXIT FOR
  174.                     END IF
  175.                 NEXT
  176.             END IF
  177.         ELSE
  178.             IF mouseIsDown = true THEN
  179.                 FOR i = 1 TO 4
  180.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  181.                         IF i = mouseDownOn THEN
  182.                             'click
  183.                             index = index + 1
  184.                             IF index < LEN(sequence$) \ 2 THEN
  185.                                 COLOR _RGB32(238, 166, 0)
  186.                             ELSE
  187.                                 COLOR _RGB32(0, 166, 238)
  188.                             END IF
  189.                             _PRINTSTRING (x, y), STRING$(index, 254)
  190.  
  191.                             check = CVI(MID$(sequence$, index * 2 - 1, 2))
  192.                             drawBoard
  193.                             drawSquare i, 2
  194.                             PLAY "l16" + block(i).note + "l4"
  195.                             _DISPLAY
  196.                             IF i = check THEN
  197.                                 IF index = LEN(sequence$) \ 2 THEN
  198.                                     drawBoard
  199.                                     _DISPLAY
  200.                                     _DELAY .5
  201.                                     EXIT DO
  202.                                 END IF
  203.                             ELSE
  204.                                 'error - restart
  205.                                 gameOver = true
  206.                                 COLOR _RGB32(127, 0, 0)
  207.                                 _PRINTSTRING (x, y), STRING$(goal, 254)
  208.                                 EXIT DO
  209.                             END IF
  210.                         END IF
  211.                         EXIT FOR
  212.                     END IF
  213.                 NEXT
  214.             ELSE
  215.                 'hover
  216.                 FOR i = 1 TO 4
  217.                     IF mx >= block(i).x AND mx <= block(i).x + block(i).w AND my >= block(i).y AND my <= block(i).y + block(i).h THEN
  218.                         LINE (boardX + block(i).x, boardY + block(i).y)-STEP(block(i).w - 1, block(i).h - 1), _RGB32(255, 50), BF
  219.                         EXIT FOR
  220.                     END IF
  221.                 NEXT
  222.             END IF
  223.             mouseIsDown = false
  224.         END IF
  225.         _DISPLAY
  226.     LOOP
  227.  
  228. SUB addNote
  229.     DIM i AS LONG
  230.     i = _CEIL(RND * 4)
  231.     sequence$ = sequence$ + MKI$(i)
  232.  
  233. SUB playSequence
  234.     DIM AS LONG j, i
  235.     FOR j = 1 TO LEN(sequence$) \ 2
  236.         drawBoard
  237.         _DISPLAY
  238.         _DELAY .05
  239.         i = CVI(MID$(sequence$, j * 2 - 1, 2))
  240.         drawSquare i, 2
  241.         _DISPLAY
  242.         _DELAY .2
  243.         PLAY block(i).note
  244.     NEXT
  245.  
  246. SUB resetSequence
  247.     DIM AS LONG j, i
  248.     sequence$ = ""
  249.  
  250.     IF NOT gameOver THEN
  251.         PLAY "mbT240l16aebcbedfcaebl4"
  252.         'animation
  253.         FOR j = 1 TO 12
  254.             i = i + 1
  255.             IF i = 5 THEN i = 1
  256.             drawBoard
  257.             drawSquare i, 2
  258.             _DISPLAY
  259.             _LIMIT 20
  260.         NEXT
  261.         PLAY "T120mf"
  262.     ELSE
  263.         FOR i = 1 TO 4
  264.             drawSquare i, 2
  265.         NEXT
  266.         _DISPLAY
  267.         PLAY "t120mfl2o1cl4"
  268.     END IF
  269.     drawBoard
  270.     _DISPLAY
  271.     _DELAY .5
  272.  
  273. SUB drawBoard
  274.     STATIC board AS LONG
  275.     DIM AS LONG i
  276.  
  277.     IF board = 0 THEN
  278.         board = _NEWIMAGE(_WIDTH(canvas), _HEIGHT(canvas), 32)
  279.         FOR i = 1 TO 4
  280.             drawSquare i, 1
  281.         NEXT
  282.         _PUTIMAGE (0, 0), , board, (boardX, boardY)-STEP(_WIDTH(canvas) - 1, _HEIGHT(canvas) - 1)
  283.     ELSE
  284.         _PUTIMAGE (boardX, boardY), board
  285.     END IF
  286.  
  287.  
  288. SUB drawSquare (this AS INTEGER, c AS INTEGER)
  289.     DIM thisColor AS _UNSIGNED LONG
  290.     IF c = 1 THEN thisColor = block(this).low ELSE thisColor = block(this).high
  291.     LINE (boardX + block(this).x, boardY + block(this).y)-STEP(block(this).w - 1, block(this).h - 1), thisColor, BF
  292.  
  293. FUNCTION timeElapsedSince! (startTime!)
  294.     IF startTime! > TIMER THEN startTime! = startTime! - 86400
  295.     timeElapsedSince! = TIMER - startTime!
  296.  

 
Captura de Tela 2021-06-26 às 20.05.41.png


Quote
But this is a minimalist (minimalistic?) version.

Certainly not minimalest, can't be at 312 LOC. ;-)
« Last Edit: June 26, 2021, 09:33:29 pm by bplus »

FellippeHeitor

  • Guest
Re: Genius
« Reply #4 on: June 26, 2021, 09:35:30 pm »
Minimalistic in visuals... I could never compete is those competitions of who does more with less code.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Genius
« Reply #5 on: June 26, 2021, 10:20:08 pm »
So let me get this straight... In Brazil, they would call me Simon?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Genius
« Reply #6 on: June 26, 2021, 10:32:54 pm »
So let me get this straight... In Brazil, they would call me Simon?

Pete

Precisely 😉

FellippeHeitor

  • Guest
Re: Genius
« Reply #7 on: June 27, 2021, 10:41:44 am »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Genius
« Reply #8 on: June 27, 2021, 12:46:08 pm »
Nice, @FellippeHeitor!  You beat me to it!  I was just this weekend working on the exact same thing, converting THIS smartbasic version to QB64.  I will abandon it now and just play yours.:)

-Dav

Marked as best answer by on Today at 09:17:00 am

FellippeHeitor

  • Guest
Re: Genius
« Reply #9 on: June 27, 2021, 12:50:29 pm »
  • Undo Best Answer
  • That's a big coincidence! I sure wish you wouldn't give up converting yours, though. It must be an interesting comparison exercise!

    FellippeHeitor

    • Guest
    Re: Genius
    « Reply #10 on: June 27, 2021, 12:52:09 pm »
    Updated the code box above, but I will keep it fresh from now on at the repository: https://github.com/FellippeHeitor/genius

    Offline Dav

    • Forum Resident
    • Posts: 792
      • View Profile
    Re: Genius
    « Reply #11 on: June 29, 2021, 04:43:05 pm »
    That's a big coincidence! I sure wish you wouldn't give up converting yours, though. It must be an interesting comparison exercise!

    I'll try to finish it then.  I'm finding less and less time to code these days though - my gigs are roaring back this month.  Yay.  And getting more piano tuning calls. Feels so good to work again!

    I like how you show the progress at the top.  To me Genius (Simon) is easier with sounds - without note patterns I don't seem to do as good. 

    - Dav