Robots/Phix: Difference between revisions

Content added Content deleted
(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: Line 2:
{{trans|C++}}
{{trans|C++}}
<lang Phix>constant W = 62, H = 42, INC = 10
<lang Phix>constant W = 62, H = 42, INC = 10

integer robotsCount, aliveRobots, score, X, Y, alive
integer robotsCount, aliveRobots, score, X, Y, alive
sequence board = repeat(repeat(' ',W),H)
sequence board = repeat(repeat(' ',W),H)

procedure clearBoard()
procedure clearBoard()
board = repeat(repeat('#',W),H)
board = repeat(repeat('#',W),H)
Line 14: Line 14:
end for
end for
end procedure
end procedure

procedure printScore()
procedure printScore()
position(H,1); bk_color(2); text_color(10);
position(H,1); bk_color(GREEN); text_color(BRIGHT_GREEN);
printf(1," SCORE: %d ", score)
printf(1," SCORE: %d ", score)
end procedure
end procedure

procedure createBoard()
procedure createBoard()
aliveRobots = robotsCount
aliveRobots = robotsCount
Line 33: Line 33:
end for
end for
end procedure
end procedure

procedure displayBoard()
procedure displayBoard()
position(1,1)
position(1,1)
for y=1 to H do
for y=1 to H do
for x=1 to W do
for x=1 to W do
integer t = board[y,x]
integer t = board[y,x],
bk_color(0)
k = find(t," #+A*@")
text_color({0,9,14,12,12,10}[find(t," #+Å*@")])
bk_color(BLACK)
text_color({WHITE,BRIGHT_BLUE,YELLOW,BRIGHT_RED,BRIGHT_RED,BRIGHT_GREEN}[k])
puts(1,t)
puts(1,t)
end for
end for
Line 47: Line 48:
printScore()
printScore()
end procedure
end procedure

procedure checkCollision(integer x, y)
procedure checkCollision(integer x, y)
if X==x and Y==y then
if X==x and Y==y then
alive = false
alive = false
board[y,x] = 'Å'
board[y,x] = 'A'
else
else
integer c = board[y,x]
integer c = board[y,x]
Line 62: Line 63:
end if
end if
end procedure
end procedure

procedure moveRobots()
procedure moveRobots()
for y=1 to H do
for y=1 to H do
Line 86: Line 87:
end for
end for
end procedure
end procedure

procedure execute(integer x, y)
procedure execute(integer x, y)
board[Y,X] = ' '; X += x; Y += y;
board[Y,X] = ' '; X += x; Y += y;
board[Y,X] = '@'; moveRobots();
board[Y,X] = '@'; moveRobots();
end procedure
end procedure

procedure teleport()
procedure teleport()
board[Y,X] = ' '
board[Y,X] = ' '
Line 98: Line 99:
if find(board[Y,X],"*+~") then
if find(board[Y,X],"*+~") then
alive = false
alive = false
board[Y,X] = 'Å'
board[Y,X] = 'A'
else
else
board[Y,X] = '@'
board[Y,X] = '@'
Line 104: Line 105:
moveRobots()
moveRobots()
end procedure
end procedure

procedure waitForEnd()
procedure waitForEnd()
while aliveRobots and alive do
while aliveRobots and alive do
Line 112: Line 113:
end while
end while
end procedure
end procedure

procedure getInput()
procedure getInput()
while true do
while true do
Line 126: Line 127:
elsif k='T' then teleport() exit
elsif k='T' then teleport() exit
elsif k='Z' then waitForEnd() exit
elsif k='Z' then waitForEnd() exit
elsif k='!' then alive = false exit
end if
end if
end while
end while
printScore()
printScore()
end procedure
end procedure

procedure play()
procedure play()
clear_screen()
while true do
while true do
cursor(NO_CURSOR)
cursor(NO_CURSOR)
Line 145: Line 148:
end while
end while
displayBoard()
displayBoard()
position(25, 1); bk_color(0); text_color(7)
position(25, 1); bk_color(BLACK); text_color(WHITE)
position( 8,10); puts(1,"+----------------------------------------+")
position( 8,10); puts(1,"+----------------------------------------+")
position( 9,10); puts(1,"| GAME OVER |")
position( 9,10); puts(1,"| GAME OVER |")
Line 153: Line 156:
if upper(wait_key())!='Y' then exit end if
if upper(wait_key())!='Y' then exit end if
end while
end while
clear_screen()
end procedure
end procedure