Re: MINESWEEPER for the HP PRIME Message #11 Posted by cyrille de Brébisson on 10 Dec 2013, 8:33 a.m., in response to message #1 by Tony Gallo
Hello,
Nice work...
I had a quick look at the code and here are some comments:
(Note: since HPPL is a new language, what you write might end up being used by others as example code, as a result, it would pay for it to be as 'clean' as possible!)
- Look at the ICON documentation (in online help). It is used to creae sprites and bitmaps for use in programs. It will allow you to create better graphics with faster on screen drawing and less code.
you can download the ICON creator helper program at: http://h30499.www3.hp.com/hpeb/attachments/hpeb/bsc-408/14143/1/lodepng.zip
- Look at the makelist instruction. It is very powerfull! Anytime you need to create a list (either in a for loop or even staticaly), see if it can be used.
For example, minefield:={10,10,10,.....,10,10,10,10,10};
can be replaced by minefield:=makelist(10,1,100);
- more on list:
case
if bombcount == 0 then color := RGB(100,20,250); end;
if bombcount == 1 then color := RGB(1,0,254); end;
if bombcount == 2 then color := RGB(1,127,1); end;
if bombcount == 3 then color := RGB(254,0,0); end;
if bombcount == 4 then color := RGB(1,0,128); end;
if bombcount == 5 then color := RGB(129,1,2); end;
if bombcount == 6 then color := RGB(0,128,129); end;
if bombcount == 7 then color := RGB(0,0,0); end;
if bombcount == 8 then color := RGB(128,128,128); end;
end;
can be replaced by a list lookup:
local MyListOfCOlor= { RGB(100,20,250), ...}; // you could even have the list a global non exported variable. even faster.
color=MyListOfCOlor(bombcount+1);
- Avoid mixing CAS with non cas programs. look at the MOD and IP/FP functions as replacements for irem and iquo
I := irem(index-1,10);
J := iquo(index-1,10);
- look at the WAIT(-1) command. this is what you should use to wait for key presses/mouse events as it is low power consumption and returns all the info you want/need.
Cheers, Cyrille
Edited: 10 Dec 2013, 8:33 a.m.
|