0

我正在使用 ScalaSwing 在 Scala 中创建游戏,我已将代码重构为 MVC 格式。

当我尝试将玩家 1 策略“设置”为权力策略时,问题就出现了,当它抛出

type mismatch;found _16.Player required _2.model.Player where val _2:controller.Controller

我不确定如何准确修复此错误,我希望有人可以帮助我。

下面是发生错误的地方,在controller.set(playerOrder(0),"power")

  contents += new Button(Action("Set Player 1 Strategy"){
  val playerOrder = model.PlayerOrder
  playerOrder.reset
  val pop = new PopupMenu {
    contents += new Button(Action("Power Strategy"){
      controller.set(playerOrder(0),"power")
    })
  }
})

以下是单例对象 PlayerOrder 的定义方式:

object PlayerOrder extends scala.collection.mutable.Queue[Player] {

this += new Player("Michael","B",(1,0))
this += new Player("Mike","O",(0,-1))
this += new Player("Mikey","G",(-1,0))
this += new Player("Jim","R",(0,1))

def advance {
  this += this.dequeue
}

def show : String = {
  var result = ""    
  for (p <- this.toArray) 
    result += p.name + ", "
  result.substring(0, result.length-2)
}

def current: Player = this.front

def update {
  for(player<- this){
    if(!player.is_alive){
      for((k,v) <- player.marble_locations){
        board(v._1)(v._2).reset
      }
    this.dequeue
    }
  } 
}

def reset {
this += new Player("Michael","B",(1,0))
this += new Player("Mike","O",(0,-1))
this += new Player("Mikey","G",(-1,0))
this += new Player("Jim","R",(0,1))
  while (this.size > 4){
    this.dequeue
  }
}

}

最后是功能set

def set(player: model.Player, keyword: String) {
    player.setStrat(keyword)
}
4

0 回答 0