After the user presses any key

Assignment Help C/C++ Programming
Reference no: EM13163248

In this assignment, you will be writing a C++ command-line program that simulates a 3x3 sliding puzzle game. In a sliding puzzle game, 8 tiles with the numerals 1-8 are placed onto a 3x3 square grid. One of the positions is left open for tiles coming from the top, bottom, left, or right (depending on the puzzle configuration). The goal of the game is to slide the tiles around so they appear in order on the puzzle board. When writing this program, you should adhere to the object-oriented programming paradigm.

Assignment

When writing this program, you must design an object that represents the sliding puzzle board. To do this, you must consider the attributes and methods needed by the board to respond to a driver that contains the core logic of the game.

We should begin with a preliminary run-down of the object's features.

Attributes

int SlidingPuzzle::theBoard[3][3];
Description: The primary attribute of the object represents the data on the board. The board array contains the digits 1-8 and the asterisk (*) to represent the open position on the puzzle. When making moves, the data in this array will change to reflect the new state of the board. When the object displays itself on the screen, we will use this array to determine the board's current state.

Methods

SlidingPuzzle::SlidingPuzzle();
Description: This is the constructor method for the object. It will automatically execute once the board has been instantiated in the driver. Upon creation, it would be wise to immediately populate the board with valid values for all of the tiles. You should be able to trigger this with a single call to InitializeBoard().

void SlidingPuzzle::InitializeBoard();
Description: This method will manually populate the board with the game's starting configuration. Initially, the board should look like this:

1 2 3
4 5 6
7 8 *   <=== the * represents the blank space on the board

bool SlidingPuzzle::isBoardSolved();
Description: This method examines the board to determine if it is in the solved state. It returns a boolean value reflecting this determination.

bool SlidingPuzzle::slideTile(int);
Description: This method takes a single argument indicating the direction to slide a tile. A good approach would be to set up numerical codes representing the four possible movement directions (UP, DOWN, LEFT, and RIGHT). When the method is called, movement in the indicated direction should take place by exchanging the values in the appropriate tiles. If the move is not possible, the state of the board should remain unchanged. A boolean value should be returned reflecting whether or not the board has been mutated.

