gpt4 book ai didi

smalltalk - 睡在 Smalltalk Squeak 中

转载 作者:行者123 更新时间:2023-12-04 00:10:14 25 4
gpt4 key购买 nike

我正在处理 N*N 皇后问题及其图形用户界面。我想每次移动都睡几秒钟,这样观众就可以看到这个过程。如何让 smalltalk 休眠?

谢谢

最佳答案

你可以等待而不是 sleep 。

5 seconds asDelay wait.

例如如果您选择并打印以下内容,它将等待 5 秒,然后打印结果 (2)

[
5 seconds asDelay wait.
1 + 1
] value

Delay 类的注释解释了它的作用。

I am the main way that a process may pause for some amount of time. The simplest usage is like this:

(Delay forSeconds: 5) wait.

An instance of Delay responds to the message 'wait' by suspending the caller's process for a certain amount of time. The duration of the pause is specified when the Delay is created with the message forMilliseconds: or forSeconds:. A Delay can be used again when the current wait has finished. For example, a clock process might repeatedly wait on a one-second Delay.

A delay in progress when an image snapshot is saved is resumed when the snapshot is re-started. Delays work across millisecond clock roll-overs.

For a more complex example, see #testDelayOf:for:rect: .

更新:(基于评论)

wait 将暂停执行流程,这意味着在前面的示例中,只有在等待时间结束后,1 + 1 才会执行(执行流程恢复)结束了。

所以在你的类里面你可以...

MyBoard>>doStep
self drawBoard.
5 seconds asDelay wait.
self solve.
5 seconds asDelay wait.
self destroyBoard.

关于smalltalk - 睡在 Smalltalk Squeak 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37053038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com