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 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的用法。