Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a webpage that enables the user to play the game of 8-Puzzle. Theres a 2-by- 4 board (implemented as an HTML5 table) for a

Create a webpage that enables the user to play the game of 8-Puzzle. Theres a 2-by- 4 board (implemented as an HTML5 table) for a total of 8 slots. One of the slots is empty. The other slots are occupied by 7 tiles, randomly numbered from 1 through 8.

The exercise will incorporate a two-dimensional array, and the 8-puzzle requires significantly fewer tile objects and a significantly smaller 2d array.

Some Hints (for one approach to completing the exercise):

Have each cell (tile) in the HTML table be a distinct object (with a distinct id). Use CSS to specify how the objects display (font size & color, border, etc.)

Have the JavaScript file generate a two-dimensional (2-d) array, with elements identified with those in the HTML table. Create a listener for each cell element.

Store the numbers 1 through 8 randomly in a 1-d array and use this to populate your 2-d array.

Build a function which can swap any numbered tile with the blank tile (only if the blank tile is directly adjacent).

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions