Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this assignment, you are to write a section of the program that will prepare the playing grid for a new game by randomly placing cards
this assignment, you are to write a section of the program that will prepare the playing grid for a new game by randomly placing cards on the grid and printing the position of all the cards (face up). The game uses a sequence of 8 letters of the alphabet instead of images for the card faces, where the user defines the first letter of the sequence. Some examples: 'A','A','B,'B','C, 'C','D','D',E''E', 'F,'F,'G','G','H','H I 'q''q''r''r''s','s', 't', 't, 'u','u','v','v', 'w', 'w','x''x' Matching letters make up the matching pair. So 'A' and 'A' are a matching pair, as well as 't' and 't, etc The game grid is 4 cards by 4 cards with 16 cards total, consisting of 8 matching pairs. Your job is to determine the letters that make up the pairs in the deck, and deal the deck randomly to the game grid. There are several approaches of varying efficiency to solve this problem. Although not very efficient, one way to accomplish this task is to create a character array deck that holds the letters that make up the playing card faces. Then you declare a 2-dimensional array grid that will keep track of which letters are in which positions on the grid. The program loops though all grid positions and for each position it draws a random letter from the deck until the grid is filled. A card can be drawn from this virtual deck only once. You have to keep track of which positions in the deck have already been drawn by using another array cardDrawn so you do not draw the same card more than once. To help with debugging and to visually inspect that the cards are correctly drawn from the deck, you print out the deck content before every attempt to draw a card. This way you can see how the deck is depleted. In order to accommodate this visualization, you will replace the drawn letter from the deck with a space. This part of the code would eventually get deleted or commented out but for now it can provide a useful view into the drawing routine. Finally, after the grid is populated, you print it to the screen. Requirements: 1. Create a new Netbeans project 2. Define a constant for the size of the grid, gridsize = 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started