我的第一个“业余项目”

        一个用QBASIC写就的21点赌博游戏,能够下赌注与AI(美其名曰)玩,字符界面的人机交互。

DECLARE SUB yingying (y!, c!, d!)
DECLARE SUB shushu (y!, c!, d!)
DECLARE SUB ying (y!, c!, d!)
DECLARE SUB shu (y!, c!, d!)
DECLARE SUB prinqian (y!, c!)
DECLARE SUB prindian (dian!)


DEF fnzhi (qq)
  IF qq <= 10 THEN
    zhi = qq
  ELSE
    zhi = 10
  END IF
  fnzhi = zhi
END DEF


CLS
you = 100: computer = 100
DO WHILE NOT you < 0 AND NOT computer < 0
  a = 0: b = 0
  DO
    CALL prinqian(you, computer)
    input "input the number of money:"; duzhu
  LOOP UNTIL duzhu <= 20 AND duzhu >= 5 AND FIX(duzhu) = duzhu
  nd = 1
  FOR n = 1 TO 2
    RANDOMIZE TIMER
    aa = INT(RND * 13 + 1)
    bb = INT(RND * 13 + 1)
    a = a + fnzhi(aa)
    b = b + fnzhi(bb)
  NEXT n
'*****b*****
  DO WHILE b <= 16
    b = b + fnzhi(INT(RND * 13 + 1))
  LOOP
'*****b*****
  flag = 1
  DO WHILE flag = 1 AND a < 22
  CALL prindian(a)
  DO
    IF nd = 1 THEN
      input "input the number of money again."; duzhu2
    END IF
    nd = 0
  LOOP UNTIL duzhu2 <= 20 AND FIX(duzhu2) = duzhu2 AND duzhu2 >= 0
  duzhu = duzhu + duzhu2
  duzhu2 = 0
a: input "1 or 0:"; flag
    IF flag = 0 THEN
      EXIT DO
    ELSEIF flag = 1 THEN
      aa = INT(RND * 13 + 1)
      a = a + fnzhi(aa)
    ELSE
      GOTO a
    END IF
  LOOP
  PRINT a, b
  IF a > b AND a <= 21 OR b > 21 AND a <= 21 THEN
    PRINT "You win."
    IF a = 21 THEN
      CALL yingying(you, computer, duzhu)
    ELSE
      CALL ying(you, computer, duzhu)
    END IF
  ELSE
    PRINT "You fail."
    IF b = 21 THEN
      CALL shushu(you, computer, duzhu)
    ELSE
      CALL shu(you, computer, duzhu)
    END IF
  END IF
  you = you - 2
LOOP
IF you < 0 THEN
  PRINT "Try again."
ELSE
  PRINT "You are the winner."
END IF
END

SUB prindian (dian)
  PRINT "dian:"; dian
END SUB

SUB prinqian (y, c)
  PRINT "You:"; y, "Computer:"; c
END SUB

SUB shu (y, c, d)
  y = y - d
  c = c + d
END SUB

SUB shushu (y, c, d)
  c = c + 2 * d
  y = y - 2 * d
END SUB

SUB ying (y, c, d)
  y = y + d
  c = c - d
END SUB

SUB yingying (y, c, d)
  c = c - 2 * d
  y = y + 2 * d
END SUB

        这段代码写于03年,彼时为了中考加分而准备计算机二级考试,考试内容是QBASIC。而我学了点东西总爱鼓捣,这算是当时的“得意之作”。彼时不知面向对象为何物,只知顺序,分支,循环;只知冒泡排序,朴素的选择排序,而不知快速排序。

你可能感兴趣的:(我的第一个“业余项目”)