Another Console Game
Posted: Fri Jul 18, 2008 3:41 am
Code: Select all
;Catch the X's
;Originally written for the TI-83 Plus by myself
;-TI-83 code:
;
;Let:
; A = score
; B = Escape
; C = enemyX
; D = enemyY
; E = XsMissed
; F = playerX
; G = playerY
; H = enemypointX1
; I = enemypointY1
; J = enemypointX2
; K = enemypointY2
; L = enemypointX3
; M = enemypointY3
; N = random number
;Adapted for PureBasic console
;-Variables
score.l ;player's score (how many 'X's you have caught)
Escape.l ;tells whether user has hit escape (exit the game)
enemyx.l ;the x console position of the enemy 'X' that is currently falling
enemyy.l ;the y console position of the enemy 'X' that is currently falling
XsMissed.l = 0;number of X's the player missed: 3=game over
playerx.l = 39 ;the x console position of the player
playery.l = 23;the y console position of the player
Dim enemyxpoints.l(3) ;an array of the x console positions of the fallen points at which the player did not catch the 'X'
Dim enemyypoints.l(3) ;an array of the y console positions of the fallen points at which the player did not catch the 'X'
RandomSeed(ElapsedMilliseconds()) ;Randomize the random seed
If OpenConsole() And InitKeyboard()
EnableGraphicalConsole(#True)
ConsoleCursor(0)
ConsoleTitle("Catch The X's")
For a = 0 To 79
ConsoleColor(9,0)
ConsoleLocate(a,0)
Print("B")
ConsoleLocate(a,24)
Print("B")
Next
For a = 1 To 23
ConsoleLocate(0,a)
Print("B")
ConsoleLocate(79,a)
Print("B")
Next
a = 0
ConsoleColor(10,0)
ConsoleLocate(playerx,playery)
Print("P")
enemyx = Random(77)+1
enemyy = 1
Repeat
a = a + 1
Escape = GetAsyncKeyState_(#VK_ESCAPE)
Pause = GetAsyncKeyState_(#VK_PAUSE)
Left = GetAsyncKeyState_(#VK_LEFT)
Right = GetAsyncKeyState_(#VK_RIGHT)
If enemyy = 23
ConsoleColor(10,0)
ConsoleLocate(playerx,playery)
Print("P")
If enemyx = playerx And enemyy = playery
score = score + 1
ConsoleColor(13,0)
ConsoleLocate(0,0)
Print("Score: "+Str(score))
Else
XsMissed = XsMissed + 1
enemyxpoints(XsMissed) = enemyx
enemyypoints(XsMissed) = enemyy
EndIf
enemyx = Random(77)+1
enemyy = 1
ElseIf enemyy < 23 And Not a % 3
ConsoleLocate(enemyx,enemyy)
Print(" ")
enemyy = enemyy + 1
ConsoleColor(12,0)
ConsoleLocate(enemyx,enemyy)
Print("X")
EndIf
If XsMissed
ConsoleColor(12,0)
For x = 1 To XsMissed
ConsoleLocate(enemyxpoints(x),enemyypoints(x))
Print("X")
Next
EndIf
If XsMissed = 3
End
EndIf
If (Left <> 0 Or Right <> 0) And (Not (Left <> 0 And Right <> 0))
ConsoleLocate(playerx,playery)
Print(" ")
EndIf
If Left <> 0 And Not Right
playerx = playerx-1
If playerx = 0
playerx = 78
EndIf
ConsoleColor(10,0)
ConsoleLocate(playerx,playery)
Print("P")
EndIf
If Right <> 0 And Not Left
playerx = playerx+1
If playerx = 79
playerx = 1
EndIf
ConsoleColor(10,0)
ConsoleLocate(playerx,playery)
Print("P")
EndIf
Delay(50)
Until Escape <> 0
EndIf
Just a console game I thought I'd share
