小编Tou*_*own的帖子

去教程选择语句

我正在浏览tour.golang.org上的示例,我遇到过这个我不太懂的代码:

package main
import "fmt"

func fibonacci(c, quit chan int) {
    x, y := 0, 1
    for {
        select {
        case c <- x: // case: send x to channel c?
            x, y = y, x+y
        case <-quit: // case: receive from channel quit?
            fmt.Println("quit")
            return
        }
    }
}

func main() {
    c := make(chan int)
    quit := make(chan int)
    go func() { // when does this get called?
        for i := 0; i < 10; i++ {
            fmt.Println(<-c)
        } …
Run Code Online (Sandbox Code Playgroud)

channel go switch-statement

7
推荐指数
2
解决办法
1939
查看次数

摇摆简单叠加

我正在制作一个2D游戏,其中玩家在迷宫中漫游。 GUI的屏幕截图

我想实现某种“黑暗度”,甚至像被黑色包围的玩家周围的透明形状一样简单,例如: 模拟屏幕截图

我发现使用Swing的问题是,尽管这是可能的,但它意味着必须重新绘制所有内容,这会在每次发生时产生令人讨厌的“闪烁”效果。有没有一种方法可以进行某种形式的叠加,或者只是在Swing中进行叠加的一种好方法?我现在对GUI /可视化工具还没有足够的经验,所以如果可能的话,我想坚持使用Swing。

编辑:这是我的方法来绘制背景,即地板,墙壁和出口:

    public final void paintBG(Graphics g){
    g.setColor(Color.LIGHT_GRAY); // Screen background
    g.fillRect(0, 0, getWidth(), getHeight());
    // Draw the Walls of the maze
    // scalex and y are for scaling images/walls within the maze since I let users specify how big they want the maze
    for (int j = 0; j < this.height; j++, y += scaley) {
        x = 20;
        for (int i = 0; i < this.width; i++, x += scalex) {
            if (!(maze[j][i].northwall.isBroken())) // If …
Run Code Online (Sandbox Code Playgroud)

java graphics swing

5
推荐指数
1
解决办法
520
查看次数

Clojure - 获取向量向量内的数据

我有一个向量向量,其中包含一些字符串和整数:

(def data [
["a" "title" "b" 1]
["c" "title" "d" 1]
["e" "title" "f" 2]
["g" "title" "h" 1]
])
Run Code Online (Sandbox Code Playgroud)

我试图迭代向量并返回(?)包含特定字符串(例如“a”)的任何行。我尝试实现这样的事情:

(defn get-row [data]
  (for [d [data]
        :when (= (get-in d[0]) "a")] d
  ))
Run Code Online (Sandbox Code Playgroud)

我对 Clojure 很陌生,但我相信这是在说:对于“data”中的每个元素(向量),如果该向量包含“a”,则返回它?

我知道 get-in 需要 2 个参数,这部分是我不确定该怎么做的地方。

我看过这样的答案但我不太明白它们是如何工作的。据我所知,他们正在将矢量转换为地图并对其进行操作?

clojure lighttable

3
推荐指数
1
解决办法
707
查看次数

标签 统计

channel ×1

clojure ×1

go ×1

graphics ×1

java ×1

lighttable ×1

swing ×1

switch-statement ×1