Last active
September 9, 2015 17:06
-
-
Save Sfshaza/0532bfcb70bf5e4a900c to your computer and use it in GitHub Desktop.
anagram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
Copyright (c) 2012, the Dart project authors. | |
Please see the AUTHORS file for details. | |
All rights reserved. Use of this source code | |
is governed by a BSD-style license that can be | |
found in the LICENSE file. | |
--> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Anagram</title> | |
<script async type="application/dart" src="main.dart"></script> | |
<script async src="packages/browser/dart.js"></script> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<h1>Anagram</h1> | |
<h3>Pile:</h3> | |
<div id="letterpile"> | |
</div> | |
<h3>Word:</h3> | |
<div id="result"> | |
</div> | |
<h3>Scrabble Value:</h3> | |
<p id="value"></p> | |
<button id="clearButton"> new letters </button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2012, the Dart project authors. Please see the | |
// AUTHORS file for details. All rights reserved. Use of this | |
// source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
import 'dart:html'; | |
import 'dart:math'; | |
// Should remove tiles from here when they are selected otherwise | |
// the ratio is off. | |
String scrabbleLetters = 'aaaaaaaaabbccddddeeeeeeeeeeeeffggghhiiiiiiiiijkllllmmnnnnnnooooooooppqrrrrrrssssttttttuuuuvvwwxyyz**'; | |
List<ButtonElement> buttons = new List(); | |
Element letterpile; | |
Element result; | |
ButtonElement clearButton; | |
Element value; | |
int wordvalue = 0; | |
Map scrabbleValues = { 'a':1, 'e':1, 'i':1, 'l':1, 'n':1, | |
'o':1, 'r':1, 's':1, 't':1, 'u':1, | |
'd':2, 'g':2, 'b':3, 'c':3, 'm':3, | |
'p':3, 'f':4, 'h':4, 'v':4, 'w':4, | |
'y':4, 'k':5, 'j':8, 'x':8, 'q':10, | |
'z':10, '*':0 }; | |
void main() { | |
letterpile = querySelector("#letterpile"); | |
result = querySelector("#result"); | |
value = querySelector("#value"); | |
clearButton = querySelector("#clearButton"); | |
clearButton.onClick.listen(newletters); | |
generateNewLetters(); | |
} | |
void moveLetter(Event e) { | |
Element letter = e.target; | |
if (letter.parent == letterpile) { | |
result.children.add(letter); | |
wordvalue += scrabbleValues[letter.text]; | |
value.text = "$wordvalue"; | |
} else { | |
letterpile.children.add(letter); | |
wordvalue -= scrabbleValues[letter.text]; | |
value.text = "$wordvalue"; | |
} | |
} | |
void newletters(Event e) { | |
letterpile.children.clear(); | |
result.children.clear(); | |
generateNewLetters(); | |
} | |
generateNewLetters() { | |
Random indexGenerator = new Random(); | |
wordvalue = 0; | |
value.text = ''; | |
buttons.clear(); | |
for (var i = 0; i < 7; i++) { | |
int letterIndex = | |
indexGenerator.nextInt(scrabbleLetters.length); | |
// Should remove the letter from scrabbleLetters to keep the | |
// ratio correct. | |
buttons.add(new ButtonElement()); | |
buttons[i].classes.add("letter"); | |
buttons[i].onClick.listen(moveLetter); | |
buttons[i].text = scrabbleLetters[letterIndex]; | |
letterpile.children.add(buttons[i]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: #F8F8F8; | |
font-family: 'Open Sans', sans-serif; | |
font-size: 14px; | |
font-weight: normal; | |
line-height: 1.2em; | |
margin: 15px; | |
} | |
.letter { | |
width: 48px; | |
height: 48px; | |
font-size: 32px; | |
background-color: Lavender; | |
color: purple; | |
border: 1px solid black; | |
margin: 2px 2px 2px 2px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment