Graphics 尝试使用图形库Ocaml移动圆
我是ocaml新手,尝试使用ocaml图形库移动一个圆。 这是我做的,但它不起作用。它应该持续无限长的时间,因为“while true”,但它不起作用,我无法提供输入Graphics 尝试使用图形库Ocaml移动圆,graphics,ocaml,Graphics,Ocaml,我是ocaml新手,尝试使用ocaml图形库移动一个圆。 这是我做的,但它不起作用。它应该持续无限长的时间,因为“while true”,但它不起作用,我无法提供输入 #load "graphics.cma";; #load "unix.cma";; Graphics.open_graph " 800x250";; Graphics.remember_mode true;; Graphics.set_color 100;; Graphics.foreground;; let player =
#load "graphics.cma";;
#load "unix.cma";;
Graphics.open_graph " 800x250";;
Graphics.remember_mode true;;
Graphics.set_color 100;;
Graphics.foreground;;
let player = [|40;80;10|];;
Graphics.fill_circle player.(0) player.(1) player.(2);;
let rec check button =
if button = 'w'
then
player.(0) <- player.(0) + 50;
Graphics.fill_circle player.(0) player.(1) player.(2);
while true do
let s = Graphics.wait_next_event [Graphics.Button_down; Graphics.Key_pressed]
and bo=Graphics.key_pressed ()
in if not bo then check s.Graphics.key;
done;;
#加载“graphics.cma”;;
#加载“unix.cma”;;
Graphics.open_图形“800x250”;;
Graphics.memory_mode true;;
Graphics.set_color 100;;
图形。前景;;
让玩家=[40;80;10];;
图形填充圆播放器。(0)播放器。(1)播放器。(2);;
让记录检查按钮=
如果按钮='w'
然后
玩家。(0)以下是问题的原因:
Graphics.fill_circle player.(0) player.(1) player.(2);
^^^^^^^
here should be a double semicolon
如果没有第二个分号,则while表达式被视为
作为检查
功能的一部分,适当的缩进说明了这一点:
let rec check button =
if button = 'w'
then
player.(0) <- player.(0) + 50;
Graphics.fill_circle player.(0) player.(1) player.(2);
while true do
let s = Graphics.wait_next_event [Graphics.Button_down; Graphics.Key_pressed]
and bo=Graphics.key_pressed ()
in if not bo then check s.Graphics.key;
done
使用以下命令编译并运行它
ocamlbuild -pkg graphics graph.native --
“它不起作用”是对这个问题的一个相当笼统的描述。如果你表现出某种输出可能会有所帮助。这看起来像是要在顶层运行的代码。那么,在你输入每一行之后,你能展示toplevel是怎么说的吗?你能解释一下,当我向前移动并创建一个新的圆圈时,我如何删除上一个圆圈吗。谢谢你之前的回答。
ocamlbuild -pkg graphics graph.native --