Juegos HP Prime

Juegos

 

A Short Tetris program, published by Cyrille de Brévisson.

DoesNotFit(game, piece, p) // return true if piece does not fit

begin

  local j;

  if game(im(p), re(p)) then return 1; end;

  for j:=1 to size(piece) do

    p:= p+piece(j);

    if game(im(p), re(p)) then return 1; end;

  end;

  return 0;

end;

 

EXPORT Tetris()

BEGIN

  local game= makemat(J=1 or J=12 or I=1 or I=25,25,12), pause=0.200, score= 0;

  local shapes= {{(1, 0), (0, 1), (-1, 0)},

                          {(1, 0), (0, 1), (1, 0)},

                          {(-1, 0), (0, 1), (-1, 0)},

                          {(1, 0), (1, 0), (0, 1)},

                          {(-1, 0), (-1, 0), (0, 1)},

                          {(1, 0), (1, 0), (-1, 1)},

                          {(1, 0), (1, 0), (1, 0)}}; // Bar

  while 1 do

    local piece=shapes(randint(6)+1), p=(5,2), i, j; // get a random piece

 

    if DoesNotFit(game, piece, p) then return score; end; // test if we lose

 

    // create background

    dimgrob_p(G1, 320, 240);

    dimgrob_p(G2, 320, 240);

    line_p(G1,99, 0, 99, 232, #FF); line_p(G1, 99, 232, 202, 232, #FF); line_p(G1,202, 232, 202, 0, #FF);

    for i:=1 to 23 do

      for j:=1 to 10 do

        if game(i+1,j+1) then rect_p(G1, j*10+91, i*10-9, j*10+100, i*10, #0); end;

      end;

    end;

 

    while NOT DoesNotFit(game, piece, p) do

      // Draw the background on back buffer

      blit_p(G2, G1);

      // draw the piece

      i:=p;

      rect_p(G2, i*10-(-81,19), i*10-(-90,10), #0);

      for j:=1 to size(piece) do

        i:= i+piece(j);

        rect_p(G2, i*10-(-81,19), i*10-(-90,10), #0);

      end;

      // draw backbuffer on screen

      blit_p(G2);

      // pause

      wait(pause);

      // keys?

      if IsKeyDown(37) then if NOT DoesNotFit(game, piece, p-1) then p:= p-1; end; end;

      if IsKeyDown(39) then if NOT DoesNotFit(game, piece, p+1) then p:= p+1; end; end;

      if IsKeyDown(33) then

        local rotate= piece*(0, 1);

        if NOT DoesNotFit(game, rotate, p) then piece:= rotate; end;

      end;

      // try to go down...

      if DoesNotFit(game, piece, p+(0,1)) then break; else p:= p+(0,1); end;

    end;

    // put piece in game!

    game(im(p), re(p)):= 1;

    for j:=1 to size(piece) do

      p:= p+piece(j);

      game(im(p), re(p)):=1;

    end;

    // remove lines?

    for i:=24 downto 2 do

      if game(i)=[1,1,1,1,1,1,1,1,1,1,1,1] then

        for j:=i-1 downto 2 do game(j+1):= game(j); end;

        game(2):= [1,0,0,0,0,0,0,0,0,0,0,1];

        score:= score+1;

        i:= i+1;

      end;

    end;

    // faster!

    pause:= pause-0.001;

  end;

END;

 

The first Angry Birds program for the HP Prime, by Mic:

 

EXPORT ANGRY_BIRDS()
BEGIN
//By Mickaël Nicotera
local touch;
LOCAL X,Y,A,B,C,S,T,E;
LOCAL W,G,H,J;
LOCAL L1,L2;

S:=0; E:=10; L1:={1,1,1}; L2:={#78FF37h,#303030h}; W:=1; G:=RANDOM(60,170); H:=RANDOM(60,170); J:=RANDOM(60,170);

WHILE E>0 DO

IF irem(S,30)==0 AND S>29 AND E<>10-W THEN W:=W+1; E:=10-W; L1:={1,1,1}; G:=RANDOM(60,170); H:=RANDOM(60,170); J:=RANDOM(60,170); END;

X:=0; Y:=190;

DIMGROB_P(G1,320,220); RECT_P(G1,RGB(73,194,255)); RECT_P(G1,20,200,60,240,RGB(127,70,0),RGB(127,70,0)); FOR I FROM 1 TO 6 DO ARC_P(G1,40,193,7-I,0,360,RGB(244,30,30)); END; FOR I FROM 0 TO 2 DO LINE_P(G1,43,189+I,51,189+I,RGB(255,161,1)); END;

RECT_P(G1,200,G,240,240,RGB(127,70,0),RGB(127,70,0)); FOR I FROM 1 TO 6 DO ARC_P(G1,220,G-6,7-I,0,360,L2(L1(1))); END; RECT_P(G1,240,H,280,240,RGB(127,70,0),RGB(127,70,0)); FOR I FROM 1 TO 6 DO ARC_P(G1,260,H-6,7-I,0,360,L2(L1(2))); END; RECT_P(G1,280,J,320,240,RGB(127,70,0),RGB(127,70,0)); FOR I FROM 1 TO 6 DO ARC_P(G1,300,J-6,7-I,0,360,L2(L1(3))); END;

TEXTOUT_P("Tries = "+E,G1,200,7,1,RGB(255,244,43)); TEXTOUT_P("Score = "+S,G1,250,7,1,RGB(255,244,43)); TEXTOUT_P("ANGRY BIRDS",G1,80,7,3,RGB(255,255,255)); TEXTOUT_P("Power ",G1,25,22,1,RGB(255,0,0)); TEXTOUT_P("By Mic ",G1,138,22,1,RGB(255,255,255));

TEXTOUT_P("Level "+W,G1,118,198,1,RGB(255,255,255));

WHILE ISKEYDOWN(30)<>1 do blit_p(G0,G1,0,0);

touch:=mouse();

LINE_P(52,190,72,Y-20); RECT_P(20,10,20+iquo(X,6),20,RGB(255,0,0),RGB(255,0,0)); WAIT(0.1);

if size(touch(1)) then

IF touch(1,5)==2 THEN

X:=B&#8594;R(touch(1,1)); Y:=B&#8594;R(touch(1,2));

LINE_P(52,190,72,Y-20);

RECT_P(20,10,20+iquo(X,6),20,RGB(255,0,0),RGB(255,0,0));

end; end;

END;

A:=0.008-(230-Y)/70000; B:=2.71+(40-Y)/500+(X-50)/500; C:=305-X/10; T:=0; E:=E-1; TEXTOUT_P("Score = "+S,G1,250,7,1,RGB(255,244,43));

IF (G-19<A*220^2-B*220+C<G+6) AND L1(1)<>2 THEN S:=S+10; L1(1):=2; END; IF (H-19<A*260^2-B*260+C<H+6) AND L1(2)<>2 THEN S:=S+10; L1(2):=2; END; IF (J-19<A*300^2-B*300+C<J+6) AND L1(3)<>2 THEN S:=S+10; L1(3):=2; END;

M:=51; N:=189; FOR I FROM 1 TO 30 DO TEXTOUT_P("o",M,N,1,RGB(255,41,38)); M:=M+10; N:=A*M^2-B*M+C; WAIT(0.2); END;

END;

MSGBOX("Score = "+S);

END;

 

A small Mastermind Program, by Tony Gallo. (Here is a link to the download with the manual: 

 

FilledCircle();

ShowResult();

GuessComplete();

BoxSelectedColor();

ShowSolution();

 

EXPORT Mastermind()

//Mastermind v1.0

//Tony Gallo

//tgallo@tbaytel.com

 

BEGIN

local touch;

LOCAL X,Y;

local ColorX;

local Solution, Guess, SolFlag;

local SolColor, PegColor;

local G;

local B, W;

local I, J;

local choice;

local startcol;

local key;

local message;

 

CHOOSE(choice, "Allow Vacant Pegs?", "Yes", "No");

 

if choice==1 then

   startcol:=0;

else

   startcol:=1;

end;

   

//generate solution

Solution:={0,0,0,0};

FOR I FROM 1 to 4 DO

   Solution(I) := RANDINT(startcol,6);

END;

 

 

//clear screen

RECT_P(0,0,319,239,0,RGB(142,142,142));

 

//credits

TEXTOUT_P("MASTERMIND",10,5,2,RGB(0,0,0));

TEXTOUT_P("v1.0   2013",10,16,1,RGB(0,0,0));

TEXTOUT_P("by Tony Gallo",10,26,1,RGB(0,0,0));

 

 

 

//top rectangle

 RECT_P(95,5,220,35,0,RGB(185,135,105)); 

 

//game board

RECT_P(10,70,310,225,0,RGB(185,135,105)); 

 LINE_P(10,195,310,195,RGB(0,0,0)); 

  

//lines and circles

 FOR X:=1 to 10 DO 

  LINE_P(30*X+10,70,30*X+10,225,RGB(0,0,0)); 

  FOR Y:= 1 to 4 DO 

   ARC_P(30*X-5,30*Y+60,10,RGB(0,0,0)); 

  END; 

  ARC_P(30*X-10,205,3,RGB(0,0,0)); 

  ARC_P(30*X,205,3,RGB(0,0,0)); 

  ARC_P(30*X-10,215,3,RGB(0,0,0)); 

  ARC_P(30*X,215,3,RGB(0,0,0)); 

 END; 

 

//position pointer

TEXTOUT_P("▲",20,222,5,RGB(207,3,124));

 

//selected colour

TEXTOUT_P("Selected Color:",12,50,2,RGB(0,0,0));

 

if choice==1 then

//unselected - brown - 0

FilledCircle(120,53,10,RGB(185,135,105));

ARC_P(120,53,10,RGB(0,0,0));

TEXTOUT_P("CLR",112,49,1,RGB(75,0,130));

end;

 

 

//red - 1

FilledCircle(150,53,10,RGB(255,0,0));

 

 

//green - 2

FilledCircle(180,53,10,RGB(0,255,0));

 

 

//blue - 3

FilledCircle(210,53,10,RGB(0,0,255));

 

 

//yellow - 4

FilledCircle(240,53,10,RGB(255,244,43));

 

 

//black - 5

FilledCircle(270,53,10,RGB(0,0,0));

  

//white - 6

FilledCircle(300,53,10,RGB(255,255,255));

 

//set default color

ColorX := 1;

 

//draw box

LINE_P(105+(ColorX*30),40,135+(ColorX*30),40,RGB(0,0,0));

LINE_P(105+(ColorX*30),66,135+(ColorX*30),66,RGB(0,0,0));

LINE_P(105+(ColorX*30),40,105+(ColorX*30),66,RGB(0,0,0));

LINE_P(135+(ColorX*30),40,135+(ColorX*30),66,RGB(0,0,0));

 

G:=1;

 

Guess:={0,0,0,0};

 

message:=0;

 

WHILE ISKEYDOWN(4)<>1 do

 

wait(.1);

touch:=mouse();

key:=-1;

 

key:=getkey;

 

   if (key >=0 or size(touch(1))) and message==1 then

      RECT_P(225,5,300,35,RGB(142,142,142),RGB(142,142,142));

      message:=0;

   end;

 

      //color selecting using  left and right

     if key==7 and ((choice==1 and ColorX>=1) or (choice==2 and ColorX>=2)) then

       ColorX:=ColorX-1;

   BoxSelectedColor(ColorX);

  continue;

     end;

 

     if key==8 and ColorX<=5 then

       ColorX:=ColorX+1;

   BoxSelectedColor(ColorX);

  continue;

     end;

 

     //Guessing

     if key==30 then

 

         //if no vacant pegs alowed make sure none are vacant

          if choice==2 and (Guess(1)==0 or Guess(2)==0 or Guess(3)==0 or Guess(4)==0) then

              TEXTOUT_P("No vacant pegs",230,10,1,RGB(0,0,0));

              TEXTOUT_P("allowed.",242,22,1,RGB(0,0,0));

              message:=1;

               continue;

         end;

 

        //analyse

        B:=0;

        W:=0;

       SolFlag:={0,0,0,0};

 

       //look for exact matches

       FOR I FROM 1 TO 4 DO

         if Guess(I)==Solution(I) then

                  B:=B+1;

                  Guess(I):=7; //flagged

                  SolFlag(I):=1; //flagged

           end;

       END;

 

      //look for right colour wrong spot

     FOR I FROM 1 TO 4 DO

   if Guess(I)<>7 then

      FOR J FROM 1 TO 4 DO

         if SolFlag(J)==0 AND Guess(I)==Solution(J) then

                     W:=W+1;

             Guess(I):=7;

                  SolFlag(J):=1;

         end;

      END;

   end;

     END;

 

      Guess:={0,0,0,0};

 

        //place black and white pegs

        FOR I FROM 1 to B DO

   ShowResult(I, RGB(0,0,0),G);

        END;

 

        FOR I FROM B+1 to B+W DO

   ShowResult(I, RGB(255,255,255),G);

        END;

 

       if B==4 then

   TEXTOUT_P("You win!",250,16,2,RGB(0,0,0));

   ShowSolution(Solution);

                           break;

       end;

 

        if G==10 then

   TEXTOUT_P("You lose!",250,16,2,RGB(0,0,0));

   ShowSolution(Solution);

                           break;

        end;

 

        G:=G+1;

         RECT_P(10,230,310,235,RGB(142,142,142)); 

        TEXTOUT_P("▲",(30*(G-1))+20,222,5,RGB(207,3,124));

  continue;

   end;

 

  if size(touch(1)) then

    if  touch(1,5)==0 then

      X:=B→R(touch(1,1));

      Y:=B→R(touch(1,2));

 

     //color selector

      if 110<=X<=310 and 43<=Y<=63 THEN

 

         if 110<=X<=130 and choice==1 then ColorX := 0 END; //unselected - brown

         if 140<=X<=160 then ColorX := 1  END; //red

         if 170<=X<=190 then ColorX := 2  END; //green

         if 200<=X<=220 then ColorX := 3  END; //blue

         if 230<=X<=250 then ColorX := 4  END; //yellow

         if 260<=X<=280 then ColorX := 5  END; //black

         if 290<=X<=310 then ColorX := 6  END; //white

 

        BoxSelectedColor(ColorX);

  continue;

      END;

 

 

     //placing pegs

      if (30*(G-1))+10<=X<=(30*(G-1))+40 and 80<=Y<=190 THEN

                        

      if ColorX == 0 then PegColor:=RGB(185,135,105) END;

     if ColorX == 1 then PegColor:=RGB(255,0,0) END;

    if ColorX == 2 then PegColor:=RGB(0,255,0) END;

     if ColorX == 3 then PegColor:=RGB(0,0,255) END;

     if ColorX == 4 then PegColor:=RGB(255,244,43) END;

     if ColorX == 5 then PegColor:=RGB(0,0,0) END;

     if ColorX == 6 then PegColor:=RGB(255,255,255) END;

   

    if 80<=Y<=100 then

          Guess(4):=ColorX;

       FilledCircle((30*(G-1))+25,90,9,PegColor);

  continue;

   END;

 

    if 110<=Y<=130 then

          Guess(3):=ColorX;

          FilledCircle((30*(G-1))+25,120,9,PegColor);

  continue;

    END;

 

    if 140<=Y<=160 then

           Guess(2):=ColorX;

           FilledCircle((30*(G-1))+25,150,9,PegColor);

  continue;

     END;

 

 

    if 170<=Y<=190 then                                 

          Guess(1):=ColorX;

          FilledCircle((30*(G-1))+25,180,9,PegColor);

  continue;

    END;

 

   END;

 

    end;

 

  end;

END;

 wait();

END;

 

FilledCircle(X,Y,Radius,Color)

begin

local I;

 

    FOR I FROM 0 TO Radius DO

    ARC_P(X,Y,I,Color);

    END;

end;

 

ShowResult(I, Color, G)

begin

   if I==1 then FilledCircle(30*G-10,205,2,Color); end;

     if I==2 then FilledCircle(30*G,205,2,Color);  end;

     if I==3 then FilledCircle(30*G-10,215,2,Color); end;

     if I==4 then FilledCircle(30*G,215,2,Color); end;

end;

 

BoxSelectedColor(ColorX)

begin

           //clear old box wherever it may be

          LINE_P(105,40,315,40,RGB(142,142,142));

          LINE_P(105,66,315,66,RGB(142,142,142));

           FOR I FROM 0 to 8 DO

                LINE_P(105+(I*30),40,105+(I*30),66,RGB(142,142,142));

          END;

 

          //draw box

          LINE_P(105+(ColorX*30),40,135+(ColorX*30),40,RGB(0,0,0));

          LINE_P(105+(ColorX*30),66,135+(ColorX*30),66,RGB(0,0,0));

          LINE_P(105+(ColorX*30),40,105+(ColorX*30),66,RGB(0,0,0));

          LINE_P(135+(ColorX*30),40,135+(ColorX*30),66,RGB(0,0,0));

end;

 

ShowSolution(Solution)

begin

local SolColor;

FOR I FROM 1 to 4 DO

  if Solution(I) == 0 then SolColor:=RGB(185,135,105) END; //unselected - brown

  if Solution(I) == 1 then SolColor:=RGB(255,0,0) END; //red

  if Solution(I) == 2 then SolColor:=RGB(0,255,0) END; //green

  if Solution(I) == 3 then SolColor:=RGB(0,0,255) END; //blue

  if Solution(I) == 4 then SolColor:=RGB(255,244,43) END; //yellow

  if Solution(I) == 5 then SolColor:=RGB(0,0,0) END; //black

  if Solution(I) == 6 then SolColor:=RGB(255,255,255) END; //white

 

 

   ARC_P(82+(I*30),20,10,RGB(0,0,0));

  FilledCircle(82+(I*30),20,9,SolColor);

END;

end;