Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prj10072021;
- import java.util.Scanner;
- public class Game {
- Player player1, player2;
- Die d;
- int boardSize;
- Player currentPlayer;
- Scanner in = new Scanner(System.in);
- public Game(String name1, String name2, int boardSize) {
- this.player1 = new Player(name1);
- this.player2 = new Player(name2);
- this.boardSize = boardSize;
- d = new Die();
- if (d.getNum() % 2 == 0) {
- currentPlayer = player1;
- } else {
- currentPlayer = player2;
- }
- }
- public String startGame() {
- while (player1.getPos() < this.boardSize && player2.getPos() < this.boardSize) {
- System.out.println(currentPlayer.getName() + " take a move");
- in.next();
- d.roll();
- int steps = d.getNum();
- currentPlayer.move(steps);
- int newPos = hasLeader(currentPlayer.getPos());
- if (newPos != currentPlayer.getPos()) {
- currentPlayer.move(newPos - currentPlayer.getPos());
- }
- newPos = hasSnake(currentPlayer.getPos());
- if (newPos != currentPlayer.getPos()) {
- currentPlayer.move(newPos - currentPlayer.getPos());
- }
- if (currentPlayer == player1) {
- currentPlayer = player2;
- } else {
- currentPlayer = player1;
- }
- }
- if (player1.getPos() >= this.boardSize) {
- return player1.getName();
- } else {
- return player2.getName();
- }
- }
- public int hasLeader(int n) {
- if (n == 5)
- return 13;
- if (n == 12)
- return 25;
- return n;
- }
- public int hasSnake(int n) {
- if (n == 17)
- return 10;
- if (n == 29)
- return 14;
- return n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement