Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAurioch

Posted 22 July 2013 - 04:17 AM

Goodie goodie, look what I found on my old PC from 1991 biggrin.png

Few years ago, I was bored on vacation and all other electronic devices were used by other family members, so I wrote this little gem in QBasic which needs serious refactoring:

CLS

DIM a, b, i, n, s AS INTEGER
DIM button AS STRING
DIM direction AS STRING
DIM x(100) AS INTEGER
DIM y(100) AS INTEGER

s = 0
n = 1
direction = ""
x(1) = 12 '25 max
y(1) = 40 '80 max
RANDOMIZE 1
a = INT(RND * 20) + 3
b = INT(RND * 77) + 2

COLOR 9
PRINT "Welcome to Aurioch's ASCII Snake"
COLOR 3
PRINT CHR$(201); STRING$(78, 205); CHR$(187)
FOR i = 1 TO 20
  PRINT CHR$(186); STRING$(78, " "); CHR$(186)
NEXT i
PRINT CHR$(200); STRING$(78, 205); CHR$(188)
LOCATE 1, 60
COLOR 12
PRINT "Score:"; S

DO
  FOR i = 1 TO n
    LOCATE x(i), y(i)
    COLOR 10
    IF i = 1 THEN
      PRINT CHR$(2)
    ELSE
      PRINT CHR$(254)
    END IF
  NEXT i

  LOCATE a, b
  COLOR 14
  PRINT CHR$(42)
  FOR i = 1 TO 5000 'delay
  NEXT i
  button = INKEY$
  FOR i = 1 TO n
    LOCATE x(i), y(i)
    PRINT " "
  NEXT i

  IF button = "w" THEN direction = "up"
  IF button = "s" THEN direction = "down"
  IF button = "a" THEN direction = "left"
  IF button = "d" THEN direction = "right"

  IF (direction = "up") AND (x(1) > 3) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    x(1) = x(1) - 1
  END IF

  IF (direction = "right") AND (y(1) < 79) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    y(1) = y(1) + 1
  END IF

  IF (direction = "down") AND (x(1) < 22) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    x(1) = x(1) + 1
  END IF

  IF (direction = "left") AND (y(1) > 2) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    y(1) = y(1) + 1
  END IF

  IF (x(1) = a) AND (y(1) = b) THEN
    a = INT(RND * 20) + 3
    b = INT(RND * 77) + 2
    s = s + n
    n = n + 1
    IF direction = "up" THEN
      x(n) = x(1) + 1
      y(n) = y(1)
    END IF
    IF direction = "down" THEN
      x(n) = x(1) - 1
      y(n) = y(1)
    END IF
    IF direction = "left" THEN
      x(n) = x(1)
      y(n) = y(1) + 1
    END IF
    IF direction = "right" THEN
      x(n) = x(1)
      y(n) = y(1) - 1
    END IF
    LOCATE 1, 66
    PRINT s
  END IF

LOOP UNTIL button = CHR$(27)
COLOR 7
END

Yesterday, I was rewriting it on my laptop and noticed that I made game loop without knowing about it at all XD


#1Aurioch

Posted 22 July 2013 - 04:15 AM

Goodie goodie, look what I found on my old PC from 1991 :D

Few years ago, I was bored on vacation and all other electronic devices were used by other family members, so I wrote this little gem in QBasic which needs serious refactoring:

CLS

DIM a, b, i, n, s AS INTEGER
DIM button AS STRING
DIM direction AS STRING
DIM x(100) AS INTEGER
DIM y(100) AS INTEGER

s = 0
n = 1
smjer = ""
x(1) = 12 '25 max
y(1) = 40 '80 max
RANDOMIZE 1
a = INT(RND * 20) + 3
b = INT(RND * 77) + 2

COLOR 9
PRINT "Welcome to Aurioch's ASCII Snake"
COLOR 3
PRINT CHR$(201); STRING$(78, 205); CHR$(187)
FOR i = 1 TO 20
  PRINT CHR$(186); STRING$(78, " "); CHR$(186)
NEXT i
PRINT CHR$(200); STRING$(78, 205); CHR$(188)
LOCATE 1, 60
COLOR 12
PRINT "Score:"; S

DO
  FOR i = 1 TO n
    LOCATE x(i), y(i)
    COLOR 10
    IF i = 1 THEN
      PRINT CHR$(2)
    ELSE
      PRINT CHR$(254)
    END IF
  NEXT i

  LOCATE a, b
  COLOR 14
  PRINT CHR$(42)
  FOR i = 1 TO 5000 'delay
  NEXT i
  button = INKEY$
  FOR i = 1 TO n
    LOCATE x(i), y(i)
    PRINT " "
  NEXT i

  IF button = "w" THEN direction = "up"
  IF button = "s" THEN direction = "down"
  IF button = "a" THEN direction = "left"
  IF button = "d" THEN direction = "right"

  IF (direction = "up") AND (x(1) > 3) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    x(1) = x(1) - 1
  END IF

  IF (direction = "right") AND (y(1) < 79) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    y(1) = y(1) + 1
  END IF

  IF (direction = "down") AND (x(1) < 22) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    x(1) = x(1) + 1
  END IF

  IF (direction = "left") AND (y(1) > 2) THEN
    IF n > 1 THEN
      FOR i = n TO 2 STEP -1
        x(i) = x(i - 1)
        y(i) = y(i - 1)
      NEXT i
    END IF
    y(1) = y(1) + 1
  END IF

  IF (x(1) = a) AND (y(1) = b) THEN
    a = INT(RND * 20) + 3
    b = INT(RND * 77) + 2
    s = s + n
    n = n + 1
    IF direction = "up" THEN
      x(n) = x(1) + 1
      y(n) = y(1)
    END IF
    IF direction = "down" THEN
      x(n) = x(1) - 1
      y(n) = y(1)
    END IF
    IF direction = "left" THEN
      x(n) = x(1)
      y(n) = y(1) + 1
    END IF
    IF direction = "right" THEN
      x(n) = x(1)
      y(n) = y(1) - 1
    END IF
    LOCATE 1, 66
    PRINT s
  END IF

LOOP UNTIL button = CHR$(27)
COLOR 7
END

Yesterday, I was rewriting it on my laptop and noticed that I made game loop without knowing about it at all XD


PARTNERS