CoffeeScript (for jay muratore) by Trevor Burnham

CoffeeScript (for jay muratore) by Trevor Burnham

Author:Trevor Burnham
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
ISBN: 978-1-934356-78-4
Publisher: The Pragmatic Bookshelf, LLC (306009)


* * *

Figure 4. Playing with our command-line prompt

Collections/5x5/game.coffee

promptForTile2 = (x1, y1) ->

console.log "Please enter coordinates for the second tile."

inputCallback = (input) ->

try

{x: x2, y: y2} = strToCoordinates input

catch e

console.log e

return

if x1 is x2 and y1 is y2

console.log "The second tile must be different from the first."

else

console.log "Swapping (#{x1}, #{y1}) with (#{x2}, #{y2})..."

x1--; x2--; y1--; y2--; # convert 1-based indices to 0-based

[grid[x1][y1], grid[x2][y2]] = [grid[x2][y2], grid[x1][y1]]

{moveScore, newWords} = scoreMove grid, {x1, y1, x2, y2}

unless moveScore is 0

console.log """

You formed the following word(s):

#{newWords.join(', ')}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.