Java - StringIndexOutOfBoundsException en scala

 
Vista:

StringIndexOutOfBoundsException en scala

Publicado por fernando (1 intervención) el 05/06/2016 01:35:53
Buenas noches, me presento en el foro, Soy Fernando, un estudiante de teleco, soy un novato en la programacion orientada a objetos y en java, y empece a aprender scala porque me parece mas facil en algunos casos, tengo solo un objeto principal y una clase punto con dos metodos y solo quiero mover el punto correctamente pero ni me lo actualiza ni se como seguir, llevo todo el dia con esto y estoy exhausto... lo dejo en sus manos por hoy.. gracias y buenas noches.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Point(xc: Int, yc: Int) {
  var x: Int = xc
  var y: Int = yc
  def moved(dx: Int, dy: Int) {
    x = x + dx
    y = y + dy
  }
  def movimiento(dd: Char) {
    if ( dd == 'w' ) {
      y = y + 1
    }else if (dd == 's') {
      y = y - 1
    }else if(dd == 'a') {
      x = x - 1
    }else if (dd == 'd') {
      x = x + 1
    }
       }
}
 
object move extends JFXApp{
 
    val pt = new Point(10, 10)
    stage = new JFXApp.PrimaryStage {
      title.value = "when/choose/otherwise"
      width = 500
      height = 500
      scene = new Scene {
        fill = Color.Green
        content = new Rectangle {
          x = pt.x
          y = pt.y
          width = 10
          height = 10
          fill = Color.GhostWhite
          var c = readChar()
          println("Press any key to start:")
          while(true)
          {
            c = readChar()
            pt.movimiento(c)
            println("("+pt.x+","+pt.y+")")
          }
        }
      }
    }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder