0

I'm creating a game in Scala using ScalaSwing, where I've refactored the code into MVC format.

The problem arises when I try to "set" Player 1 strategy to the power strategy, when it throws

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

I'm not sure how exactly to fix this error, and I'm hoping somebody could help me.

Below is where the error occurs,at 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")
    })
  }
})

Here is how the singleton object PlayerOrder is defined:

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
  }
}

}

And finally the function set:

def set(player: model.Player, keyword: String) {
    player.setStrat(keyword)
}
Michael
  • 21
  • 2
  • Is the `Player` class you use inside `PlayerOrder` the same as `model.Player`? – mfirry Apr 09 '17 at 03:21
  • I agree with @mfirry, do you have multiple `Player` classes defined? Your function requires a Controller.model.Player from what I can read. It's hard to answer without more information about your project structure. – alamit Apr 09 '17 at 12:48
  • @mfirry - yes, `Player` is a class defined within `model` and `PlayerOrder` is an object also defined within `model`. @AdrienLamit - No, there is only one Player class defined. – Michael Apr 09 '17 at 14:08

0 Answers0