Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Qwixx You will write a version of the dice game Qwixx. In this game there are 6 dice, 2 white dice and 4 colour dice:

Qwixx

You will write a version of the dice game Qwixx. In this game there are 6 dice, 2 white dice and 4 colour dice: red, yellow, green and blue and each player has a game board as shown below: The goal of the game is to score as many points as possible. The more numbers you cross off the higher your score. There are 4 rows of numbers, each a different color, and two of them go from 2-12 whereas the other two go from 12-2. The main rule is that you have to start on the left and go to the right and if you pass up a number, well youre out of luck. In other words, you can mark off a number only if it's to the right of all marked-off numbers in the same row. So, if you marked of say the 2, 3 and 6 on the red row, the next number you can mark is 7 (or higher). You cannot mark off 4 and 5 anymore.

At the start of each new round:

The player changes (this is now the players whos turn it is)

The dice are rolled.

All players can use the total number of the two white dice to cross off that number in any row on their sheet (as long as they follow the right left to left right rule).

Next, the player whos turn it is gets to choose a second number to cross off using 1 white dice plus one colored dice. For example, if you had a white 3 and a red 6 you could cross off a 9 in your red row. On your turn you must take a number or take a penalty (worth -5 at the end of the game). Note that are no penalties for passing on the white dice total.

The game ends when:

Any 2 of the colour rows have been locked out (by any player crossing off the 12 or 2 at the far right of the score pad) or a player has passed 4 times (i.e. has -20 points).

Scoring to determine the winner:

At the end of the game you count up how many numbers are crossed off in each row and score accordingly based on the scoring grid shown below in the methods description section.

Subtract the number of negative points from the total.

The winner is the player with the most points.

In order to get you started here are the classes, instance variables, and methods you should have. You will create 4 classes: Dice, Move, Player, and Qwixx.

1. Define a Dice class:

a. A Dice object has 2 attributes: a String colour and an integer currentSide.

b. Default constructor which sets the colour to white and sets an initial currentSide using the rollDice() method (see below).

c. A constructor that takes one input, a colour, and sets an initial currentSide using the rollDice() method (see below).

d. A get/set (mutator/accessor) method for colour and a get method for currentSide.

e. A toString() method that returns the colour and current side of the dice as a String.

2. Define a Move class:

a. A Move object has 2 attributes: a character colour and an integer number.

b. Get/set (mutator/accessor) methods for colour and number.

c. A constructor that takes two inputs, a colour and a number and sets the attributes accordingly.

d. A static methods convertColourtoNum(char colour) method that takes a char and converts it to the index of the row for that colour (i.e. R = 0, Y = 1, G =2, B = 3) and returns that index. This method will help you index the right array element during the game to cross it out.

3. Define a Player class:

a. A Player object has seven attributes: a String name, a 2D String[4][11] gameBoard (the col will represent the colour (Red, Yellow, Green and Blue), and the row the numbers in that colour row (from 12-2 or 2-12), 4 integers to keep track of the last number that was crossed of in each colour row, and an integer negativePoints to keep track of how many negative points they accumulated by passing.

b. A default constructor which initializes all of the attributes, the game board should be initialized using the initializeGameboard() method described below.

c. A constructor which takes one parameter, a String for the player name.

d. Accessor/get methods for each of the attributes except the game board.

e. An initializeGameboard() which initializies each row of the gameboard; for Red and Yellow from 12-2 2-12 and for Green and Blue from 2-12 12-2.

f. An addNegativePoints(int pts) method that takes a parameter pts and adds these to the negativePoints of the player.

g. A printGameBoard() method that prints out the players gameboard (including the name of the player whos board is being printed.

h. A makeMove(Move m)method, that takes as input a move and crosses off the appropriate colour/number combination on the players gameboard. Hint: you may wish to make use of your convertColourtoNum(char colour) method.

i. A getBoardTotalMethod() which calculates the total for the gameboard based on the following (the top row is how many numbers are crossed off, the bottom how many points). You should calculate the points per each colour based on how many numbers were crossed off and subtract the players negative points to get the total.

4. A Qwixx class:

a. The Qwixx class is where all the action happens. In this class we have the following attributes: an array of Dice[] that will contain each of the coloured dice and two white dice. An array of Players[] that contains the players in the game, four boolean values that keep track of whether a colour is locked and therefore no longer playable (recall a colour is locked when any player crosses off the 12 or 2 at the far right of the score pad of that colour), a static variable NEGPTS which is set to -5.

b. A constructor that takes an array of Players and initializes the Players[] with it. The constructor should also initialize the Dice[].

c. The following methods: rollDice() which randomly assigns the current side of each of the 6 dice. A printRolledDice() method that prints all of the dice and their current values.

d. A playWhiteDiceMove() which takes care of the moves on the white dice. Recall that all players can use the total number on the two white dice to cross off a number in any row on their sheet. This method should print the total of the white dice and ask each player if they would like to use the total to cross of one of the numbers on the game board. If a player wants to make a move, you should create a move, check if its valid and if it is update the gameboard. For simplicity, you may loop through the players in the same order each time. The method might make use of the following helper methods:

a. A getWhiteDiceTotal()method that returns the sum of the two white dice.

b. A checkValidMove(Player p, Move m) method that checks if the move the player wants to make is valid and returns a boolean indicating whether it is or is not a valid move. Remember a move is valid if its on the gameboard and if the number being crossed off is further right then the last crossed off number AND the colour has not been unlocked. Hint: the Player class keeps track of the last crossed of value for each colour on their own gameboard.

c. A checkColourFinished(Player p, Char colour)method that returns true if the colour the player has just crossed off a number in becomes finished. The method should also update that colour to be locked for the game and output this to the console.

d. A checkGameFinished()method that checks if the game is finished. A game is finished when all of the two colour rows have been locked out (by a player crossing off the 12 or 2 at the far right of the score pad) or a player has passed 4 times (i.e. has -20 points).

e. A playColourDiceMoves() method which takes care of the moves on the colour dice. Recall that the player whos turned it is gets to choose a second number to cross off using 1 white die plus one colored die. This method should ask the player if they want to make a move. If they do, it should ask which white dice they want to use and which colour they want to cross out, create a move based on this, check if its valid and if so update the gameboard. If they decide not to play, then you should give them -5 points. Again, you may use the helper methods listed above.

f. A play() method which loops calling the rollDice(), printRolledDice(), playWhiteDiceMove(), playColourDiceMove(), and checkGameFinished() methods until the game is done. Once the game is done use a method (e.g. determineWinner()) to determine the winner.

4. A Driver class:

a. The main method in the driver class should ask the user how many players are playing the game. Ensure this is between 2-5.

b. For each player ask the user the name and create the player.

c. Create a Qwixx game with the array of players and call the play() method.

*Note although you should check valid moves, you do not have to deal with input mismatch errors. Here is a sample output to illustrate the expected behavior of your program. Your formatting may differ from the below but must demonstrate the behavior of the game and be easy to follow.

Message me if you need the sample on Facebook (Michael Khieu) or Instagram (@king_khieu)

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_2

Step: 3

blur-text-image_3

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions