Cash-back offer from May 7th to 12th, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 38.00

CS 105 MP3: Number Sorting Game | Complete Solution

Question posted by
Online Tutor Profile
request

MP3: Number Sorting Game

Due: Tuesday, Sep. 29th by 8:00pm

Let's do this!

Part 1: Creating a new function

In numbers.js, you will need to create a new function called processClick(). This function will take an argument that will allow you to tell it which tile was clicked, so it will need to look something like this function processClick(tileId){}. This will create a variable called tileId that you can use anywhere inside the function (within the curly braces), but not outside of it.

 

Part 2: Calling the function

Your new function will need to be called every time the player clicks a tile. You can achieve this by adding an event handler to each different cell in the keypad table. In HTML, a cell is defined by the <td> tag and since we are waiting for a click, we need to insert an onClick handler to each of those cells. In generic terms, this will look like this (You must change this code to fit your needs; Just copying and pasting this example will not do you any good) : <td id="myCell" onClick="myfunction(this.id);"> The this.id part forwards the id of the cell to the called function so it can properly process the click. By the way, this always refers to the object you are currently dealing with, so in this case the applicable <td>.

 

Part 3: Getting stuff from the keypad

You will need to read the content of each clicked cell so that you may swap them around. Once you get the hang of it, it is actually not that hard to get the content in Javascript. The entire page is considered a document and everything in the page lives under the document object. We can use document.getElementById(desiredId) to get any item (technically speaking any "object") from the page. You already know the id of the clicked tile as it was passed to the function from the event handler. So you could use document.getElementById(tileId). This will give you the <td> object for the clicked tile. This tile itself has a property (which is sort of like a variable) called innerHTML. So document.getElementById(tileId).innerHTML will get you the number that is in the currently clicked cell.

Part 4: Writing stuff to the keypad

Now that you know how to read from innerHTML, writing to it won't a big deal. You can write "I love my cat" to a cell by just assigning that text to innerHTML, like so:document.getElementById(tileId).innerHTML="I love my cat";

Part 5: Remembering the tile

The only slightly tricky part is keeping track of the clicked tile. When the player clicks one, you need to know whether he already clicked one before (whether there is an orange tile). If so, you need to perform the swap and turn the tiles white again. If not, you need to turn the clikcked tile orange and somehow remember the fact that this tile was clicked.

You can do this in many ways. However, to make it a little easier for you, we have defined a global variable called clickedcell that initially holds an empty string. You may use this variable to remember what tile the player has clicked (do not use var to recreate it). Obviously you need to also empty it out after each swap.

Part 6: Changing the color of an object

Each object has many properties and a <td> has things such as innerHTML and also one called style. This lets you change just about everything about how the object looks, including its style.backgroundColor which you can read and write the exact same way as innerHTML.

Oh, one more thing, colors are defined in hexadecimal RGB space. So orange is #D35400 and white is #FFFFFF. Play around with it a little and see what cool colors you can come up with.

Part 7: The winning condition

The last thing on your to-do list is the winning condition. Every time a user swaps two tiles, you must check whether all of them are in the right place. If so, you will need to congratulate the user by displaying an alert message.

And that's pretty much it.

You have just programmed your first real game pretty much from scratch (not the programming language). Amazing, right?
 
Submit your MP3 here!

Available Answer
$ 38.00

[Solved] CS 105 MP3: Number Sorting Game | Complete Solution

  • This Solution has been Purchased 1 time
  • Submitted On 03 Oct, 2015 04:16:23
Answer posted by
Online Tutor Profile
solution
This Tutorial is rated A+ p...
Buy now to view the complete solution
Other Similar Questions
User Profile
AceTu...

CS 105 MP3: Number Sorting Game | Complete Solution

This Tutorial is rated A+ previously,if you have any questions regarding this tutorial then you can contact me....

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35