player1Turn()不会返回所需的值

时间:2015-02-02 15:31:23

标签: java

player1Turn()一直说,无论我输入什么,temp = 0. temp应该是他们选择的坑,但是数字,所以我可以返回temp并在数组中使用它。另外,我知道需要有一个return语句来完成这个方法,但是现在我只是试图让temp达到我想要的水平。对整件事的建议值得欢迎,但我主要关注的是player1Turn()。感谢

   import java.util.*;

public class Mancala
{
  Scanner input = new Scanner(System.in);
  public static void main(String[]args)
  {
    Mancala mancala = new Mancala();
    int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
    System.out.print(" ");
    mancala.display(board);
    System.out.print(" ");
    mancala.player1Turn();

  }
  public static void display(int[] board)
{
    System.out.println(" A  B  C  D  E  F");
    System.out.print(" ");
  for(int i = 13; i >=8; i--)
  {
    System.out.print(" "+board[i]+" ");
  }
  System.out.println("\n"+board[0]+"                  "+board[7]);
  System.out.print(" ");
  for(int i = 6; i >=1; i--)
  {
    System.out.print(" "+board[i]+" ");
  }
  System.out.println("\n  G  H  I  J  K  L");
}
public void player1Turn()
{
  int temp = 0;
  System.out.print("Which pit would you like to select? ");
  String pit = input.nextLine();
  {
  if(pit == "A")
    temp = 13;
  else if(pit == "B")
    temp = 12;
  else if(pit == "C")
    temp = 11;
  else if(pit == "D")
    temp = 10;
  else if(pit == "E")
    temp = 9;
  else if(pit == "F")
    temp = 8;
  else
    System.out.print("That is not a valid pit!");
  }
  System.out.print(temp);
}
}

0 个答案:

没有答案