Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will program Crazy Nancys garden Game. The winner of the game is the player (called gardener from now on) who fills

For this assignment you will program Crazy Nancys garden Game. The winner of the game is the player (called gardener from now on) who fills up his/her garden with flowers and trees the first. There are no ties in this game. This game requires luck with the dice and a bit of strategy.

Rules of the game: 1. Number of players: 2 to 10 2. Garden size: N x N, where N is at least 3 3. Each player has a garden board which is empty when they start the game. A player can plant either a flower which takes up one square or a tree which takes up 4 squares (2 x 2).

4. The game works as follows: a) Determine who goes 1st: each player rolls 2 dice. The player with the highest roll goes first. How ever if any player rolls the same total, this process starts over again. Here is a sample output to illustrate the above explanation:

image text in transcribed

b) Each player has a turn until there is a winner. During his/her turn a player: a. Rolls the 2 dice. b. Based on the outcome gets to plant a pre-set number of trees and/or flowers.

image text in transcribed

c. It is possible that a player does not have enough room left in his/her garden to plant a tree in which case the player looses a turn. It is also possible that a player fills his/her garden before finishing his/her turn when they have 2 items to plant. If this happens then they are declared the winner.

Implementation of the game: You will create 4 classes: Dice, Garden, Player, and LetsPlay. Write the declaration of these classes each in a file of their own based on the following specifications. You cannot omit any of the attributes or methods given in these classes. You can add some if you like. 1. Class Dice: a) A Dice object has 2 attributes: Two integers which record the value of each die. b) Default constructor which sets the value of each die to zero. c) Get (accessor) methods for each attribute. d) A rollDice() method which randomly assigns a number between 1 and 6 to each die and return the sum of the two dice. e) A toString() method that returns the content of each die as a String. 2. Class Garden: a) A Garden object has 1 attributes: garden a 2-D character array representing the garden. Each location will contain one of the following characters: i. 'f': if a flower occupies that location. ii. 't': if a part of a tree occupies that location. iii. '-': if that location is empty. b) A default constructor which creates the array garden as 3x3 array (the default garden size) and initializes each space to '-', the symbol used to represent an empty space using the method initializeGarden() described in d) below. c) A constructor which takes an integer representing the size of the garden and creates the garden array as a size x size array and initializes each space to '-' the symbol used to represent an empty space using the method initializeGarden() described in d) below. d) A private initializeGarden() method which initializes each space in the array garden to '-'. e) A getInLocation(int r,int c) method which returns the character stored in location [r][c] of garden. f) A plantFlower(int r,int c) method which stores the character 'f' in the location [r][c] of garden. g) A plantTree(int r,int c) method which stores the character 't' in the locations [r][c], [r+1][c], [r][c+1] and [r+1][c+1] of garden. h) A removeFlower(int r,int c) method which stores the character '-' in the location [r][c] of garden. i) A countPossibleTrees() method which returns the number of places a tree can be planted in the garden. A tree takes 4 spots as a 2x2 block. For example if the status of the garden is

| 0 1 2 3 0 | - - - - 1 | - - - -

2 | t t t t 3 | t t t t

image text in transcribed

j) A countPossibleFlowers() method which returns the number of places a flower can be planted in the garden. k) A gardenFull() method which returns true if the garden is full and false otherwise. l) A toString() method that returns as a String the content of a garden object as an N x N square (see figure 3 above). 3. Class Player : 1. A Player object has two attributes: a String name that stores a gardener`s name, and a Garden object garden which is this player`s board game. 2. A constructor which takes two parameters, a String for the player`s name and an integer for the size of the garden. 3. An Accessor/get method for the name attribute. 4. The following methods are all methods that will have the garden attribute call the corresponding method from the Garden class. This is necessary since garden is a private attribute of the class Player. i. howManyFlowersPossible() which will return the result of a call to the method countPossibleFlowers() by the attribute garden. ii. howManyTreesPossible() which will return the result of a call to the method countPossibleTrees() by the attribute garden. iii. whatIsPlanted(int r, int c) which will return the result of a call to the method getInLocation(r,c) by the attribute garden. iv. plantTreeInGarden(int r, int c) which will call the method plantTree() to plant a flower in garden in location [r][c]. v. plantFlowerInGarden(int r, int c) which will call the method plantFlower() to plant a tree in garden in location[r][c], [r+1][c], [r][c+1] and [r+1][c+1]. vi. eatHere(int r, int c) which will call the method removeFlower() to remove a flower in garden in location [r][c], which means assigning a '-' to the location

[r][c]. Note the same method removeFlower() will be used to remove a portion of a tree. vii. isGardenFull() which will return the result of a call to the method gardenFull() by the attribute garden. viii. showGarden() which displays the content of the garden object as in figure 1. 4. Class LetsPlay: The LetsPlay class is the driver class and where all the action happens. Your players must be stored in an array of type Player. There must not be any Garden objects declared in the driver. Each Player object has a Garden object as one of its attributes. Here are the general steps of the algorithm. 1. Display a welcome banner. 2. Display the general rules of the game. Your text can differ from the sample provided, but the rules must be the same. 3. Ask the user the size of the board: Do they accept the default 3x3 grid or do they want to choose another size. Make sure the size is at least 3. 4. Ask the user for the number of players. Make sure number entered is between 2 and 10 inclusive. 5. Create the Player array. Be sure to include the player`s names. 6. Decide who goes 1st. Each player throws the dice (using the DICE class). The one with the highest total goes first. If two players throw the same total, you need to start over. See rule 4 a). 7. As long as there is no winner a. The next player throws the dice. b. Based on the total rolled, either the player can plant something or has the rabbit eating a flower or part of a tree. If the player can plant, prompt the user for the coordinates of the flower(s) and or trees(s). You are always to refer to a player by hisher name, show them the total of their roll, as well as the value of each die. Tell them what they are to plant, show them the status of their garden, tell them in how many places in their garden they can plant the tree or flower. If there is no room for the item in the garden, player loses a turn. If there is room prompt them for the coordinates. Here is a sample to illustrate the expected behaviour.

image text in transcribed

image text in transcribedimage text in transcribed

Let's see who goes first a rolled a 7 b rolled a 12 c rolled a 7 We will start over as 7 was rolled by a as well. a rolled a 8 b rolled a 9 c rolled a 7 d rolled a 8 We will start over as 8 was rolled by a as well. a rolled a 10 b rolled a 12 c rolled a 7 d rolled a 4 b goes first Figure 1- Who goes first? Let's see who goes first a rolled a 7 b rolled a 12 c rolled a 7 We will start over as 7 was rolled by a as well. a rolled a 8 b rolled a 9 c rolled a 7 d rolled a 8 We will start over as 8 was rolled by a as well. a rolled a 10 b rolled a 12 c rolled a 7 d rolled a 4 b goes first Figure 1- Who goes first

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago