Robots/Phix: Difference between revisions

m
use std colours (for lnx)
(Created page with "=={{header|Phix}}== {{trans|C++}} <lang Phix>constant W = 62, H = 42, INC = 10 integer robotsCount, aliveRobots, score, X, Y, alive sequence board = repeat(repeat(' ',W),H)...")
 
m (use std colours (for lnx))
Line 2:
{{trans|C++}}
<lang Phix>constant W = 62, H = 42, INC = 10
 
integer robotsCount, aliveRobots, score, X, Y, alive
sequence board = repeat(repeat(' ',W),H)
 
procedure clearBoard()
board = repeat(repeat('#',W),H)
Line 14:
end for
end procedure
 
procedure printScore()
position(H,1); bk_color(2GREEN); text_color(10BRIGHT_GREEN);
printf(1," SCORE: %d ", score)
end procedure
 
procedure createBoard()
aliveRobots = robotsCount
Line 33:
end for
end procedure
 
procedure displayBoard()
position(1,1)
for y=1 to H do
for x=1 to W do
integer t = board[y,x],
bk_color k = find(0t," #+A*@")
text_colorbk_color({0,9,14,12,12,10}[find(t," #+Å*@")]BLACK)
text_color({WHITE,BRIGHT_BLUE,YELLOW,BRIGHT_RED,BRIGHT_RED,BRIGHT_GREEN}[k])
puts(1,t)
end for
Line 47 ⟶ 48:
printScore()
end procedure
 
procedure checkCollision(integer x, y)
if X==x and Y==y then
alive = false
board[y,x] = 'ÅA'
else
integer c = board[y,x]
Line 62 ⟶ 63:
end if
end procedure
 
procedure moveRobots()
for y=1 to H do
Line 86 ⟶ 87:
end for
end procedure
 
procedure execute(integer x, y)
board[Y,X] = ' '; X += x; Y += y;
board[Y,X] = '@'; moveRobots();
end procedure
 
procedure teleport()
board[Y,X] = ' '
Line 98 ⟶ 99:
if find(board[Y,X],"*+~") then
alive = false
board[Y,X] = 'ÅA'
else
board[Y,X] = '@'
Line 104 ⟶ 105:
moveRobots()
end procedure
 
procedure waitForEnd()
while aliveRobots and alive do
Line 112 ⟶ 113:
end while
end procedure
 
procedure getInput()
while true do
Line 126 ⟶ 127:
elsif k='T' then teleport() exit
elsif k='Z' then waitForEnd() exit
elsif k='!' then alive = false exit
end if
end while
printScore()
end procedure
 
procedure play()
clear_screen()
while true do
cursor(NO_CURSOR)
Line 145 ⟶ 148:
end while
displayBoard()
position(25, 1); bk_color(0BLACK); text_color(7WHITE)
position( 8,10); puts(1,"+----------------------------------------+")
position( 9,10); puts(1,"| GAME OVER |")
Line 153 ⟶ 156:
if upper(wait_key())!='Y' then exit end if
end while
clear_screen()
end procedure
 
7,796

edits