This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Polymer/master
6/17 master -> stable
- Loading branch information
Showing
41 changed files
with
855 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a Polymer port/implementation of https://github.com/IgorMinar/Memory-Game. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
@host { | ||
* { | ||
display: block; | ||
width: 165px; | ||
height: 200px; | ||
position: relative; | ||
-webkit-perspective: 800px; | ||
-moz-perspective: 800px; | ||
-ms-perspective: 800px; | ||
-o-perspective: 800px; | ||
perspective: 800px; | ||
} | ||
} | ||
|
||
.card { | ||
width: 100%; | ||
height: 100%; | ||
-webkit-transition: -webkit-transform 1s; | ||
-moz-transition: -moz-transform 1s; | ||
-ms-transition: -ms-transform 1s; | ||
-o-transition: -o-transform 1s; | ||
transition: transform 1s; | ||
-webkit-transform-style: preserve-3d; | ||
-moz-transform-style: preserve-3d; | ||
-ms-transform-style: preserve-3d; | ||
-o-transform-style: preserve-3d; | ||
transform-style: preserve-3d; | ||
} | ||
|
||
.card.flipped { | ||
-webkit-transform: rotateY( 180deg ); | ||
-moz-transform: rotateY( 180deg ); | ||
-ms-transform: rotateY( 180deg ); | ||
-o-transform: rotateY( 180deg ); | ||
transform: rotateY( 180deg ); | ||
} | ||
|
||
.card img { | ||
display: block; | ||
height: 100%; | ||
width: 100%; | ||
position: absolute; | ||
-webkit-backface-visibility: hidden; | ||
-moz-backface-visibility: hidden; | ||
-ms-backface-visibility: hidden; | ||
-o-backface-visibility: hidden; | ||
backface-visibility: hidden; | ||
} | ||
|
||
|
||
|
||
.card .back { | ||
background: blue; | ||
-webkit-transform: rotateY( 180deg ); | ||
-moz-transform: rotateY( 180deg ); | ||
-ms-transform: rotateY( 180deg ); | ||
-o-transform: rotateY( 180deg ); | ||
transform: rotateY( 180deg ); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict'; | ||
/* Memory Game Models and Business Logic */ | ||
|
||
function Tile(title) { | ||
this.title = title; | ||
this.flipped = false; | ||
} | ||
|
||
Tile.prototype.flip = function() { | ||
this.flipped = !this.flipped; | ||
} | ||
|
||
|
||
function Game(tileNames) { | ||
var tileDeck = makeDeck(tileNames); | ||
|
||
this.grid = makeGrid(tileDeck); | ||
this.message = Game.MESSAGE_CLICK; | ||
this.unmatchedPairs = tileNames.length; | ||
|
||
this.flipTile = function(tile) { | ||
if (tile.flipped) { | ||
return; | ||
} | ||
|
||
tile.flip(); | ||
|
||
if (!this.firstPick || this.secondPick) { | ||
|
||
if (this.secondPick) { | ||
this.firstPick.flip(); | ||
this.secondPick.flip(); | ||
this.firstPick = this.secondPick = undefined; | ||
} | ||
|
||
this.firstPick = tile; | ||
this.message = Game.MESSAGE_ONE_MORE; | ||
|
||
} else { | ||
|
||
if (this.firstPick.title === tile.title) { | ||
this.unmatchedPairs--; | ||
this.message = (this.unmatchedPairs > 0) ? Game.MESSAGE_MATCH : Game.MESSAGE_WON; | ||
this.firstPick = this.secondPick = undefined; | ||
} else { | ||
this.secondPick = tile; | ||
this.message = Game.MESSAGE_MISS; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Game.MESSAGE_CLICK = 'Click on a tile.'; | ||
Game.MESSAGE_ONE_MORE = 'Pick one more card.' | ||
Game.MESSAGE_MISS = 'Try again.'; | ||
Game.MESSAGE_MATCH = 'Good job! Keep going.'; | ||
Game.MESSAGE_WON = 'You win!'; | ||
|
||
|
||
/* Create an array with two of each tileName in it */ | ||
function makeDeck(tileNames) { | ||
var tileDeck = []; | ||
tileNames.forEach(function(name) { | ||
tileDeck.push(new Tile(name)); | ||
tileDeck.push(new Tile(name)); | ||
}); | ||
|
||
return tileDeck; | ||
} | ||
|
||
|
||
function makeGrid(tileDeck) { | ||
var gridDimension = Math.sqrt(tileDeck.length), | ||
grid = []; | ||
|
||
for (var row = 0; row < gridDimension; row++) { | ||
grid[row] = []; | ||
for (var col = 0; col < gridDimension; col++) { | ||
grid[row][col] = removeRandomTile(tileDeck); | ||
} | ||
} | ||
|
||
return grid; | ||
} | ||
|
||
|
||
function removeRandomTile(tileDeck) { | ||
var i = Math.floor(Math.random()*tileDeck.length); | ||
return tileDeck.splice(i, 1)[0]; | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Copyright 2013 The Polymer Authors. 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> | ||
<title>Memory Game</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<script src="../../polymer/polymer.js"></script> | ||
<script src="game.js"></script> | ||
|
||
<element name="g-card" attributes="tile"> | ||
<link rel="stylesheet" href="card.css"> | ||
<template> | ||
<div class="card {{ flipped: tile.flipped }}"> | ||
<img class="back" src="img/{{ tile.title }}.png"> | ||
<img class="front" src="img/back.png"> | ||
</div> | ||
</template> | ||
<script> | ||
Polymer.register(this, { | ||
}); | ||
</script> | ||
</element> | ||
|
||
<element name="match-game"> | ||
<template> | ||
<style> | ||
div { | ||
font-size: 30px; | ||
} | ||
</style> | ||
<div>Pairs left to match: {{ game.unmatchedPairs }}</div> | ||
<div>Matching: {{ game.firstPick.title }}</div> | ||
<table> | ||
<tr template repeat="{{ row in game.grid }}"> | ||
<td template repeat="{{ tile in row }}"> | ||
<g-card on-click="flip" tile="{{ tile }}"></g-card> | ||
</td> | ||
</tr> | ||
</table> | ||
<div class="message">{{ game.message }}</div> | ||
</template> | ||
<script> | ||
Polymer.register(this, { | ||
ready: function() { | ||
this.game = new Game(['8-ball', 'kronos', 'baked-potato', | ||
'dinosaur', 'rocket', 'skinny-unicorn', | ||
'that-guy', 'zeppelin']); | ||
}, | ||
flip: function(e, detail, target) { | ||
this.game.flipTile(target.templateInstance.model.tile); | ||
} | ||
}); | ||
</script> | ||
</element> | ||
|
||
</head> | ||
|
||
<body> | ||
<match-game></match-game> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
<script src="https://www.google.com/jsapi"></script> | ||
<script src="../../polymer/platform/WebAnimations/web-animations.js"></script> | ||
<link rel="import" href="../pica/components/pi-app.html"/> | ||
<pi-app></pi-app> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Polymer('x-foo', { | ||
ready: function() { | ||
this.style.color = 'blue'; | ||
} | ||
}); | ||
|
||
Polymer('x-bar', { | ||
ready: function() { | ||
this.style.padding = '4px'; | ||
this.style.backgroundColor = 'orange'; | ||
this.__proto__.__proto__.ready.call(this); | ||
}, | ||
parseElement: function() { | ||
this.webkitCreateShadowRoot().appendChild(document.createElement('content')); | ||
this.textContent = 'Override!'; | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script src="../../../platform/platform.js"></script> | ||
<script src="polymer-element.js"></script> | ||
<script src="elements.js"></script> | ||
</head> | ||
<body> | ||
|
||
<x-foo></x-foo> | ||
<hr> | ||
|
||
<x-bar></x-bar> | ||
<hr> | ||
|
||
<x-zot></x-zot> | ||
<hr> | ||
|
||
<x-baz></x-baz> | ||
<hr> | ||
|
||
<x-quux></x-quux> | ||
<hr | ||
|
||
<!-- preloaded external script --> | ||
<polymer-element name="x-foo"> | ||
<template> | ||
Hello Light World | ||
</template> | ||
</polymer-element> | ||
|
||
<!-- external script w/templating override --> | ||
<polymer-element name="x-bar" extends="x-foo"> | ||
<template> | ||
Hello Lighter World [<shadow></shadow>] | ||
</template> | ||
</polymer-element> | ||
|
||
<!-- no script --> | ||
<polymer-element name="x-zot" extends="x-foo"> | ||
<template> | ||
Hello Lighter World [<shadow></shadow>] | ||
</template> | ||
</polymer-element> | ||
|
||
<!-- inline script --> | ||
<polymer-element name="x-baz" extends="x-zot"> | ||
<script> | ||
Polymer('x-baz', { | ||
ready: function() { | ||
this.style.padding = '4px'; | ||
this.style.backgroundColor = 'tomato'; | ||
this.__proto__.__proto__.ready.call(this); | ||
} | ||
}); | ||
</script> | ||
</polymer-element> | ||
|
||
<!-- inline external script --> | ||
<polymer-element name="x-quux" extends="x-zot"> | ||
<script src="x-quux.js"></script> | ||
</polymer-element> | ||
|
||
<script> | ||
addEventListener("WebComponentsReady", function() { | ||
CustomElements.upgradeDocument(document); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.