记住玩家对象的先前位置

时间:2016-02-26 02:52:35

标签: java java.util.scanner stddraw

好的,所以我正在尝试使用扫描仪创建一个程序,如果用户键入“向上”,“向下”,“向左”或“向右”,则形状将相应移动。我的形状随着文字的说法移动,但每当我输入一个新命令时,我都无法让程序记住在给出新命令之前形状的位置。每次进入新方向时,形状都从0,0开始。以下是我到目前为止的情况,我认为问题在于我的y坐标:

 double location = 0;
 double prev = 0;     
 for (double i = -10; i <= 10; i++) // for the scale that was set 
 {
  String word = in.nextLine(); // new string: word = user typed

  if (word.equals("up")) // if word = up, move player up
  {
    location ++;
    prev -= location;
    StdDraw.clear();
    drawTarget(a);
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledCircle(prev, location, 0.5);

  }

 else if (word.equals("down")) // if word = down, move player down
  {
    location--;
    prev += location;
    StdDraw.clear();
    drawTarget(a);
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledCircle(prev, location, 0.5);

  }
 }

0 个答案:

没有答案