mikhail_dvorkin icon

NimConsoleView

mikhail_dvorkin | PRO | 02/27/17 05:47:42 AM UTC | 0 ⭐ | 761 👁️ | Never ⏰ | []
Java |

540 B

|

None

|

0 👍

/

0 👎

package me.dvorkin;
 
import java.util.Arrays;
import java.util.Scanner;
 
public class NimConsoleView {
    NimModel model;
    Scanner in = new Scanner(System.in);
 
    public NimConsoleView(NimModel model) {
        this.model = model;
    }
 
    public int[] interact() {
        System.out.println("Field: " +
                Arrays.toString(model.getField()));
        int player = model.whoMoves() ? 1 : 2;
        System.out.println("Player " + player + ", make your move:");
        int index = in.nextInt() - 1;
        int amount = in.nextInt();
        return new int[]{index, amount};
    }
}

Comments