├── .jshintrc
├── HISTORY.md
├── LICENSE
├── README.md
├── cards.ttf
├── img
├── JC.gif
├── JD.gif
├── JH.gif
├── JS.gif
├── KC.gif
├── KD.gif
├── KH.gif
├── KS.gif
├── N1.gif
├── N2.gif
├── QC.gif
├── QD.gif
├── QH.gif
├── QS.gif
└── cardsuits.png
├── index.html
├── playingCards.js
├── playingCards.ui.css
└── playingCards.ui.js
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "jquery":true
3 | }
--------------------------------------------------------------------------------
/HISTORY.md:
--------------------------------------------------------------------------------
1 | # 1.0.0
2 | * adding slow layout effect
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010 Adam Eivy (antic | atomantic)
2 | Dual licensed under the MIT and GPL licenses:
3 | * http://www.opensource.org/licenses/mit-license.php
4 | * http://www.gnu.org/licenses/gpl.html
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to
8 | deal in the Software without restriction, including without limitation the
9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 | sell copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 | IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # License
2 | JavaScript & CSS:
3 | @author Adam Eivy (antic | atomantic)
4 | @link [http://adameivy.com/JavaScript-Playing-Cards/](http://adameivy.com/JavaScript-Playing-Cards/)
5 |
6 | @license Copyright (c) 2010 Adam Eivy (antic | atomantic) Dual licensed under the MIT and GPL licenses:
7 | * [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
8 | * [http://www.gnu.org/licenses/gpl.html](http://www.gnu.org/licenses/gpl.html)
9 |
10 | Card Face images:
11 | @author David Bellot
12 | @link [http://david.bellot.free.fr/svg-cards/](http://david.bellot.free.fr/svg-cards/)
13 | @license [http://creativecommons.org/licenses/by-sa/2.5/](http://creativecommons.org/licenses/by-sa/2.5/)
14 |
15 | # What it does
16 |
17 | The library comes in multiple parts. You can either just use the playingCard.js library, which has no UI rendering (just creates deck objects with the standard methods) or you can add on the playingCards.ui.js library, which adds the ability to render the cards to the page.
18 |
19 | Note: This library was really just something that I wanted to build for the sake of proving out that a deck of cards could be implemented in JavaScript and CSS. I had no real-world use-case for it. Since throwing this out on Github, several people have started using this as a foundation for making games. That's awesome--but I haven't been working on this. I welcome pull-requests, but I also am not actively updating this codebase. The code is pretty simple and could probably stand some updating with newer standards (as it is several years old). You might be better off using this as a reference point / proof-of-concept :)
20 |
21 | If I were to re-write this for a particular game/use-case, I'd probably change the API a bit. Additionally, I'd add methods for managing hands/players, which is not part of the existing library.
22 |
23 | On the flip-side, since you obviously like playing cards, you might be interested in my hand-painted, beetle-themed playing card deck, which I'll be releasing to Kickstarter ~Aug 1, 2015: http://bit.ly/beetledeck
24 |
25 | # Usage
26 |
27 | If you are only using playingCards.js:
28 |
29 | var cardDeck = new playingCards(); // will create a new deck object
30 |
31 | If you are including jQuery, the playingCards.ui.js and playingCards.ui.css:
32 |
33 | $('#cardTable').playingCards(); // will lay out a random deck on the cardTable element
34 |
35 | override defaults for playingCards() and for card() by adding new properties to the following objects:
36 |
37 | playingCards.defaults
38 |
39 | playingCards.card.defaults
40 |
41 | ## Example Implementation
42 | For a rough example of implementation, look at the code for the demo page:
43 | https://github.com/atomantic/JavaScript-Playing-Cards/blob/master/index.html
44 |
45 | # API Docs (simple version)
46 |
47 | * init() - builds the deck (and shuffles it), automatically called when initializing an instance
48 | * shuffle() - shuffle the deck
49 | * orderByRank() - orders the existin cards by rank
50 | * orderBySuit() - calls init() again (TODO: this should probably order the existing cards in the deck by suit, but I was lazy)
51 | * spread($destinationElement, slowly) - (ui only) lay out the cards in the DOM, optionally with a slow placement
52 | * count() - return the number of cards remaining in the deck
53 | * addCard() - return a card from the drawn pile back to the top of the deck
54 | * draw() - draw a card from the top of the deck (stored in the draw pile)
55 |
56 | # Demo
57 |
58 | The repository holds a demo in index.html, which is published on the github project page:
59 | [Demo](http://atomantic.github.com/JavaScript-Playing-Cards)
60 |
--------------------------------------------------------------------------------
/cards.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/cards.ttf
--------------------------------------------------------------------------------
/img/JC.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/JC.gif
--------------------------------------------------------------------------------
/img/JD.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/JD.gif
--------------------------------------------------------------------------------
/img/JH.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/JH.gif
--------------------------------------------------------------------------------
/img/JS.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/JS.gif
--------------------------------------------------------------------------------
/img/KC.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/KC.gif
--------------------------------------------------------------------------------
/img/KD.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/KD.gif
--------------------------------------------------------------------------------
/img/KH.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/KH.gif
--------------------------------------------------------------------------------
/img/KS.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/KS.gif
--------------------------------------------------------------------------------
/img/N1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/N1.gif
--------------------------------------------------------------------------------
/img/N2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/N2.gif
--------------------------------------------------------------------------------
/img/QC.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/QC.gif
--------------------------------------------------------------------------------
/img/QD.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/QD.gif
--------------------------------------------------------------------------------
/img/QH.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/QH.gif
--------------------------------------------------------------------------------
/img/QS.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/QS.gif
--------------------------------------------------------------------------------
/img/cardsuits.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atomantic/JavaScript-Playing-Cards/e1dce08e18f554c129657012bbcec8c8d2c1e649/img/cardsuits.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
57 | A playing card JavaScript and CSS library for creating standard deck games. The library is wrapped to allow it to act as a plugin for jquery (or another framework)
58 |
59 |
60 |
This is really just a proof-of-concept that a deck of cards can be managed in JavaScript/CSS
61 |
You might be interested in my hand-painted, beetle-themed playing card deck, which I'll be releasing to Kickstarter ~Aug 1, 2015: http://bit.ly/beetledeck
62 |
License
63 |
MIT/GPL
64 |
65 |
66 |
67 |
Demo
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
Card Deck
77 |
78 |
79 |
Drawn Cards
80 |
81 |
82 |
83 |
84 |
166 |
167 |
Download
168 |
169 | You can download this project in either
170 | zip or
171 | tar formats.
172 |
173 |
You can also clone the project with Git
174 | by running:
175 |
');
89 | this.html = strBuild.join('');
90 | return this.html;
91 | };
92 | /**
93 | * build the middle of the playing card HTML
94 | *
95 | * @return string The HTML block for the middle of the card
96 | */
97 | playingCards.card.prototype.buildIconHTML = function() {
98 | // TODO: could we optimize this with a for loop that breaks/continues to named positions?
99 | if (this.rank === "A") {
100 | return ['
', this.suitCode, '
'];
101 | }
102 | if (this.rank === "J" || this.rank === "Q" || this.rank === "K" || this.rank === "N") {
103 | var n = 'D';
104 | var imgPrefix = this.conf.imgPrefix || '';
105 | if (!this.conf.singleFace) {
106 | n = this.suit;
107 | }
108 | return [
109 | '
', this.suitCode, '
',
110 | '',
111 | '
', this.suitCode, '
'
112 | ];
113 | }
114 | var ret = [],
115 | list = ['4', '5', '6', '7', '8', '9', '10'];
116 | // all of these will have A1, A5, C1, C5 icons
117 | if (list.indexOf(this.rank) !== -1) {
118 | ret = ret.concat([
119 | '
', this.suitCode, '
',
120 | '
', this.suitCode, '
',
121 | '
', this.suitCode, '
',
122 | '
', this.suitCode, '
'
123 | ]);
124 | }
125 | list = ['2', '3'];
126 | if (list.indexOf(this.rank) !== -1) {
127 | ret = ret.concat([
128 | '
', this.suitCode, '
',
129 | '
', this.suitCode, '
'
130 | ]);
131 | }
132 | list = ['3', '5', '9'];
133 | if (list.indexOf(this.rank) !== -1) {
134 | ret = ret.concat([
135 | '
', this.suitCode, '
'
136 | ]);
137 | }
138 | list = ['6', '7', '8'];
139 | if (list.indexOf(this.rank) !== -1) {
140 | ret = ret.concat([
141 | '
', this.suitCode, '
',
142 | '
', this.suitCode, '
'
143 | ]);
144 | }
145 | list = ['7', '8', '10'];
146 | if (list.indexOf(this.rank) !== -1) {
147 | ret = ret.concat([
148 | '
', this.suitCode, '
'
149 | ]);
150 | }
151 | list = ['8', '10'];
152 | if (list.indexOf(this.rank) !== -1) {
153 | ret = ret.concat([
154 | '
', this.suitCode, '
'
155 | ]);
156 | }
157 | list = ['9', '10'];
158 | if (list.indexOf(this.rank) !== -1) {
159 | ret = ret.concat([
160 | '