KarelPasGtk
-----------------

KarelPasGtk adds commands of programming language Karel into Pascal.
The programming language Karel is intended for learning of programming.
We control the movement of robot Karel using commands
 move, turnLeft ... 
In comparsion with classical versions of Karel there are many
other possibilities:
inserting images, keyboard control, more Karels ... 

Simple editor qek enables insert Karel's commands from menu and
it immediately runs the programs.

KarelPasGtk exists in Linux and M$ Win32 version.



REQUIREMENTS:

Linux, X windows, gtk+
(or M$ Win32 and dll libraries gtk2)

and installed freepascal 2.x: http://www.freepascal.org/



INSTALL:

Extract zip file with subdirectories k_units and examples.
The executable file for Linux is named "qek", for M$ Windows it is "qek.exe".
The Directory k_units must be a subdirectory of the directory,
where qek executable is.
When you are compiling your Karel-pascal program for the first time
you need to have right for writing to the directory k_units. 
It is necessary to put the full path to freepascal compiler ppc386
in setting of the program.


In Linux it is recommended to run qek from xterm, because the program
writes there some messages and if the program crashes 
it can be terminated by ctrl-C.


For M$ Win it is necessary to have dll libraries gtk2.
You can download it from http://members.lycos.co.uk/alexv6/ 



LOCALIZATION:

Another language versions you can obtain by translating
the configuration file.
In menu you select options-save_ options.
The file .qek will be created in home directory.
You can translate this file and if you want you can rename it into
qek.cfg and place it into directory where the executable qek is.
Then it is possible to create program unit containing translated
procedure names simillary as the translation into Czech is
in the directory "cesky".



EXAMPLES:

In the directory examples we can find some examples of codes.
1-maze: simple program for going through a maze.
2-fill: filling of an area with marks using recursion.
3-allfunctions: shows all the special functions,
  keyboard control is explained in the output on the terminal 
  after the program is launched
4-morekarels: example of movement of more Karels at a time,
  Karel 6 can be controled by arrows on keyboard
snake: simple game snake
6-pinguin: game with pinguin and bears, a few levels.



USAGE:

Karel's commands and basic Pascal structures can be inserted 
from the menu. The structure as "if..then" or "while..do" 
can be applied for selected block.
                                                                                
Quick example:
menu:  Pascal->head,
       Karel-basic->move,  Karel-basic->turnLeft, Karel-basic->move
button: save>compile>run





Basic Karel's commands:


kInit(width, height) 
 - it is necessary to call this at the begining. 
   It sets width and height of Karl's area. Width and height are numbers
   of the cells.
   
move, turnLeft, turnRight  
 - moving and turning of robot Karel 
 
put, get
 - robot Karel puts under himself a mark or he gets it from there
isWall, isMark 
 - It tests whether there is a wall in front of him or a mark under him
 
isNorth, isWest ...
 - it tests the direction of Karel's face




Further commands:


moveToWall
 - Karel enters the field where a wall is         

buildWall, destroyWall
 - Karel builds (destroys) a wall under himself

isOnWall
 - It tests whether there is a wall under Karel

isOut
 - It tests whether there is the rim of Karel's area in front of Karel
 (the test isWall can't distinguish the rim of the area and a wall inside)

key
 - the function which returns the pressed key. For instance 'a' 'X' or ' '. 
	 It returns the string 'enter' for the key Enter,
	 the string 'esc' for the key Esc
	 and the string 'up' 'down' 'left' 'right' for the arrows
	 
waitKey 
 - it waits for the key press
 
kExit 
 - it terminates the program
 
manualControl
 - it allows you to move Karel using the keys, to put marks and build walls 
 
kSaveAll('file_name')
 - saves all into the file: walls, marks, positions of karels...
 
kLoadAll('file_name') 
 - restores all from the file

krestart
 - it sets all the values as they were on Karel's start

sumMarks, sumWalls
 - returns number of all marks, walls

kSetxy(x,y) kSetdir(dir)
 - directly set karel's position and direction.
   (ksetdir(1) sets direction to East ...) 

kdialog('text')
 - it shows a dialog window. If the text ends with '?'
   there will be two buttons [yes] and [No]. If you press [Yes]
   the function returns true.
   For instance: 
   if kdialog('What will you press?') then writeln('You have pressed yes');
   If the text doesn't end with '?' only button [Ok] will be shown.




The speed of Karel:


kQuick
 - sets the speed of Karel's moving to maximum 

KNormal
 - sets the normal speed

It is possible to set the speed of Karel using variables:
kDelay - the time which one step takes aproximately in 1/100 s
kMinisteps - the number of steps in animation of moving Karel 
          from one cell to another
  
  


The commands for manipulation with pictures:


All pictures have to be in xpm format (create them using gimp or convert
them  with another program which is able to handle xpm format).
The pictures should be squares (except of the picture of the backgroung)
They can be other size than 30x30 (it is the width and height of one cell)

background('file_name')
 - shows a picture on the background.
background('RRRGGGBBB')
 - fills background with color, for instance background('999000000'); is red.
 
drawpic('file_name')
 - Karel draws a picture under himself 

loadWall('file_name')
 - reads the picture of the wall which will be drawn
   when the procedure builtWall is called 

loadMarks('xpic')
 - reads the files xpic1.xpm, xpic2.xpm ... xpic9.xpm, xpicX.xpm,
   which will be used when the command put is called to show 
   how many marks there are.                           
   
loadKarel('xpic')
 - reads the files xpicN.xpm, xpicE.xpm, xpicS.xpm, xpicW.xpm
    and uses them to show Karel in different directions.



Using more Karels


There is 7 of Karels with numbers k= 0,1,2,3,4,5,6,

kSwitch(k) 
 -  switches which Karel will be controled                  

KShow, kHide
 - shows or hides Karel

isVisible
 - test whether active Karel is visible

isKarel(k) 
- tests whether there is Karel number k on the position of active Karel

For moving all Karels at a time it is necessary 
to set the variable kAutoexecute as false. 
Then all Karel's commands will not be shown immediately 
but will be shown after the procedure kExecute is called.






LICENCE:

(c) 2004-2005 Jirka Bubenicek  - hebrak@yahoo.com 
GNU GENERAL PUBLIC LICENSE
