<div style="float: left; padding: 10px;"></div>BASIC for BlackBerry PlayBook By Harry Dodgson
Version: 1.2.28
Release: June 25, 2012
File Size: 441 KB

Những ai học CNTT những năm 90 trở về trước chắc chắn không lạ gì Ngôn ngữ lập trình BASIC, tiền thân của Visual Basic hay Visual Basic .NET ngày nay. Ngày trước, BASIC và PASCAL là hai ngôn ngữ lập trình thường được giảng dạy trong trường học, thậm chí năm thứ nhất Đại học, trường mình dạy môn Tin học Đại cương bằng chính anh BASIC này

Thật thú vị khi bây giờ, ngay trên chiếc PlayBook bạn có thể ôn lại những kỷ niệm xưa, có thể thoải mái viết những dòng lệnh và cho chương trình chạy ngay trên PlayBook. Điều mà trước kia mọi người phải làm trên những chiếc máy tính 386 hay 486. Khi cài phần mềm này lên, nó có sẵn một số chương trình demo để bạn tham khảo. Bạn có thể tạo mới và lưu lại những file chương trình của mình. File chương trình được lưu trong thư mục Shared/Documents, và nó cũng được tự động add vào danh sách.

Một vài hình ảnh:


Bạn viết mã chương trình ở cửa sổ bên trên, khi nào xong nhấn nút Run ở góc dưới màn hình để chạy. Nhấn nút Save để lưu lại.



Bạn cũng có thể tự viết chương trình Trò chơi Tetris đơn giản


Bạn cũng có thể tham khảo rất nhiều ví dụ khi nhấn vào nút Show Web Docs

Đây không chỉ giúp bạn "ôn lại kỷ niệm xưa" mà nó còn là một công cụ tốt để con/cháu bạn làm quen với lập trình :-bd

Tải miễn phí tại App World




<div>Premium Content</div>
<div>Subscribe and get exclusive access to our premium content!</div>



p/s: PlayBook quá lợi hại :-bd

Đoạn mã của game Tetris đây


Mã:
' Cheezy Tetris

' skips the long beam, since it doesn't fit in a 3x3 square
' wouldn't be that hard to include it now

' ----------------------
' todo:
' game levels with speed changes
' -----------------------

' powers of two
array powers  3 = 4 2 1
' number of rotations
array numrots 6 = 1 2 2 4 4 4
array board   190
array blanks  19

' numeric data - bitmaps for score
' arranged as 1 row for 0-9
array row1 10 = 01110 00100 01110 11110 00010 11111 00111 11111 01110 01110
array row2 10 = 10001 01100 10001 00001 00110 10000 01000 00001 10001 10001
array row3 10 = 10001 10100 00001 00010 01010 11110 10000 00010 10001 10001
array row4 10 = 10001 00100 00010 00100 10010 00001 11110 00100 01110 01111
array row5 10 = 10001 00100 01100 00010 11111 00001 10001 01000 10001 00001
array row6 10 = 10001 00100 10000 00001 00010 10001 10001 01000 10001 00010
array row7 10 = 01110 11111 11111 11110 00010 01110 01110 01000 01110 11100
array pwr10 5 = 10^4 10^3 10^2 10 1

define rectangle _x1 _y1 _x2 _y2
define square    _x1 _y1 _sz
define block     _x  _y
define draw_score _x _y _score
define draw_char _x _y _digit _rx _ry
define check_hit _x _y

constant left    = 50
constant top     = 30+50
constant height  = 450
constant width   = 250
constant forever = 0
constant htb     = 18
constant wdb     = 10
constant scale   = 6
constant score_x = 620
constant score_y = 50

' draw channel
  clear graphics
  rectangle left-8 top+50 left top+height
  rectangle left+width top+50 left+width+8 top+height
  rectangle left-8 top+height left+width+8 top+height+8
  fill left-2 top+52
  fill left+width+2 top+52
  fill left-2 top+height+2

' draw buttons
  b_L_L = 400
  b_L_R = 540
  square 400 200 140
  drawline 450 270 470 240
  drawline 450 270 470 300
  b_M_L = 600
  b_M_R = 740
  square 600 200 140
  drawcircle 670 270 15
  drawline 680 267 685 272
  drawline 685 272 690 267
  b_R_L = 800
  b_R_R = 940
  square 800 200 140
  drawline 880 270 860 240
  drawline 880 270 860 300
  square 600 400 140
  drawline 640 480 670 500
  drawline 640 475 670 495
  drawline 670 500 700 480
  drawline 670 495 700 475

  rectangle 400 150 940 160
  fill 402 152

' just to test board display
for b = 16 to htb-1
  for a = 0 to wdb
    if random(4) &lt; 2.0
      board(b*10+a) = integer(random(7))
    endif
  next a
next b

lines = 0
draw_score score_x score_y lines

sleep 0.2
repeat getmouse xm ym until xm &lt; 0

