JuliaKara.jl
v0.3.0
一个是Swisseducs Kara港口的包装(德语页面)。 Kara是一个容易进入编程世界的概念。卡拉(Kara)是一个小瓢虫,生活在蘑菇,树木和叶子的森林中。卡拉可以移动单个蘑菇,放置和去除叶子,不能移动树木,并且完全使用朱莉娅代码控制。与原始KARA相比,互动男子气概的重点是使用REPL。
使用PKG Replode中的Julia安装
add JuliaKara或在朱莉娅(Julia)0.6中使用
Pkg . add ( " JuliaKara " )通过打开Julia并using JuliaKara进入REPP,开始使用Juliakara。接下来,通过输入@World (10,10)创建一个具有函数绑定的大小10x10的新世界。
您现在可以使用
move(kara)迈出迈向卡拉面对的方向,turnLeft(kara)向左转,turnRight(kara)右转Kara,putLeaf(kara)将叶子放在Kara和removeLeaf(kara)从卡拉下面去除一片叶子和
treeFront(kara)检查Kara是否站在树的前面,treeLeft(kara)检查是否有Kara剩下的一棵树,treeRight(kara)检查是否有Kara的树,onLeaf(kara)检查Kara下面是否有叶子mushroomFront(kara)检查卡拉是否站在蘑菇前。Juliakara意识到原始Kara用于将世界存储在文件中的XML语法。可以通过GUI或命令@World [path]加载世界。与GUI版本@World [path]相反,打开了一个新窗口,并在全球范围中注册world和kara作为参考。
@World " file1.world "
move (kara) # moves Kara in world from file1.world
@World " file2.world "
# kara and world referencing elements from file1.world
# are now overwritten with references to elements from file2.world
move (kara) # moves Kara in world from file2.world
# Create additional references to world and kara
world_save = world
kara_save = kara
@World " file3.world "
# kara and world referencing elements from file2.world
# are now overwritten with references to elements from file3.world
move (kara) # moves Kara in world from file3.world
# Access stored references
move (world_save,kara_save) # moves Kara in world from file2.world如果一个人通过GUI加载世界并想要上述行为,则必须通过以下方式恢复对Kara的引用。
kara = get_kara (world) Juliakara支持多个世界和多个卡拉斯。如果您想复制该示例在Juliakara的测试目录中运行,例如~/.Julia/v0.6/JuliaKara/test 。
# Load the world contained in example.world.
# This also creates a macro @w1 in global scope to interact with
# the world
@World w1 " example.world "
# Create an empty world w2
@World w2 ( 10 , 2 )
# Place kara in the empty world.
# place_kara() returns a reference to the placed kara.
# @w2 place_kara(1,1) is just syntactic sugar for place_kara(w2,1,1)
kara = @w2 place_kara ( 1 , 1 )
# Kara is already placed in world w1, therefore we fetch it with get_kara()
# Since we can't create two kara references we use lara instead.
lara = @w1 get_kara ()
# Move lara a step in world w1
@w1 move (lara)
# Alternatively:
move (w1,lara)
# Move kara a step in world w2
@w2 move (kara)
# It's even possible to allow kara from world w2 to
# place something in world w1
@w1 putLeaf (kara)
reset!(world) :加载后将world重置为州或store!(world) 。store!(world) :存储当前的world状态。place_kara(world,X,Y,orientation) :将Kara world在X , Y面向orientation 。有效的方向是:NORTH , :EAST :SOUTH :WEST 。 orientation是可选的,默认为:NORTH 。place_mushroom(world,X,Y) :在X , Y world上放置蘑菇。place_tree(world,X,Y) :在X , Y处将一棵树放在world上。place_leaf(world,X,Y) :在X , Y world中放置一片叶子。上面使用的宏进行交互,例如@w1基本上将@w1 f(args...)转换为f(w1,args...) 。因此,由于上述所有方法都将world作为他们的第一个论点,也可以使用世界宏来称呼它们。这也适用于自定义方法:
function turnAround (wo,ka)
turnLeft (wo,ka)
turnLeft (wo,ka)
end
@w1 turnAround (lara)Juliakara的示例页面包含进一步的材料,显示了Juliakara的用法。