Shared board
diff --git a/lib/components/board.dart b/lib/components/board.dart
new file mode 100644
index 0000000..81720c1
--- /dev/null
+++ b/lib/components/board.dart
@@ -0,0 +1,100 @@
+import './card.dart' show Card;
+import '../logic/card.dart' as logic_card;
+import 'package:sky/widgets.dart' as widgets;
+import 'package:vector_math/vector_math.dart' as vector_math;
+import 'dart:math' as math;
+import 'package:sky/theme/colors.dart' as colors;
+
+const cardHeight = 96;
+const cardWidth = 71;
+
+class CardCluster extends widgets.Component {
+ List<int> cards; // the indicies of the 4 cards in the center, in clockwise order
+ CardCluster(this.cards);
+
+ widgets.Widget build() {
+
+ return new widgets.Container(
+ child: new widgets.Stack([
+ new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI).translate(0, -cardHeight / 2),
+ child: new Card(logic_card.Card.All[cards[0]], true)
+ ),
+ new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI/2.0).translate(0, cardWidth/2),
+ child: new Card(logic_card.Card.All[cards[1]], true)
+ ),
+ new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().translate(-cardWidth, cardWidth / 2),
+ child: new Card(logic_card.Card.All[cards[2]], true)
+ ),
+ new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI/2.0).translate(0, -cardHeight/2),
+ child: new Card(logic_card.Card.All[cards[3]], true)
+ )
+ ]));
+ }
+}
+
+class PlayerHand extends widgets.Component {
+ int count;
+ PlayerHand(this.count);
+
+ widgets.Widget build() {
+ List<widgets.Positioned> cards = [];
+ for (int i = 0; i < count; i++) {
+ cards.add(new widgets.Positioned(child: new Card(logic_card.Card.All[0], false),
+ top: 0.0,
+ left: cardWidth*i/2.0));
+ }
+ return new widgets.Stack(cards);
+ }
+}
+
+class Board extends widgets.Component {
+ CardCluster centerCluster;
+ List<PlayerHand> hands; // counts of cards in players hands, in clockwise order
+
+ Board(List<int> cards, List<int> playerHandCount) :
+ centerCluster = new CardCluster(cards) {
+ assert(playerHandCount.length == 4);
+ hands = new List<PlayerHand>();
+ for (int count in playerHandCount) {
+ hands.add(new PlayerHand(count));
+ }
+ }
+
+ widgets.Widget build() {
+ return new widgets.Container(
+ decoration: new widgets.BoxDecoration(backgroundColor: colors.Pink[500]),
+ child: new widgets.Stack(
+ [
+ new widgets.Positioned(child: hands[0],
+ top: 0.0,
+ left: 250.0),
+ new widgets.Positioned(child: new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI/2.0),
+ child: hands[1]
+ ),
+ left: 100.0,
+ top: 400.0),
+ new widgets.Positioned(child: new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI),
+ child: hands[2]
+ ),
+ top: 820.0,
+ left: 350.0),
+ new widgets.Positioned(child: new widgets.Transform(
+ transform: new vector_math.Matrix4.identity().rotateZ(math.PI/2.0),
+ child: hands[3]
+ ),
+ left: 500.0,
+ top: 400.0),
+ new widgets.Positioned(child: centerCluster,
+ top: 400.0,
+ left: 300.0),
+ ]
+ )
+ );
+ }
+}
diff --git a/lib/components/card.dart b/lib/components/card.dart
index e15eff4..f482ca9 100644
--- a/lib/components/card.dart
+++ b/lib/components/card.dart
@@ -1,6 +1,5 @@
import '../logic/card.dart' as logic_card;
import 'package:sky/widgets.dart' as widgets;
-import 'package:sky/theme/colors.dart' as colors;
class Card extends widgets.Component {
logic_card.Card card;
@@ -10,21 +9,7 @@
widgets.Widget build() {
return new widgets.Listener(
- child: new widgets.Container(
- child: new widgets.Container(
- decoration: new widgets.BoxDecoration(
- border: new widgets.Border.all(
- width: 3.0,
- color: colors.Red[500]
- ),
- backgroundColor: colors.Brown[500]
- ),
- child: new widgets.Flex([
- imageFromCard(card, faceUp),
- new widgets.Text('removethis')
- ], direction: widgets.FlexDirection.vertical)
- )
- )
+ child: imageFromCard(card, faceUp)
);
}
diff --git a/lib/components/game.dart b/lib/components/game.dart
index 9a229c2..da2c4d1 100644
--- a/lib/components/game.dart
+++ b/lib/components/game.dart
@@ -3,6 +3,7 @@
import 'card_collection.dart' show CardCollectionComponent, Orientation;
import 'package:sky/widgets/basic.dart';
import 'package:sky/theme/colors.dart' as colors;
+import 'board.dart' show Board;
class GameComponent extends StatefulComponent {
Game game;
@@ -17,6 +18,8 @@
switch (game.gameType) {
case GameType.Hearts:
return buildHearts();
+ // Code to display board:
+ // return new Board([2,3,4,5], [1, 2, 3, 4]);
default:
return null; // unsupported
}
diff --git a/lib/logic/card.dart b/lib/logic/card.dart
index 021495f..f637191 100644
--- a/lib/logic/card.dart
+++ b/lib/logic/card.dart
@@ -1,7 +1,65 @@
+import 'dart:collection';
+
class Card {
final String deck;
final String identifier;
+ static final List<Card> All = new UnmodifiableListView<Card>([
+ const Card("classic", "c1"),
+ const Card("classic", "c2"),
+ const Card("classic", "c3"),
+ const Card("classic", "c4"),
+ const Card("classic", "c5"),
+ const Card("classic", "c6"),
+ const Card("classic", "c7"),
+ const Card("classic", "c8"),
+ const Card("classic", "c9"),
+ const Card("classic", "c10"),
+ const Card("classic", "cj"),
+ const Card("classic", "cq"),
+ const Card("classic", "ck"),
+ const Card("classic", "d1"),
+ const Card("classic", "d2"),
+ const Card("classic", "d3"),
+ const Card("classic", "d4"),
+ const Card("classic", "d5"),
+ const Card("classic", "d6"),
+ const Card("classic", "d7"),
+ const Card("classic", "d8"),
+ const Card("classic", "d9"),
+ const Card("classic", "d10"),
+ const Card("classic", "dj"),
+ const Card("classic", "dq"),
+ const Card("classic", "dk"),
+ const Card("classic", "h1"),
+ const Card("classic", "h2"),
+ const Card("classic", "h3"),
+ const Card("classic", "h4"),
+ const Card("classic", "h5"),
+ const Card("classic", "h6"),
+ const Card("classic", "h7"),
+ const Card("classic", "h8"),
+ const Card("classic", "h9"),
+ const Card("classic", "h10"),
+ const Card("classic", "hj"),
+ const Card("classic", "hq"),
+ const Card("classic", "hk"),
+ const Card("classic", "s1"),
+ const Card("classic", "s2"),
+ const Card("classic", "s3"),
+ const Card("classic", "s4"),
+ const Card("classic", "s5"),
+ const Card("classic", "s6"),
+ const Card("classic", "s7"),
+ const Card("classic", "s8"),
+ const Card("classic", "s9"),
+ const Card("classic", "s10"),
+ const Card("classic", "sj"),
+ const Card("classic", "sq"),
+ const Card("classic", "sk"),
+ ]);
+
+
const Card(this.deck, this.identifier);
toString() => "${deck} ${identifier}";
diff --git a/lib/logic/game.dart b/lib/logic/game.dart
index 0aeaf9d..7f51861 100644
--- a/lib/logic/game.dart
+++ b/lib/logic/game.dart
@@ -10,60 +10,7 @@
class Game {
final GameType gameType;
final List<List<Card>> cardCollections = new List<List<Card>>();
- final List<Card> deck = <Card>[
- const Card("classic", "c1"),
- const Card("classic", "c2"),
- const Card("classic", "c3"),
- const Card("classic", "c4"),
- const Card("classic", "c5"),
- const Card("classic", "c6"),
- const Card("classic", "c7"),
- const Card("classic", "c8"),
- const Card("classic", "c9"),
- const Card("classic", "c10"),
- const Card("classic", "cj"),
- const Card("classic", "cq"),
- const Card("classic", "ck"),
- const Card("classic", "d1"),
- const Card("classic", "d2"),
- const Card("classic", "d3"),
- const Card("classic", "d4"),
- const Card("classic", "d5"),
- const Card("classic", "d6"),
- const Card("classic", "d7"),
- const Card("classic", "d8"),
- const Card("classic", "d9"),
- const Card("classic", "d10"),
- const Card("classic", "dj"),
- const Card("classic", "dq"),
- const Card("classic", "dk"),
- const Card("classic", "h1"),
- const Card("classic", "h2"),
- const Card("classic", "h3"),
- const Card("classic", "h4"),
- const Card("classic", "h5"),
- const Card("classic", "h6"),
- const Card("classic", "h7"),
- const Card("classic", "h8"),
- const Card("classic", "h9"),
- const Card("classic", "h10"),
- const Card("classic", "hj"),
- const Card("classic", "hq"),
- const Card("classic", "hk"),
- const Card("classic", "s1"),
- const Card("classic", "s2"),
- const Card("classic", "s3"),
- const Card("classic", "s4"),
- const Card("classic", "s5"),
- const Card("classic", "s6"),
- const Card("classic", "s7"),
- const Card("classic", "s8"),
- const Card("classic", "s9"),
- const Card("classic", "s10"),
- const Card("classic", "sj"),
- const Card("classic", "sq"),
- const Card("classic", "sk"),
- ];
+ final List<Card> deck = new List<Card>.from(Card.All);
final Random random = new Random();
String debugString = 'hello?';
@@ -112,4 +59,4 @@
}
return -1;
}
-}
\ No newline at end of file
+}