[bknr-cvs] r2416 - branches/trunk-reorg/projects/scrabble/website
hhubner at common-lisp.net
hhubner at common-lisp.net
Tue Jan 29 12:08:10 UTC 2008
Author: hhubner
Date: Tue Jan 29 07:08:08 2008
New Revision: 2416
Added:
branches/trunk-reorg/projects/scrabble/website/scrabble-yui-pos.js
Log:
save this file just in case
Added: branches/trunk-reorg/projects/scrabble/website/scrabble-yui-pos.js
==============================================================================
--- (empty file)
+++ branches/trunk-reorg/projects/scrabble/website/scrabble-yui-pos.js Tue Jan 29 07:08:08 2008
@@ -0,0 +1,168 @@
+// -*- Java -*- (really Javascript)
+
+var boardScoring = [["triple-word",null,null,"double-letter",null,null,null,"triple-word",
+ null,null,null,"double-letter",null,null,"triple-word"],
+ [null,"double-word",null,null,null,"triple-letter",null,null,null,"triple-letter",
+ null,null,null,"double-word",null],
+ [null,null,"double-word",null,null,null,"double-letter",null,"double-letter",
+ null,null,null,"double-word",null,null],
+ ["double-letter",null,null,"double-word",null,null,null,"double-letter",
+ null,null,null,"double-word",null,null,"double-letter"],
+ [null,null,null,null,"double-word",null,null,null,null,null,"double-word",
+ null,null,null,null],
+ [null,"triple-letter",null,null,null,"triple-letter",null,null,null,"triple-letter",
+ null,null,null,"triple-letter",null],
+ [null,null,"double-letter",null,null,null,"double-letter",null,"double-letter",
+ null,null,null,"double-letter",null,null],
+ ["triple-word",null,null,"double-letter",null,null,null,"double-word",
+ null,null,null,"double-letter",null,null,"triple-word"],
+ [null,null,"double-letter",null,null,null,"double-letter",null,"double-letter",
+ null,null,null,"double-letter",null,null],
+ [null,"triple-letter",null,null,null,"triple-letter",null,null,null,"triple-letter",
+ null,null,null,"triple-letter",null],
+ [null,null,null,null,"double-word",null,null,null,null,null,"double-word",
+ null,null,null,null],
+ ["double-letter",null,null,"double-word",null,null,null,"double-letter",
+ null,null,null,"double-word",null,null,"double-letter"],
+ [null,null,"double-word",null,null,null,"double-letter",null,"double-letter",
+ null,null,null,"double-word",null,null],
+ [null,"double-word",null,null,null,"triple-letter",null,null,null,"triple-letter",
+ null,null,null,"double-word",null],
+ ["triple-word",null,null,"double-letter",null,null,null,"triple-word",
+ null,null,null,"double-letter",null,null,"triple-word"]];
+
+function getFieldScore(x, y) {
+ return boardScoring[x][y] || 'standard';
+}
+
+var board;
+
+function makeBoard() {
+ var container = $('playfield');
+ board = [];
+ for (x = 0; x < 15; x++) {
+ board[x] = [];
+ for (y = 0; y < 15; y++) {
+ var element = DIV();
+ element.style.position = 'absolute';
+ element.style.width = '40px';
+ element.style.height = '40px';
+ element.style.backgroundImage = 'url(images/' + getFieldScore(x, y) + '.png)';
+ board[x][y] = element;
+ appendChildNodes(container, element);
+ YAHOO.util.Dom.setXY(element, [ x * 44, y * 44 ]);
+ }
+ }
+
+ myTrayContainer = DIV();
+ myTrayContainer.style.position = 'absolute';
+ myTrayContainer.style.width = 7 * 44 + 'px';
+ myTrayContainer.style.height = '44px';
+ appendChildNodes(container, myTrayContainer);
+ YAHOO.util.Dom.setXY(myTrayContainer, [ 194, 665 ]);
+
+ var shuffleButton = DIV(null, "shuffle");
+ shuffleButton.style.color = 'white';
+ shuffleButton.style.position = 'absolute';
+ shuffleButton.onclick = shuffleMyTray;
+ appendChildNodes(container, shuffleButton);
+ YAHOO.util.Dom.setXY(shuffleButton, [ 480, 665 ]);
+
+ var clearButton = DIV({ id: 'clear' }, "clear");
+ clearButton.style.color = 'white';
+ clearButton.style.position = 'absolute';
+ clearButton.onclick = clearBoard;
+ appendChildNodes(container, clearButton);
+ YAHOO.util.Dom.setXY(clearButton, [ 480, 680 ]);
+
+}
+
+function setLetter(x, y, letter) {
+ var image = IMG({ src: 'images/' + letter + '.png'});
+ image.style.position = 'absolute';
+ image.style.top = '3px';
+ image.style.left = '3px';
+ replaceChildNodes(board[x][y], image);
+ board[x][y].letterNode = image;
+}
+
+function clearBoard() {
+ for (x = 0; x < 15; x++) {
+ for (y = 0; y < 15; y++) {
+ var letterNode = board[x][y].letterNode;
+ if (letterNode) {
+ board[x][y].letterNode = null;
+ letterNode.anim = new YAHOO.util.Motion(letterNode, { points: { to: [ 7 * 44 + 3, 7 * 44 + 3 ]}});
+ letterNode.anim.duration = 0.15;
+ letterNode.anim.onComplete.subscribe(function () { removeElement(this); });
+ letterNode.anim.animate();
+ }
+ }
+ }
+}
+
+var tray;
+
+function trayClick(letter) {
+ this.clicked = !this.clicked;
+ this.anim = new YAHOO.util.Motion(this, { points: { by: [ 0, (this.clicked ? 15 : -15 ) ]}});
+ this.anim.duration = 0.15;
+ this.anim.animate();
+}
+
+function makeMyTray(letters) {
+ tray = [];
+ for (var i = 0; i < letters.length; i++) {
+ var element = IMG({src: 'images/' + letters[i] + '.png'});
+ element.letter = letters[i];
+ element.style.position = 'absolute';
+ element.style.width = '34px';
+ element.style.height = '34px';
+ element.
+ onclick = trayClick;
+ setElementPosition(element, { x: i * 40 });
+ tray[i] = element;
+ }
+ replaceChildNodes(myTrayContainer, tray);
+}
+
+function shuffleMyTray() {
+ var count = tray.length;
+ var newTray = [];
+ for (var i = 0; i < count; i++) {
+ do {
+ index = Math.floor(Math.random() * count);
+ } while (newTray[index]);
+ newTray[index] = tray[i];
+ newTray[index].anim = new YAHOO.util.Motion(tray[i], { points: { to: [ 194 + i * 40, 680 ] }});
+ newTray[index].anim.duration = 0.5;
+ newTray[index].anim.animate();
+ newTray[index].clicked = false;
+ }
+ tray = newTray;
+}
+
+function drawGameState (gameState) {
+ for (var i = 0; i < gameState.board.length; i++) {
+ var x = gameState.board[i][0];
+ var y = gameState.board[i][1];
+ var char = gameState.board[i][2];
+ setLetter(x, y, char);
+ }
+}
+
+function init() {
+ makeBoard();
+ makeMyTray(['S', 'A', 'C', 'H', 'D', 'E', 'N']);
+ setLetter(7, 7, 'H');
+ setLetter(7, 8, 'A');
+ setLetter(7, 9, 'L');
+ setLetter(7, 10, 'L');
+ setLetter(7, 11, 'O');
+ setLetter(8, 7, 'O');
+ setLetter(9, 7, 'R');
+ setLetter(10, 7, 'S');
+ setLetter(11, 7, 'T');
+ var d = loadJSONDoc("/game/108");
+ d.addCallbacks(drawGameState, alert);
+}
More information about the Bknr-cvs
mailing list