repeat
  dr_x = left + 50
  gosub choice
  if wd = 2
    lpy = top + 1 - 25
  else
    lpy = top + 0 - 25
  endif
  repeat
    lpy = lpy + 2
    clear at left 0 width height+top
    gosub drawboard
    gosub drawone
    getmouse xm ym

    if (xm >= b_L_L) and (xm &lt;= b_L_R) and (ym >= 200) and (ym &lt; 340) and (dr_x >= left)
      check_hit dr_x-25 lpy
      if hit = 0
        dr_x = dr_x - 25
      endif
    endif
    if (xm >= b_R_L) and (xm &lt;= b_R_R) and (ym >= 200) and (ym &lt; 340)
      if dr_x &lt;= (left+width-50-(ht*25))
        check_hit dr_x+25 lpy
        if hit = 0
          dr_x = dr_x + 25
        endif
      endif
    endif
    if (xm >= b_M_L) and (xm &lt;= b_M_R) and (ym >= 200) and (ym &lt; 340)
      gosub rotate
      if blk > 1
        lpy = lpy + 1
      endif
    endif
    if (xm >= b_M_L) and (xm &lt;= b_M_R) and (ym >= 400) and (ym &lt; 540)
      lpy = integer(lpy/25)*25
      repeat
        check_hit dr_x lpy
        lpy = lpy + 25
      until hit = 1
      lpy = lpy - 27
      break
    endif

    check_hit dr_x lpy
    if hit = 1
      if lpy &lt; top
        end
      else
        break
      endif
    endif
    sleep 0.05
  until forever
  gosub copyblock
  clear at left 0 width height+top
  gosub drawboard
  sleep 0.2
  gosub findlines
  if newlines
    clear at left+1 0 width-1 height+top
    gosub drawboard
    clear at score_x score_y scale*15 scale*9
    draw_score score_x score_y lines
    sleep 0.2
    gosub gravity
  endif
sleep 0.5
until forever
end

' ----------
drawboard:
  for b = 0 to htb-1
    for a = 0 to wdb-1
      c = board(b*10+a)
      if c &lt;> 0
        gosub putcol
        on c gosub c1 c2 c3 c4 c5 c6
        block left top
        gosub getcol
      endif
    next a
  next b
return

' ----------
drawone:
  for a = 1 to ht
    for b = 1 to wd
      if (cpc(a) and powers(b)) &lt;> 0
        block dr_x lpy
      endif
    next b
  next a
  lowest = 25*wd+lpy
return

' ----------
choice:
  blk = random(6) + 1
  on blk gosub c1 c2 c3 c4 c5 c6
  m_rot = numrots(blk)
  c_rot = 1
  gosub rotate2
return

c1:
  r1 = 180
  g1 = 255
  b1 = 180
  r2 = 20
  g2 = 240
  b2 = 20
return
c2:
  r1 = 255
  g1 = 180
  b1 = 180
  r2 = 240
  g2 = 20
  b2 = 20
return
c3:
  r1 = 255
  g1 = 180
  b1 = 255
  r2 = 240
  g2 = 20
  b2 = 240
return
c4:
  r1 = 180
  g1 = 180
  b1 = 255
  r2 = 20
  g2 = 20
  b2 = 240
return
c5:
  r1 = 255
  g1 = 255
  b1 = 180
  r2 = 240
  g2 = 240
  b2 = 20
return
c6:
  r1 = 180
  g1 = 255
  b1 = 255
  r2 = 20
  g2 = 240
  b2 = 240
return

' ----------
rotate:
  c_rot = c_rot + 1
  if c_rot > m_rot  let c_rot = 1
  on blk gosub r1 r2 r3 r4 r5 r6
' keep block in play if rotate off right side
  if dr_x > (left+width-25-(ht*25))
    dr_x = dr_x - 25
  endif
return

rotate2:
  on blk gosub r1 r2 r3 r4 r5 r6
return

r1:
  array cpc 3 = 6 6 0
  ht = 2
  wd = 2
return

r2:
  if c_rot = 2
    array cpc 3 = 6 3 0
    ht = 2
    wd = 3
  else
    array cpc 3 = 2 6 4
    ht = 3
    wd = 2
  endif
return

r3:
  if c_rot = 2
    array cpc 3 = 3 6 0
    ht = 2
    wd = 3
  else
    array cpc 3 = 4 6 2
    ht = 3
    wd = 2
  endif
return

r4:
  on c_rot goto ra1 ra2 ra3 ra4
  ra1:
  array cpc 3 = 4 4 6
  ht = 3
  wd = 2
  goto ra5
  ra2:
  array cpc 3 = 1 7 0
  ht = 2
  wd = 3
  goto ra5
  ra3:
  array cpc 3 = 6 2 2
  ht = 3
  wd = 2
  goto ra5
  ra4:
  array cpc 3 = 7 4 0
  ht = 2
  wd = 3
  'goto ra5
  ra5:
return

r5:
  on c_rot goto rb1 rb2 rb3 rb4
  rb1:
  array cpc 3 = 2 2 6
  ht = 3
  wd = 2
  goto rb5
  rb2:
  array cpc 3 = 7 1 0
  ht = 2
  wd = 3
  goto rb5
  rb3:
  array cpc 3 = 6 4 4
  ht = 3
  wd = 2
  goto rb5
  rb4:
  array cpc 3 = 4 7 0
  ht = 2
  wd = 3
  'goto rb5
  rb5:
return

r6:
  on c_rot goto rc2 rc3 rc4 rc1
  rc1:
  array cpc 3 = 2 7 0
  ht = 2
  wd = 3
  goto rc5
  rc2:
  array cpc 3 = 2 6 2
  ht = 3
  wd = 2
  goto rc5
  rc3:
  array cpc 3 = 7 2 0
  ht = 2
  wd = 3
  goto rc5
  rc4:
  array cpc 3 = 4 6 4
  ht = 3
  wd = 2
  'goto rc5
  rc5:
return

' ----------
putcol:
  sr1 = r1
  sg1 = g1
  sb1 = b1
  sr2 = r2
  sg2 = g2
  sb2 = b2
return

getcol:
  r1 = sr1
  g1 = sg1
  b1 = sb1
  r2 = sr2
  g2 = sg2
  b2 = sb2
return

' ----------
copyblock:
locy = integer(lpy-top+1/25)
locx = integer(dr_x-left/25)
for b = 1 to wd
  for a = 1 to ht
    if (cpc(a) and powers(b)) &lt;> 0
      board((locy+b)*10+locx+a) = blk
    endif
  next a
next b
return

' ----------
findlines:
  newlines = 0
  for b = 0 to htb-1
    cnt = 0
    for a = 0 to wdb-1
      if board(b*10+a) &lt;> 0  let cnt = cnt + 1
    next a
    if cnt = wdb
      blanks(b) = 1
      newlines = 1
      lines = lines + 1
      for a = 0 to wdb-1
        board(b*10+a) = 0
      next a
    else
      blanks(b) = 0
    endif
  next b
return

' ----------
gravity:
  b = htb-1
  ' check rows from bottom to top
  for b = htb-1 to 1 step -1
    ' see if a row is empty
    if blanks(b) = 1
      ' check rows above it for non-empty ones, exit loop if found
      for slide = b-1 to 0 step -1
        if blanks(slide) = 0  break
      next slide
      ' if loop completed without finding a row, exit routine
      if slide &lt; 0  break
      ' copy row down to empty row
      for a=0 to wdb-1
        board(b*10+a) = board(slide*10+a)
        board(slide*10+a) = 0
      next a
      ' adjust blanks array to show row status
      blanks(slide) = 1
      blanks(b) = 0
    endif
  next b
return

' ----------
draw_score:
  setcolor 240 240 240
  _hdigit = integer(_score / 10)
  _ldigit = integer(_score \ 10)
  if _hdigit &lt;> 0
    draw_char _x _y _hdigit 7*scale 4*scale
  endif
  draw_char 7*scale+_x _y _ldigit 0 4*scale
return

draw_char:
  _digit = _digit + 1
  xm = 1
  ym = 0
  for i = 1 to 7
    on i goto pr1 pr2 pr3 pr4 pr5 pr6 pr7
      pr1:
      pat = row1(_digit)
      goto rn
      pr2:
      pat = row2(_digit)
      goto rn
      pr3:
      pat = row3(_digit)
      goto rn
      pr4:
      pat = row4(_digit)
      goto rn
      pr5:
      pat = row5(_digit)
      goto rn
      pr6:
      pat = row6(_digit)
      goto rn
      pr7:
      pat = row7(_digit)
      rn:
    yp =  2*(scale*i - _ry) + 1
    for j = 1 to 5
      if integer(pat / pwr10(j)) &lt;> 0
        xp = 2*(scale*j - _rx) + 1
        ypr = (yp * xm) - (xp * ym)
        xpr = (yp * ym) + (xp * xm)
        yb  = (ypr - 1) /2 + _ry + _y
        xb  = (xpr - 1) /2 + _rx + _x
        pat = pat - pwr10(j)
        square xb yb scale
      endif
    next j
  next i
return

' ----------
check_hit:
  hit = 0
  locy = integer(_y-top/25)+1
  if locy >= (htb-wd)
    hit = 1
    return
  endif
  locx = integer(_x-left/25)
  for b = 1 to wd
    for a = 1 to ht
      if (cpc(a) and powers(b)) &lt;> 0
        if board((locy+b)*10+locx+a) &lt;> 0
          hit = 1
        endif
      endif
    next a
  next b
return

' ----------
block:
 setcolor r1 g1 b1
 square 25*a+_x 25*b+_y 24
 setcolor r2 g2 b2
 fill 25*a+_x+2 25*b+_y+2
return

square:
  _x2 = _x1 + _sz
  _y2 = _y1 + _sz
rectangle:
  drawline _x1 _y1 _x1 _y2
  drawline _x1 _y1 _x2 _y1
  drawline _x2 _y1 _x2 _y2
  drawline _x1 _y2 _x2 _y2
return