HP Prime for All
English
Русский
Name | Simon |
Description | Implementation of Simon Says, where you must repeat the pattern shown to you. |
Author | Tony Gallo |
Source code formatted by website engine
BEGIN
local colorlist;
local touch;
LOCAL X, Y;
local choice;
local done;
local start;
local touchcount;
local error;
//title screen
RECT_P(0, 0, 319, 239, 0, RGB(0, 0, 0));
TEXTOUT_P("SIMON", 135, 90, 2, RGB(255, 0, 0));
TEXTOUT_P("v1.0 2014", 130, 110, 1, RGB(255, 0, 0));
TEXTOUT_P("by Tony Gallo", 125, 130, 1, RGB(255, 0, 0));
wait(1.5);
done := 0;
WHILE (done == 0) DO
//clear screen
RECT_P(0, 0, 319, 239, 0, RGB(60, 60, 60));
//credits
TEXTOUT_P("SIMON", 10, 5, 2, RGB(0, 0, 0));
TEXTOUT_P("v1.0 2014", 100, 6, 1, RGB(0, 0, 0));
TEXTOUT_P("by Tony Gallo", 250, 5, 1, RGB(0, 0, 0));
DrawGame();
sequence := "";
start := 0;
TEXTOUT_P("Touch screen", 20, 35, 2, RGB(0, 0, 0));
TEXTOUT_P("to begin.", 20, 47, 2, RGB(0, 0, 0));
WHILE ISKEYDOWN(4) <> 1 and start == 0 do
wait(.1);
touch := mouse();
if size(touch(1)) then
if touch(1, 5) == 0 then
start := 1;
end;
end;
END;
if start == 0 then
//must have pressed Esc
return;
end;
//clear start message
RECT_P(20, 35, 95, 60, RGB(60, 60, 60), RGB(60, 60, 60));
PrintCount(0);
PlaySequence();
touchcount := 0;
error := 0;
WHILE ISKEYDOWN(4) <> 1 do
touch := mouse();
if size(touch(1)) then
if touch(1, 5) == 0 then
X := B→R(touch(1, 1));
Y := B→R(touch(1, 2));
if 80 <= X <= 160 and 50 <= Y <= 130 THEN
touchcount := touchcount+1;
if MID(sequence, touchcount, 1) < > "G" then error := 1; end;
DrawGreen(1);
wait(0.25);
DrawGreen(0);
end;
if 160 <= X <= 240 and 50 <= Y <= 130 THEN
touchcount := touchcount+1;
if MID(sequence, touchcount, 1) < > "R" then error := 1; end;
DrawRed(1);
wait(0.25);
DrawRed(0);
end;
if 80 <= X <= 160 and 130 <= Y <= 210 THEN
touchcount := touchcount+1;
if MID(sequence, touchcount, 1) < > "Y" then error := 1; end;
DrawYellow(1);
wait(0.25);
DrawYellow(0);
end;
if 160 <= X <= 240 and 130 <= Y <= 210 THEN
touchcount := touchcount+1;
if MID(sequence, touchcount, 1) < > "B" then error := 1; end;
DrawBlue(1);
wait(0.25);
DrawBlue(0);
end;
if error == 1 then
TEXTOUT_P("GAME OVER!", 248, 35, 2, RGB(0, 0, 0));
TEXTOUT_P("Press any", 252, 50, 2, RGB(0, 0, 0));
TEXTOUT_P("key.", 262, 65, 2, RGB(0, 0, 0));
break;
end;
wait(.1);
if touchcount == DIM(sequence) then
PrintCount(touchcount);
wait(.2);
PlaySequence();
touchcount := 0;
end;
end;
end;
END;
wait();
CHOOSE(choice, "Play Again?", "Yes", "No");
if choice < > 1 then done := 1; end;
END;
END;
DrawGame()
begin
local I;
FOR I FROM 0 TO 90 DO
ARC_P(160, 130, I, RGB(0, 0, 0));
END;
FOR I FROM 0 TO 35 DO
ARC_P(160, 130, I, RGB(140, 160, 180));
END;
TEXTOUT_P("SIMON", 142, 115, 2, RGB(0, 0, 0));
DrawGreen(0);
DrawRed(0);
DrawBlue(0);
DrawYellow(0);
PrintCount(0);
end;
DrawGreen(lit)
begin
local green;
if lit == 1 then
green := RGB(0, 255, 0);
else
green := RGB(10, 185, 25);
end;
FOR I FROM 45 TO 80 DO
ARC_P(160, 130, I, pi/2, pi, green);
END;
end;
DrawRed(lit)
begin
local red;
if lit == 1 then
red := RGB(255, 0, 0);
else
red := RGB(255, 60, 40);
end;
FOR I FROM 45 TO 80 DO
ARC_P(160, 130, I, 2*pi, pi/2, red);
END;
end;
DrawBlue(lit)
begin
local blue;
if lit == 1 then
blue := RGB(0, 50, 255);
else
blue := RGB(10, 180, 255);
end;
FOR I FROM 45 TO 80 DO
ARC_P(160, 130, I, pi+pi/2, 2*pi, blue);
END;
end;
DrawYellow(lit)
begin
local yellow;
if lit == 1 then
yellow := RGB(255, 255, 0);
else
yellow := RGB(255, 255, 90);
end;
FOR I FROM 45 TO 80 DO
ARC_P(160, 130, I, pi, pi+pi/2, yellow);
END;
end;
PlaySequence()
begin
local rand;
local color;
local I;
local pause;
rand := RANDINT(1, 4);
case
if rand == 1 then color := "G" end;
if rand == 2 then color := "R" end;
if rand == 3 then color := "Y" end;
if rand == 4 then color := "B" end;
end;
sequence := sequence + color;
pause := 0.25 - (0.01*DIM(sequence));
if pause < 0.05 then pause := 0.05; end;
FOR I FROM 1 to DIM(sequence) DO
wait(pause);
if MID(sequence, I, 1) == "G" then
DrawGreen(1);
wait(0.25);
DrawGreen(0);
end;
if MID(sequence, I, 1) == "R" THEN
DrawRed(1);
wait(0.25);
DrawRed(0);
end;
if MID(sequence, I, 1) == "Y" THEN
DrawYellow(1);
wait(0.25);
DrawYellow(0);
end;
if MID(sequence, I, 1) == "B" THEN
DrawBlue(1);
wait(0.25);
DrawBlue(0);
end;
END;
end;
PrintCount(number)
begin
RECT_P(145, 135, 175, 155, 0, RGB(0, 0, 0));
TEXTOUT_P(number, 155, 140, 2, RGB(255, 0, 0));
end;