// // Copyright(c) 2005-2011 Louay Gammo. All rights reserved. // function CWInfo(brand, title, date, author, editor) { this.brand = brand; this.title = title; this.date = date; this.author = author; this.editor = editor; } CWInfo.prototype.getBrand = function() { return this.brand; }; CWInfo.prototype.getTitle = function() { return this.title; }; CWInfo.prototype.getDate = function() { return this.date; }; CWInfo.prototype.getAuthor = function() { return this.author; }; CWInfo.prototype.getEditor = function() { return this.editor; }; function Clue(row, col, answer, clue) { this.row = row; this.col = col; this.answer = answer; this.clue = clue; } function CWClues() { this.clues = new Array(); this.key2seq = new Array(); this.seq2key = new Array(); } CWClues.prototype.addClue = function(key, row, col, answer, clue) { this.clues[parseInt(key)] = new Clue(row, col, answer, clue); this.seq2key.push(parseInt(key)); this.key2seq[parseInt(key)] = this.seq2key.length - 1; }; function CWGrid(height, width, defaultType, encoding) { this.letterCount = 0; this.width = width; this.height = height; if (encoding != null || encoding != '') { var rows = encoding.split(','); } else { var rows = null; } this.grid = new Array(height); for(var i = 0; i < height; i++) { this.grid[i] = new Array(width); for(var j = 0; j < width; j++) { if (rows != null) { var c = rows[i].charAt(j); if (c == '@') { var btype = 'block'; } else { var btype = 'letter'; } this.grid[i][j] = new CWCell(btype, c); } else { this.grid[i][j] = new CWCell(defaultType, null); } } } } CWGrid.prototype.setHorizontalSpan = function (index, row, col, word) { this.letterCount += word.length; for (var j = 0; j < word.length; j++) { this.grid[row][col+j] = new CWCell('letter', word.charAt(j)); if (j == 0) { this.grid[row][col+j].setIndex('start-across', index); } this.grid[row][col+j].setIndex('across', index); } } CWGrid.prototype.addVerticalIndex = function (index, row, col, len) { for (var j = 0; j < len; j++) { if (j == 0) { this.grid[row+j][col].setIndex('start-down', index); } this.grid[row+j][col].setIndex('down', index); } } function CWCell(cellType, cellValue) { this.type = cellType; this.value = cellValue; this.words = new Array(); this.index = new Array(); this.state = 0; } CWCell.prototype.resetState = function() { this.state = 0; }; CWCell.prototype.getState = function() { return this.state; }; CWCell.prototype.isErroneous = function() { return (this.state & 0x04); }; CWCell.prototype.isConfirmed = function() { return (this.state & 0x02); }; CWCell.prototype.isRevealed = function() { return (this.state & 0x01); }; CWCell.prototype.setErroneous = function() { this.state |= 0x04; }; CWCell.prototype.setConfirmed = function() { this.state |= 0x02; }; CWCell.prototype.setRevealed = function() { this.state |= 0x01; }; CWCell.prototype.resetIndex = function() { this.index = new Array(); }; CWCell.prototype.setIndex = function(key, index) { this.index[key] = parseInt(index); }; CWCell.prototype.setWord = function(key, word) { this.words[key] = word; }; CWCell.prototype.setType = function(type) { this.type = type; }; CWCell.prototype.getType = function() { return this.type; }; // // Common JS // var curI = 0; var curJ = 0; var curDir = 'across'; var splashScreen = true; var prevI = 0; var prevJ = 0; var prevDir = 'down'; var ascii_backspace = 8; //TBD? var ascii_left = 37; //TBD? var ascii_up = 38; //TBD? var ascii_right = 39; //TBD? var ascii_down = 40; //TBD? var ascii_tab = '\t'.charCodeAt(0); var ascii_space = ' '.charCodeAt(0); var ascii_a = 'A'.charCodeAt(0); var ascii_z = 'Z'.charCodeAt(0); var ascii_block = 'B'.charCodeAt(0); //with control/shift keys var ascii_editclue = 'E'.charCodeAt(0); //with control/shift keys var ascii_nextline = '\r'.charCodeAt(0); //windows specific??? function showMessage(msg, append) { var elt = document.getElementById('message'); if (elt == null) { return } if (typeof(append) == 'undefined') { append = false; } if (append) { elt.value = elt.value + msg; } else { elt.value = msg; } } function displayUserMessage(id, show) { var elt = document.getElementById(id); if (elt == null) { return false; } if (show) { elt.style.display = 'block'; } else { elt.style.display = 'none'; } return true; } function showUserMessage(id, focusId) { var elt = document.getElementById(id); if (elt == null) { return false; } elt.style.display = 'block'; var elt = document.getElementById(focusId); if (elt == null) { return false; } elt.focus(); return true; } function CancelGame(msg, href) { var agree = confirm(msg); if (agree == false) { return; } document.location.href = href; return false; } function setClueLineWidth() { var targetId = 'clueLineContainer'; var srcId = 'grid'; var t = document.getElementById(targetId); if (t == null) { return false; } var s = document.getElementById(srcId); if (s == null) { return false; } var w = s.firstChild.offsetWidth; if (w > 0) { t.style.width = w + 'px'; } counter++; showMessage('counter='+counter+' width='+w, true); } var counter = 0; // var ImageCache = new Array(); // function ImagePreloader() // { // for (var i = 0; i < 9; i++) { // ImageCache[i] = new Image(); // ImageCache[i].src = '/crossword/icons/icon_' + i + '.gif'; // } // }