459,290 Members | 1,388 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

# Game

 P: n/a Create a game in a 3x3 HTML table that works as follows: * The goal of the game is to beat the computer by scoring more points than the computer. * The game starts when a hidden random number between 1 and 9 is placed in each cell. * The user and computer take turns by "clicking" on table cells. When a cell is "clicked" by the user, the user scores the number of hidden points in the cell. When the computer takes a turn, it "clicks on" a random cell that has not been clicked yet and adds the hidden points in the clicked cell to its scor * The user always goes first, so they should have a better chance of winning since they will get 5 turns and the computer 4 turns. * The user wins if they score more points than the computer. The computer wins if it scores more than the user. Hints: * Have your script first generate a set of random numbers from 1- 9 and place them randomly in an array. The numbers in the array will need to be unique, so you will need a loop to go through and check that each new random number has not already been used. * Use the ONCLICK="clicked(cellNum)" in each cell(TD tag) to call the a function called clicked(cellNum), passing in the cell number(0,1,2,...,9) as the parameter. That way, when the function named "clicked()" gets cellNum it will know which cell was clicked and perform scoring based on that. * Use a P or DIV tags to hold the scores for the user and computer. Please help out anyway you can. I know I'm new, but I really really need help. Feb 28 '06 #1
6 Replies

 P: n/a ja******@gmail.com said the following on 2/28/2006 2:27 PM: Create a game in a 3x3 HTML table that works as follows: How much of your grade do I get for doing your homework? -- Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ Feb 28 '06 #2

 P: n/a ja******@gmail.com wrote on 28 feb 2006 in comp.lang.javascript: Create a game in a 3x3 HTML table that works as follows: * The goal of the game is to beat the computer by scoring more [....] Please help out anyway you can. I know I'm new, but I really really need help. You should do your school assignment yourself. If you get into specific trouble, perhaps, ... I mean certainly, someone here on this usenet NG will help you if you show the details of where the trouble is. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) Feb 28 '06 #3

 P: n/a ja******@gmail.com wrote: Create a game in a 3x3 HTML table that works as follows: [...] Hints: [...] Please help out anyway you can. I know I'm new, but I really really need help. You really really should have attended the corresponding lessons. PointedEars Feb 28 '06 #4

 P: n/a I have attended every class, and the teacher wont help on homework assigned outside of class. I already have tried on numerous occasions only to fall up short. I will submit the latest attempt in hopes that it can be dissected and corrected. Jonathan Riehm CIS 201-01 HW 6

Click me!

Click me!

Click me!

Click me!

Click me!

Click me!

Click me!

Click me!

Click me!

Feb 28 '06 #5

 P: n/a "ja******@gmail.com" writes: I have attended every class, and the teacher wont help on homework assigned outside of class. I already have tried on numerous occasions only to fall up short. I will submit the latest attempt in hopes that it can be dissected and corrected. I'll try to give a few hints. You are missing the point of using events. Your loop, the one which alternates between alerting that it is the user's turn and not doing it, will run to completeness (including all five alerts) before any other script is allowed to run, including the event handlers of the table cells. Javascript in browsers isn't multithreaded or preemptive. Busy-waiting on user actions will never work (it's a bad idea everywhere else too, even when it "works"). You should do the calculations and set up the intial game state and (perhaps) alert the user for his first turn. Then your initialization script should end. The next thing that happens is that the user clicks a cell and an event fires. In this event handler you update your game state accordingly. When five such events have fired (not counting any attempts of pressing the same square again!) you should be done.

 P: n/a JRS: In article <11**********************@i40g2000cwc.googlegroups .com> , dated Tue, 28 Feb 2006 11:27:20 remote, seen in news:comp.lang.javascript, ja******@gmail.com posted : * Have your script first generate a set of random numbers from 1- 9and place them randomly in an array. The numbers in the array willneed to be unique, so you will need a loop to go through and check thateach new random number has not already been used. So your instructor is also of inadequate ability. His/Her "you will need a loop ..." is a false statement. Such a loop can be used, but that is an inefficient method. The need is to deal the numbers, in random order, into an array. There is an efficient algorithm for that; it is in Knuth, and can also be found /via/ the newsgroup FAQ. * Use the ONCLICK="clicked(cellNum)" in each cell(TD tag) to callthe a function called clicked(cellNum), passing in the cellnumber(0,1,2,...,9) as the parameter. That way, when the function ^ Either your instructor cannot count or you are a careless copier. -- © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © JL/RC: FAQ of news:comp.lang.javascript jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. Mar 1 '06 #7

### This discussion thread is closed

Replies have been disabled for this discussion.