void SlidingPuzzle::scrambleBoard();
Description: This method will use the pseudo-random number generator to make an arbitrary number of random moves on the board (I suggest 10,000+ moves to thoroughly confuscate the board). Keep in mind that the seeding of the random number generator should take place in the driver code (not the object's constructor). Also keep in mind that randomly placing the pieces on the board will result in a situation where half of the time the puzzle can be solved and the other half of the time a solution is impossible.

void SlidingPuzzle::PrintBoard();
Description: This method will display the board on the console as a 3x3 grid. I suggest writing a "quick and dirty" version of this method initially so you can look at the maneuvers as they take place on the board during development. When the core logic of the program is done, you should revisit this method and upgrade it to support console color.

Hints

The following function demonstrates color printing. You can compile and play with the code to learn the basics of color. Keep in mind that you must include the Windows API in order for this to work.

#include <windows.h>
void printTheRainbow();

void printTheRainbow() {
int currentColor = 7;

// get the handle for the console
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

// exhaustively print the colors
cout << left;
for(currentColor = 0; currentColor <= 255; currentColor++) {
SetConsoleTextAttribute(hConsole, currentColor);
cout << setw(5) << currentColor
<< "Look at the pretty COLORS!" << endl;
}
}

Sample Run

When the program begins, the board should be loaded with a solved configuration.

After the user presses any key, the board will be scrambled by making a large number of random moves (for a 3x3 puzzle, 100,000 attempted random moves in random directions will result in a sufficiently scrambled board). Keep in mind that scrambling the board in a totally random fashion will result in 50% of board states being solvable and 50% of board states being unsolvable.

Note: This sample output is provided to give you an idea of what a proper implementation of the program may look like. The output you provide with your program should be captured from your implementation of the problem solution (not a cut & paste job of this output). The output from your program should resemble this layout as closely as possible to ensure you have fulfilled all of the assignment criteria, but individual style and creativity in your personal implementation are expected and encouraged.

Reference no: EM13163248

Questions Cloud

Various types of accounting systems : Write a paper in which you summarize the various accounting systems that each firm provides and various types of accounting systems
Which of these three slip directions is most favored : A single crystal of a metal is oriented for a tensile test such that its slip plane normal makes an angle of 65.5° with the tensile axis. Three possible slip directions make angles of 30°, 48°, and 78° with the same tensile axis.
What is the half-life of a compound : What is the half-life of a compound if 89 percent of a given sample of the compound decomposes in 56 min? Assume first-order kinetics.
Research a motivation theory : Research a motivation theory other than Maslow's hierarchy of needs. Describe how it is different than Maslow and how you could apply it to a current or past work/school situation.
After the user presses any key : After the user presses any key, the board will be scrambled by making a large number of random moves (for a 3x3 puzzle, 100,000 attempted random moves in random directions will result in a sufficiently scrambled board)
What is the specific heat for the metal : It takes 49.0 to raise the temperature of an 11.8 piece of unknown metal from 13.0 to 24.5. What is the specific heat for the metal?
Determine the ionization constant ka of this acid : a 0.050 molar solution of a weak monobasic (accepts one proton) substance, B has a pH of 10.98 Determine the ionization Constant Ka of this acid.
What is the value of the rydberg constant : Based on this equation, what is the value of the Rydberg constant (R) in m-1? (5 significant figures)
What are five general properties of aqueous acids : What are five general properties of aqueous acids? Name some common substances that have one or more of these properties.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Change temperature fahrenheit to celsius and kelvin

Write a program in c++ that takes the temperature in Fahrenheit and convert it to Celsius And Kelvin:

  Consists of an employee''s last name

Each input line consists of an employee's last name, first name, current base salary, total sales and percent commission. For example, in the first input line, the last name of the employee is Thomas, the first name is Andrew, the current base salary..

  Write c program-visual studio to scan multiple text files

Write program in C or C++ and Visual Studio to scan multiple text files and count number of occurrences of each word in those files. Use binary tree to keep track of all words.

  20 integers saved in a file called "data.txt"

There are 20 integers saved in a file called "data.txt" (just a random txt file with some numbers) All integers are in the range from 1 to 10

  Main function to input twenty integers in given range

Write a main function to input 20 integers in range of 1-6, function should count number of times the numbers 2 and 5 occur. function must declare statics variables count2 and count5.

  Write a program that reads in a list of integer numbers and

Write a program that reads in a list of integer numbers and print out the sum of all numbers, the average, the lowest and the highest value entered. The first input number indicates how many numbers the program is attempting to read. For example, if ..

  Design in c a unix utility program gasp

Design in C a Unix utility program gasp. Command gasp [options] STRING FILE... must read listed files (FILE...) and copy each line from input to stdout if it contains STRING.

  Prompts the user to enter an integer

Write the code that prompts the user to enter an integer between 1 and 20 (including 1 and 20), reads the value using cin, and then prints the value that they entered in a statement that begins with "You entered a ". Save this version in a separate l..

  Smallest sequence of numbers in the array

Write a function called sum_smallest_sequence() that accepts an array of  signed  integers and the  number  of items in the array as arguments, and returns the sum of the smallest sequence of numbers in the array.

  A constructor and a destructor

A constructor and a destructor, Insert a new element chosen by the user at the correct place in the list

  Write c program to read one ip address

Write a C or C++ program which Read one IP address at a time from Dec_IPAddresses.txt and convert it into Hex. Store converted values stored in another file (e.g. HEX_IPAddresses.txt).

  First display the smallest volume and then the largest volum

first display the smallest volume and then the largest volume.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd