Вы находитесь на странице: 1из 4

import java.util.ArrayList; //import java.util.HashMap; import java.util.HashSet; import java.util.Random; import acm.program.*; //import javax.swing.

*; public class Main extends acm.program.ConsoleProgram { private static final ArrayList<String> board = new ArrayList<String>(); //private HashMap<String, String> hareCard = new HashMap<String, String>(); private HashSet<String> hareCards = new HashSet<String>(); //Remove HashSet and use ArrayList to add Hare Cards. private ArrayList<String> hareDeck = new ArrayList<String>(); private ArrayList<Player> players = new ArrayList<Player>(); private HashSet<Integer> carrotCards = new HashSet<Integer>(); private ArrayList<Integer> carrotDeck = new ArrayList<Integer>(); //private ArrayList<int> carrotDeck(); private private private private private 3}; private int[] lettuceTiles = {10, 22, 42, 57}; private int[] tortoiseTiles = {11, 15, 19, 24, 30, 37, 43, 50, 56}; private int[] numberTiles = {4, 7, 8, 9, 12, 16, 17, 18, 20, 23, 27, 28, 29, 32, 35, 36, 41, 44, 45, 47, 48, 52, 53, 54, 60}; /*public Main() { }*/ public void carrotDeck() { /*for(int i = 0; i <= 500; i++) { Random generator = new Random(); int carrot = generator.nextInt(60); carrotDeck.add(carrot); }*/ carrotCards.add(1); carrotCards.add(2); carrotCards.add(5); carrotCards.add(10); carrotCards.add(15); carrotCards.add(20); carrotCards.add(30); carrotCards.add(60); for(Integer card : carrotCards) { carrotDeck.add(card); } } public void addCarrots(int player, int n) { int numberOfPlayers; int startTile = 0; int finishTile = 64; int[] hareTiles = {1, 3, 6, 14, 25, 31, 34, 39, 46, 51, 58, 62}; int[] carrotTiles = {2, 5, 13, 21, 26, 33, 38, 40, 49, 55, 59, 61, 6

for(int i = 0; i < n; i++) { Random generator = new Random(); int chosen = generator.nextInt(8); players.get(player).setCarrots(players.get(player).getCarrots() + 1) ; } } public void addPlayer() { if(players.size() <= 6) { String name = readLine(); Player player = new Player(name); players.add(player); if(players.size() < 2) { println("At least two players required to start."); } } else println("Max number of players reached."); } public void setHareCards() { /* hareCard.put("1", "Lose half your carrots - if an odd number, keep th e odd one."); hareCard.put("2", "Restore your carrot holding to exactly 65 - if you ha ve more than 65, pay extras to the carrot patch, if fewer draw extras from carro t patch"); hareCard.put("3", "Shuffle hare cards and receive from each player one c arrot."); hareCard.put("4", "If there are more players behind you than in front of you, miss a turn. If not, play again."); hareCard.put("5", "Give 10 carrots to each player lying behind you in th e race - if you haven't enough give them five each."); hareCard.put("6", "Free Ride! - Your last turn costs nothing, retrieve t he carrots you paid to reach the square."); hareCard.put("7", "Draw ten carrots for each lettuce you still hold - If you have none left, miss a turn."); hareCard.put("8", "Lose half your carrots - If an odd number, keep the o dd one."); */ hareCards.add("Lose half your carrots - if an odd number, keep the odd o ne."); hareCards.add("Restore your carrot holding to exactly 65 - if you have m ore than 65, pay extras to the carrot patch, if fewer draw extras from carrot pa tch."); hareCards.add("Shuffle hare cards and receive from each player one carro t."); hareCards.add("If there are more players behind you than in front of you , miss a turn. If not, play again."); hareCards.add("Give 10 carrots to each player lying behind you in the ra ce - if you haven't enough give them five each."); hareCards.add("Free Ride! - Your last turn costs nothing, retrieve the c arrots you paid to reach the square."); hareCards.add("Draw ten carrots for each lettuce you still hold - If you have none left, miss a turn."); for(String card : hareCards)

{ hareDeck.add(card); } } public String chooseHare() { Random generator = new Random(); int chosen = generator.nextInt(7); return hareDeck.get(chosen); } //Hare Card methods public void useHare(int player) { String result = chooseHare(); if(result.equals("Lose half your carrots - if an odd number, keep the od d one.")) { int numCarrots = players.get(player).getCarrots(); numCarrots = numCarrots / 2; players.get(player).setCarrots(numCarrots); } if(result.equals("Restore your carrot holding to exactly 65 - if you hav e more than 65, pay extras to the carrot patch, if fewer draw extras from carrot patch.")) { players.get(player).setCarrots(65); } if(result.equals("Shuffle hare cards and receive from each player one ca rrot.")) { int carrots = players.get(player).getCarrots(); carrots += (players.size() - 1); players.get(player).setCarrots(carrots); } if(result.equals("If there are more players behind you than in front of you, miss a turn. If not, play again.")) { } if(result.equals("Give 10 carrots to each player lying behind you in the race - if you haven't enough give them five each.")) { } if(result.equals("Free Ride! - Your last turn costs nothing, retrieve th e carrots you paid to reach the square.")) { } if(result.equals("Draw ten carrots for each lettuce you still hold - If you have none left, miss a turn.")) { if(players.get(player).getLettuces() > 0) { int num = players.get(player).getLettuces(); num *= 10; players.get(player).setCarrots(players.get(player).getCarrots() + num); }

else { // Miss a turn. } } } /*public String getTileType(int pos) { int n = hareTiles.length; while(Binary search { } return ("Type of Tile..."); }*/ public String getTileType() { int pos = players.get(0).getPosOnBoard(); boolean found = false; for(int i = 0; !found && (i < hareTiles.length); i++) { found = (hareTiles[i] == pos); } if(found == true) { return ("Hare Tile"); } //else //for(int i = 0; !found && (i return("N/A"); } // .append() // Random number to add to ArrayList of deck. public void run() { println(getTileType()); setHareCards(); println(chooseHare()); } }

Вам также может понравиться