croupier: Dart Style Cleanups
Enum Values and Constants are now lowerCamelCase instead of
SCREAMING_CAPS.
I use VoidCallback wherever it's imported, though some typedefs of NoArgCb
had to be kept. I renamed those to VoidCallback for consistency.
Change-Id: Ib53ae4035c91c922cd8b3810e0c1062bfc567f3a
diff --git a/lib/components/board.dart b/lib/components/board.dart
index 1e5d9ad..dc80c64 100644
--- a/lib/components/board.dart
+++ b/lib/components/board.dart
@@ -10,7 +10,7 @@
import '../logic/card.dart' as logic_card;
import '../logic/croupier.dart' show Croupier;
-import '../logic/game/game.dart' show Game, GameType, NoArgCb;
+import '../logic/game/game.dart' show Game, GameType;
import '../logic/hearts/hearts.dart' show HeartsGame, HeartsPhase;
import '../sound/sound_assets.dart';
import '../styles/common.dart' as style;
@@ -55,7 +55,7 @@
final SoundAssets sounds;
final bool isMini;
final AcceptCb gameAcceptCallback;
- final NoArgCb setGameStateCallback;
+ final VoidCallback setGameStateCallback;
final List<logic_card.Card> bufferedPlay;
HeartsGame get game => super.game;
@@ -100,8 +100,8 @@
void _handleCardCounterSounds() {
// Ensure we have the right state while we deal and score.
- if (config.game.phase == HeartsPhase.Deal ||
- config.game.phase == HeartsPhase.Score) {
+ if (config.game.phase == HeartsPhase.deal ||
+ config.game.phase == HeartsPhase.score) {
cardCounter = 0;
passing = true;
}
@@ -169,7 +169,7 @@
_handleLocalAskingReset();
Widget boardChild;
- if (config.game.phase == HeartsPhase.Play) {
+ if (config.game.phase == HeartsPhase.play) {
boardChild =
config.isMini ? _buildMiniBoardLayout() : _buildBoardLayout();
} else {
@@ -217,8 +217,8 @@
Widget _buildPassLayout() {
String passBackground = ""; // It's possible to have no background.
- if (config.game.phase == HeartsPhase.Pass ||
- config.game.phase == HeartsPhase.Take) {
+ if (config.game.phase == HeartsPhase.pass ||
+ config.game.phase == HeartsPhase.take) {
passBackground = passBackgrounds[config.game.roundNumber % 4];
}
@@ -258,7 +258,7 @@
int takeTarget = game.getTakeTarget(playerNumber);
if (takeTarget != null) {
cardsToTake = game.cardCollections[
- game.getTakeTarget(playerNumber) + HeartsGame.OFFSET_PASS];
+ game.getTakeTarget(playerNumber) + HeartsGame.offsetPass];
}
bool isHorz = playerNumber % 2 == 0;
@@ -346,7 +346,7 @@
bool isMe = playerNumber == p;
List<logic_card.Card> showCard =
- game.cardCollections[playerNumber + HeartsGame.OFFSET_PLAY];
+ game.cardCollections[playerNumber + HeartsGame.offsetPlay];
bool hasPlayed = showCard.length > 0;
bool isTurn = playerNumber == game.whoseTurn && !hasPlayed;
if (isMe && config.bufferedPlay != null) {
@@ -389,7 +389,7 @@
HeartsGame game = config.game;
int numTrickCards =
- game.cardCollections[HeartsGame.OFFSET_TRICK + pNum].length;
+ game.cardCollections[HeartsGame.offsetTrick + pNum].length;
int numTricks = numTrickCards ~/ 4;
String s = numTricks != 1 ? "s" : "";
@@ -568,7 +568,7 @@
Widget _buildCenterCard(int playerNumber) {
HeartsGame game = config.game;
List<logic_card.Card> cards =
- game.cardCollections[playerNumber + HeartsGame.OFFSET_PLAY];
+ game.cardCollections[playerNumber + HeartsGame.offsetPlay];
// TODO(alexfandrianto): Clean up soon.
// https://github.com/vanadium/issues/issues/1098
@@ -620,9 +620,9 @@
HeartsGame game = config.game;
List<logic_card.Card> cards = new List.from(
- game.cardCollections[playerNumber + HeartsGame.OFFSET_TRICK]);
+ game.cardCollections[playerNumber + HeartsGame.offsetTrick]);
- bool isPlay = game.phase == HeartsPhase.Play;
+ bool isPlay = game.phase == HeartsPhase.play;
// Prevent over-expansion of cards until a card has been played.
bool alreadyPlaying =
@@ -631,11 +631,11 @@
double sizeFactor = 1.0;
if (config.isMini) {
if (playerNumber != game.playerNumber) {
- cards.addAll(
- game.cardCollections[playerNumber + HeartsGame.OFFSET_HAND]);
+ cards
+ .addAll(game.cardCollections[playerNumber + HeartsGame.offsetHand]);
}
} else {
- cards.addAll(game.cardCollections[playerNumber + HeartsGame.OFFSET_HAND]);
+ cards.addAll(game.cardCollections[playerNumber + HeartsGame.offsetHand]);
if (alreadyPlaying) {
sizeFactor = this._centerScaleFactor;
@@ -648,6 +648,6 @@
heightCard: config.cardHeight * sizeFactor,
useKeys: true,
rotation: config.isMini ? null : _rotationAngle(playerNumber),
- animationType: component_card.CardAnimationType.LONG);
+ animationType: component_card.CardAnimationType.long);
}
}
diff --git a/lib/components/card.dart b/lib/components/card.dart
index 92c5ff8..afaddbf 100644
--- a/lib/components/card.dart
+++ b/lib/components/card.dart
@@ -9,9 +9,9 @@
import '../logic/card.dart' as logic_card;
-enum CardAnimationType { NONE, NORMAL, LONG }
+enum CardAnimationType { none, normal, long }
-enum CardUIType { CARD, ZCARD }
+enum CardUIType { card, zCard }
typedef void TapCallback(logic_card.Card card);
@@ -48,7 +48,7 @@
final Point endingPosition;
ZCard(Card dataComponent, this.startingPosition, this.endingPosition)
- : super(key: new GlobalCardKey(dataComponent.card, CardUIType.ZCARD)),
+ : super(key: new GlobalCardKey(dataComponent.card, CardUIType.zCard)),
card = dataComponent.card,
faceUp = dataComponent.faceUp,
width = dataComponent.width ?? 40.0,
@@ -81,13 +81,13 @@
CardAnimationType animationType,
this.tapCallback,
this.z})
- : animationType = animationType ?? CardAnimationType.NONE,
+ : animationType = animationType ?? CardAnimationType.none,
card = card,
width = width ?? 40.0,
height = height ?? 40.0,
rotation = rotation ?? 0.0,
useKey = useKey,
- super(key: useKey ? new GlobalCardKey(card, CardUIType.CARD) : null);
+ super(key: useKey ? new GlobalCardKey(card, CardUIType.card) : null);
// Use this helper to help create a Card clone.
// Used by the drag and drop layer.
@@ -98,7 +98,7 @@
rotation: rotation,
useKey: false,
visible: visible ?? this.visible,
- animationType: CardAnimationType.NONE,
+ animationType: CardAnimationType.none,
z: z);
}
@@ -120,8 +120,6 @@
}
class CardState extends widgets.State<Card> {
- // TODO(alexfandrianto): This bug is why some cards appear slightly off.
- // https://github.com/flutter/engine/issues/1939
Point getGlobalPosition() {
RenderBox box = context.findRenderObject();
return box.localToGlobal(Point.origin);
@@ -186,11 +184,11 @@
Duration get animationDuration {
switch (config.animationType) {
- case CardAnimationType.NONE:
+ case CardAnimationType.none:
return const Duration(milliseconds: 0);
- case CardAnimationType.NORMAL:
+ case CardAnimationType.normal:
return const Duration(milliseconds: 200);
- case CardAnimationType.LONG:
+ case CardAnimationType.long:
return const Duration(milliseconds: 1000);
default:
print("Unexpected animation type: ${config.animationType}");
@@ -217,7 +215,7 @@
// A callback that sets up the animation from point a to point b.
void _updatePosition() {
- if (config.animationType == CardAnimationType.NONE ||
+ if (config.animationType == CardAnimationType.none ||
_pointQueue.length == 1) {
Point endingLocation = config.endingPosition;
_positionTween =
diff --git a/lib/components/card_collection.dart b/lib/components/card_collection.dart
index 99994a7..2227b2e 100644
--- a/lib/components/card_collection.dart
+++ b/lib/components/card_collection.dart
@@ -12,7 +12,7 @@
enum DropType {
none,
card,
- card_collection
+ cardCollection
// I can see that both would be nice, but I'm not sure how to do that yet.
}
@@ -65,7 +65,7 @@
Color altColor,
this.rotation: 0.0,
this.useKeys: false,
- this.animationType: component_card.CardAnimationType.NORMAL})
+ this.animationType: component_card.CardAnimationType.normal})
: _acceptType = acceptType,
_backgroundColor = backgroundColor,
_altColor = altColor;
@@ -314,8 +314,7 @@
width: config.widthCard,
height: config.heightCard,
rotation: config.rotation,
- visible:
- !config.useKeys, // TODO(alexfandrianto): Is there a case where you want an invisible card and a key?
+ visible: !config.useKeys,
useKey: config.useKeys,
z: 0.0 + i,
tapCallback: config.cardTapCallback,
@@ -347,7 +346,7 @@
width: this.desiredWidth,
child: wrapCards(cardComponents));
});
- case DropType.card_collection:
+ case DropType.cardCollection:
return new DragTarget<CardCollectionComponent>(
onWillAccept: _handleWillAcceptMultiple,
onAccept: _handleAcceptMultiple, builder:
diff --git a/lib/components/croupier.dart b/lib/components/croupier.dart
index e4476d7..9b46dda 100644
--- a/lib/components/croupier.dart
+++ b/lib/components/croupier.dart
@@ -16,8 +16,6 @@
import 'croupier_profile.dart' show CroupierProfileComponent;
import 'game.dart' as component_game;
-typedef void NoArgCb();
-
GlobalObjectKey _gameKey = new GlobalObjectKey("CroupierGameKey");
GlobalObjectKey _gameArrangeKey = new GlobalObjectKey("CroupierGameArrangeKey");
@@ -31,7 +29,7 @@
}
class CroupierComponentState extends State<CroupierComponent> {
- NoArgCb makeSetStateCallback(logic_croupier.CroupierState s,
+ VoidCallback makeSetStateCallback(logic_croupier.CroupierState s,
[var data = null]) {
return () => setState(() {
config.croupier.setState(s, data);
@@ -40,7 +38,7 @@
Widget build(BuildContext context) {
switch (config.croupier.state) {
- case logic_croupier.CroupierState.Welcome:
+ case logic_croupier.CroupierState.welcome:
// in which we show them a UI to start a new game, join a game, or change some settings.
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
@@ -48,16 +46,16 @@
new FlatButton(
child: new Text('Create Game', style: style.Text.titleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.ChooseGame)),
+ logic_croupier.CroupierState.chooseGame)),
new FlatButton(
child: new Text('Join Game', style: style.Text.titleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.JoinGame)),
+ logic_croupier.CroupierState.joinGame)),
new FlatButton(
child: new Text('Resume Game', style: style.Text.titleStyle),
onPressed: config.croupier.settings.hasLastGame
? makeSetStateCallback(
- logic_croupier.CroupierState.ResumeGame,
+ logic_croupier.CroupierState.resumeGame,
config.croupier.settings.lastGameID)
: null),
new CroupierProfileComponent(
@@ -65,7 +63,7 @@
width: style.Size.settingsWidth,
height: style.Size.settingsHeight)
]));
- case logic_croupier.CroupierState.ChooseGame:
+ case logic_croupier.CroupierState.chooseGame:
// in which we let them pick a game out of the many possible games... There aren't that many.
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
@@ -73,26 +71,26 @@
new FlatButton(
child: new Text('Proto', style: style.Text.titleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.ArrangePlayers,
- logic_game.GameType.Proto)),
+ logic_croupier.CroupierState.arrangePlayers,
+ logic_game.GameType.proto)),
new FlatButton(
child: new Text('Hearts', style: style.Text.titleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.ArrangePlayers,
- logic_game.GameType.Hearts)),
+ logic_croupier.CroupierState.arrangePlayers,
+ logic_game.GameType.hearts)),
new FlatButton(
child: new Text('Poker', style: style.Text.titleStyle)),
new FlatButton(
child: new Text('Solitaire', style: style.Text.titleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.ArrangePlayers,
- logic_game.GameType.Solitaire)),
+ logic_croupier.CroupierState.arrangePlayers,
+ logic_game.GameType.solitaire)),
new FlatButton(
child: new Text('Back', style: style.Text.subtitleStyle),
onPressed: makeSetStateCallback(
- logic_croupier.CroupierState.Welcome))
+ logic_croupier.CroupierState.welcome))
]));
- case logic_croupier.CroupierState.JoinGame:
+ case logic_croupier.CroupierState.joinGame:
// A stateful view, showing the game ads discovered.
List<Widget> gameAdWidgets = new List<Widget>();
if (config.croupier.games_found.length == 0) {
@@ -108,35 +106,35 @@
CroupierSettings cs = config.croupier.settings_everyone[gsd.ownerID];
gameAdWidgets.add(new CroupierGameAdvertisementComponent(gsd,
onTap: makeSetStateCallback(
- logic_croupier.CroupierState.ArrangePlayers, gsd),
+ logic_croupier.CroupierState.arrangePlayers, gsd),
settings: cs));
});
gameAdWidgets.add(new FlatButton(
child: new Text('Back', style: style.Text.subtitleStyle),
onPressed:
- makeSetStateCallback(logic_croupier.CroupierState.Welcome)));
+ makeSetStateCallback(logic_croupier.CroupierState.welcome)));
// in which players wait for game invitations to arrive.
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
child: new Column(children: gameAdWidgets));
- case logic_croupier.CroupierState.ArrangePlayers:
+ case logic_croupier.CroupierState.arrangePlayers:
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
child: _buildArrangePlayers());
- case logic_croupier.CroupierState.PlayGame:
+ case logic_croupier.CroupierState.playGame:
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
child: component_game.createGameComponent(
config.croupier,
config.sounds,
- makeSetStateCallback(logic_croupier.CroupierState.Welcome),
+ makeSetStateCallback(logic_croupier.CroupierState.welcome),
width: ui.window.size.width,
height: ui.window.size.height - ui.window.padding.top,
key: _gameKey));
- case logic_croupier.CroupierState.ResumeGame:
+ case logic_croupier.CroupierState.resumeGame:
return new Container(
padding: new EdgeDims.only(top: ui.window.padding.top),
child: new Text("Resuming Game...", style: style.Text.titleStyle),
@@ -209,7 +207,7 @@
// Allow games that can start with these players to begin.
// Debug Mode should also go through.
- NoArgCb startCb;
+ VoidCallback startCb;
if (gad.canStart(playerNumbers) || config.croupier.debugMode) {
startCb = () {
config.croupier.settings_manager
@@ -237,7 +235,7 @@
child: new FlatButton(
child: new Text('Back'),
onPressed:
- makeSetStateCallback(logic_croupier.CroupierState.Welcome))));
+ makeSetStateCallback(logic_croupier.CroupierState.welcome))));
return new Column(children: allWidgets);
}
diff --git a/lib/components/croupier_game_advertisement.dart b/lib/components/croupier_game_advertisement.dart
index fb7fcac..2042d3f 100644
--- a/lib/components/croupier_game_advertisement.dart
+++ b/lib/components/croupier_game_advertisement.dart
@@ -9,12 +9,10 @@
import '../logic/game/game.dart' as game;
import '../styles/common.dart' as style;
-typedef void NoArgCb();
-
class CroupierGameAdvertisementComponent extends StatelessComponent {
final CroupierSettings settings;
final game.GameStartData gameStartData;
- final NoArgCb onTap;
+ final VoidCallback onTap;
CroupierGameAdvertisementComponent(this.gameStartData,
{CroupierSettings settings, this.onTap})
diff --git a/lib/components/croupier_profile.dart b/lib/components/croupier_profile.dart
index 9f079a4..e25f0ab 100644
--- a/lib/components/croupier_profile.dart
+++ b/lib/components/croupier_profile.dart
@@ -8,10 +8,10 @@
import '../styles/common.dart' as style;
enum CroupierProfileComponentOrientation {
- DEFAULT,
- MINI,
- HORIZONTAL,
- TEXT_ONLY
+ standard,
+ mini,
+ horizontal,
+ textOnly
}
class CroupierProfileComponent extends StatelessComponent {
@@ -26,7 +26,7 @@
{CroupierSettings settings,
this.height,
this.width,
- this.orientation: CroupierProfileComponentOrientation.DEFAULT})
+ this.orientation: CroupierProfileComponentOrientation.standard})
: settings = settings ?? new CroupierSettings.placeholder();
CroupierProfileComponent.mini(
@@ -35,21 +35,21 @@
settings: settings,
height: height,
width: width,
- orientation: CroupierProfileComponentOrientation.MINI);
+ orientation: CroupierProfileComponentOrientation.mini);
CroupierProfileComponent.horizontal({CroupierSettings settings})
: this(
settings: settings,
- orientation: CroupierProfileComponentOrientation.HORIZONTAL);
+ orientation: CroupierProfileComponentOrientation.horizontal);
CroupierProfileComponent.textOnly({CroupierSettings settings})
: this(
settings: settings,
- orientation: CroupierProfileComponentOrientation.TEXT_ONLY);
+ orientation: CroupierProfileComponentOrientation.textOnly);
Widget build(BuildContext context) {
switch (orientation) {
- case CroupierProfileComponentOrientation.DEFAULT:
+ case CroupierProfileComponentOrientation.standard:
return new Container(
height: this.height,
width: this.width,
@@ -61,7 +61,7 @@
name: CroupierSettings.makeAvatarUrl(settings.avatar)),
new Text(settings.name, style: style.Text.largeStyle)
], justifyContent: FlexJustifyContent.spaceAround)));
- case CroupierProfileComponentOrientation.MINI:
+ case CroupierProfileComponentOrientation.mini:
return new Container(
width: this.width,
height: this.height,
@@ -73,7 +73,7 @@
name: CroupierSettings.makeAvatarUrl(settings.avatar),
fit: ImageFit.scaleDown)
], justifyContent: FlexJustifyContent.spaceAround)));
- case CroupierProfileComponentOrientation.HORIZONTAL:
+ case CroupierProfileComponentOrientation.horizontal:
return new Card(
color: new Color(settings.color),
child: new Container(
@@ -84,7 +84,7 @@
fit: ImageFit.scaleDown),
new Text(settings.name, style: style.Text.hugeStyle)
], justifyContent: FlexJustifyContent.collapse)));
- case CroupierProfileComponentOrientation.TEXT_ONLY:
+ case CroupierProfileComponentOrientation.textOnly:
return new Card(
color: new Color(settings.color),
child: new Container(
diff --git a/lib/components/croupier_settings.dart b/lib/components/croupier_settings.dart
index 7779e39..4739e68 100644
--- a/lib/components/croupier_settings.dart
+++ b/lib/components/croupier_settings.dart
@@ -6,7 +6,6 @@
import 'package:flutter/material.dart';
-typedef void NoArgCb();
typedef void OneStringCb(String data);
typedef void SaveDataCb(int userID, String jsonData);
@@ -53,13 +52,13 @@
_tempData[avatarKey] = config.settings.avatar;
}
- Widget _makeColoredRectangle(int colorInfo, String text, NoArgCb cb) {
+ Widget _makeColoredRectangle(int colorInfo, String text, VoidCallback cb) {
return new Container(
decoration: new BoxDecoration(backgroundColor: new Color(colorInfo)),
child: new FlatButton(child: new Text(""), onPressed: cb));
}
- Widget _makeImageButton(String url, NoArgCb cb) {
+ Widget _makeImageButton(String url, VoidCallback cb) {
return new FlatButton(
child: new AssetImage(name: CroupierSettings.makeAvatarUrl(url)),
onPressed: cb);
diff --git a/lib/components/game.dart b/lib/components/game.dart
index 9f2c5a9..c5f3ff1 100644
--- a/lib/components/game.dart
+++ b/lib/components/game.dart
@@ -29,13 +29,11 @@
part 'proto/proto.part.dart';
part 'solitaire/solitaire.part.dart';
-typedef void NoArgCb();
-
abstract class GameComponent extends StatefulComponent {
final Croupier croupier;
final SoundAssets sounds;
Game get game => croupier.game;
- final NoArgCb gameEndCallback;
+ final VoidCallback gameEndCallback;
final double width;
final double height;
@@ -74,7 +72,7 @@
}
// A helper that subclasses might override to create buttons.
- Widget _makeButton(String text, NoArgCb callback) {
+ Widget _makeButton(String text, VoidCallback callback) {
return new FlatButton(
child: new Text(text, style: style.Text.liveNow), onPressed: callback);
}
@@ -95,7 +93,7 @@
void _cardLevelMapProcess(logic_card.Card logicCard) {
component_card.GlobalCardKey key = new component_card.GlobalCardKey(
- logicCard, component_card.CardUIType.CARD);
+ logicCard, component_card.CardUIType.card);
component_card.CardState cardState = key.currentState;
if (cardState == null) {
return; // There's nothing we can really do about this card since it hasn't drawn yet.
@@ -130,7 +128,7 @@
// We also need confirmation from the ZCard that we are moving.
component_card.GlobalCardKey zCardKey =
- new component_card.GlobalCardKey(c, component_card.CardUIType.ZCARD);
+ new component_card.GlobalCardKey(c, component_card.CardUIType.zCard);
component_card.ZCardState zCardKeyState = zCardKey.currentState;
// It is moving if there is an old position, the new one isn't equal to the
@@ -203,16 +201,16 @@
}
GameComponent createGameComponent(
- Croupier croupier, SoundAssets sounds, NoArgCb gameEndCallback,
+ Croupier croupier, SoundAssets sounds, VoidCallback gameEndCallback,
{Key key, double width, double height}) {
switch (croupier.game.gameType) {
- case GameType.Proto:
+ case GameType.proto:
return new ProtoGameComponent(croupier, sounds, gameEndCallback,
key: key, width: width, height: height);
- case GameType.Hearts:
+ case GameType.hearts:
return new HeartsGameComponent(croupier, sounds, gameEndCallback,
key: key, width: width, height: height);
- case GameType.Solitaire:
+ case GameType.solitaire:
return new SolitaireGameComponent(croupier, sounds, gameEndCallback,
key: key, width: width, height: height);
default:
@@ -233,7 +231,7 @@
GameArrangeComponent createGameArrangeComponent(Croupier croupier,
{double width, double height, Key key}) {
switch (croupier.game.gameType) {
- case GameType.Hearts:
+ case GameType.hearts:
return new HeartsArrangeComponent(croupier,
width: width, height: height, key: key);
default:
diff --git a/lib/components/hearts/hearts.part.dart b/lib/components/hearts/hearts.part.dart
index 1ddd970..1324d43 100644
--- a/lib/components/hearts/hearts.part.dart
+++ b/lib/components/hearts/hearts.part.dart
@@ -5,7 +5,7 @@
part of game_component;
class HeartsGameComponent extends GameComponent {
- HeartsGameComponent(Croupier croupier, SoundAssets sounds, NoArgCb cb,
+ HeartsGameComponent(Croupier croupier, SoundAssets sounds, VoidCallback cb,
{Key key, double width, double height})
: super(croupier, sounds, cb, key: key, width: width, height: height);
@@ -47,7 +47,7 @@
bool get _canBuffer {
HeartsGame game = config.game;
List<logic_card.Card> playCards =
- game.cardCollections[HeartsGame.OFFSET_PLAY + game.playerNumber];
+ game.cardCollections[HeartsGame.offsetPlay + game.playerNumber];
return game.isPlayer && game.numPlayed >= 1 && playCards.length == 0;
}
@@ -75,7 +75,7 @@
// Set a flag to ensure that we only play it once.
if (_shouldUnbuffer) {
_makeGameMoveCallback(bufferedPlay[0],
- game.cardCollections[HeartsGame.OFFSET_PLAY + game.playerNumber]);
+ game.cardCollections[HeartsGame.offsetPlay + game.playerNumber]);
bufferedPlaying = true;
}
@@ -96,34 +96,31 @@
height: config.height,
child: heartsWidget));
List<int> visibleCardCollectionIndexes = new List<int>();
- if (game.phase != HeartsPhase.Deal && game.phase != HeartsPhase.Score) {
+ if (game.phase != HeartsPhase.deal && game.phase != HeartsPhase.score) {
int playerNum = game.playerNumber;
- if (game.viewType == HeartsType.Player) {
+ if (game.viewType == HeartsType.player) {
switch (game.phase) {
- case HeartsPhase.Pass:
- visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_PASS + playerNum);
- visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_HAND + playerNum);
+ case HeartsPhase.pass:
+ visibleCardCollectionIndexes.add(HeartsGame.offsetPass + playerNum);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetHand + playerNum);
break;
- case HeartsPhase.Take:
+ case HeartsPhase.take:
visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_PASS + game.takeTarget);
- visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_HAND + playerNum);
+ .add(HeartsGame.offsetPass + game.takeTarget);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetHand + playerNum);
break;
- case HeartsPhase.Play:
+ case HeartsPhase.play:
if (_showSplitView) {
for (int i = 0; i < 4; i++) {
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_HAND + i);
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_TRICK + i);
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_PLAY + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetHand + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetTrick + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetPlay + i);
}
} else {
visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_PLAY + playerNum);
+ .add(HeartsGame.offsetPlay + playerNum);
visibleCardCollectionIndexes
- .add(HeartsGame.OFFSET_HAND + playerNum);
+ .add(HeartsGame.offsetHand + playerNum);
}
break;
@@ -133,10 +130,10 @@
} else {
// A board will need to see these things.
for (int i = 0; i < 4; i++) {
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_PLAY + i);
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_PASS + i);
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_HAND + i);
- visibleCardCollectionIndexes.add(HeartsGame.OFFSET_TRICK + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetPlay + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetPass + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetHand + i);
+ visibleCardCollectionIndexes.add(HeartsGame.offsetTrick + i);
}
}
}
@@ -151,10 +148,10 @@
void _switchViewCallback() {
HeartsGame game = config.game;
setState(() {
- if (game.viewType == HeartsType.Player) {
- game.viewType = HeartsType.Board;
+ if (game.viewType == HeartsType.player) {
+ game.viewType = HeartsType.board;
} else {
- game.viewType = HeartsType.Player;
+ game.viewType = HeartsType.player;
if (!game.isPlayer) {
game.playerNumber = 0; // avoid accidental red screen
}
@@ -324,7 +321,8 @@
}
@override
- Widget _makeButton(String text, NoArgCb callback, {bool inactive: false}) {
+ Widget _makeButton(String text, VoidCallback callback,
+ {bool inactive: false}) {
var borderColor = inactive ? Colors.grey[500] : Colors.white;
var backgroundColor = inactive ? Colors.grey[500] : null;
return new FlatButton(
@@ -338,20 +336,20 @@
}
Widget buildHearts() {
- if (config.game.viewType == HeartsType.Board) {
+ if (config.game.viewType == HeartsType.board) {
return buildHeartsBoard();
}
switch (config.game.phase) {
- case HeartsPhase.Deal:
+ case HeartsPhase.deal:
return showDeal();
- case HeartsPhase.Pass:
+ case HeartsPhase.pass:
return showPass();
- case HeartsPhase.Take:
+ case HeartsPhase.take:
return showTake();
- case HeartsPhase.Play:
+ case HeartsPhase.play:
return showPlay();
- case HeartsPhase.Score:
+ case HeartsPhase.score:
return showScore();
default:
assert(false);
@@ -362,13 +360,13 @@
Widget buildHeartsBoard() {
List<Widget> kids = new List<Widget>();
switch (config.game.phase) {
- case HeartsPhase.Deal:
- case HeartsPhase.Pass:
- case HeartsPhase.Take:
- case HeartsPhase.Play:
+ case HeartsPhase.deal:
+ case HeartsPhase.pass:
+ case HeartsPhase.take:
+ case HeartsPhase.play:
kids.add(showBoard());
break;
- case HeartsPhase.Score:
+ case HeartsPhase.score:
return showScore();
default:
assert(false);
@@ -398,7 +396,7 @@
bool isPlayer = false;
bool isError = false;
switch (game.phase) {
- case HeartsPhase.Play:
+ case HeartsPhase.play:
// Who's turn is it?
String name = _getName(game.whoseTurn) ?? "Player ${game.whoseTurn}";
isPlayer = game.whoseTurn == game.playerNumber;
@@ -412,7 +410,7 @@
status = isPlayer ? "Your trick" : "${trickTaker}'s trick";
}
break;
- case HeartsPhase.Pass:
+ case HeartsPhase.pass:
if (game.hasPassed(game.playerNumber)) {
status = "Waiting for cards...";
} else {
@@ -422,7 +420,7 @@
isPlayer = true;
}
break;
- case HeartsPhase.Take:
+ case HeartsPhase.take:
if (game.hasTaken(game.playerNumber)) {
status = "Waiting for other players...";
} else {
@@ -448,8 +446,8 @@
Widget _buildNumTrickIcon() {
HeartsGame game = config.game;
- int numTrickCards = game.cardCollections[
- HeartsGame.OFFSET_TRICK + game.playerNumber].length;
+ int numTrickCards =
+ game.cardCollections[HeartsGame.offsetTrick + game.playerNumber].length;
int numTricks = numTrickCards ~/ 4;
String iconName = "image/filter_9_plus";
@@ -471,7 +469,7 @@
flex: 1, child: new Text(status.text, style: style.Text.largeStyle)));
switch (game.phase) {
- case HeartsPhase.Play:
+ case HeartsPhase.play:
if (game.allPlayed &&
game.determineTrickWinner() == game.playerNumber &&
_showSplitView) {
@@ -494,8 +492,8 @@
});
}));
break;
- case HeartsPhase.Pass:
- case HeartsPhase.Take:
+ case HeartsPhase.pass:
+ case HeartsPhase.take:
// TODO(alexfandrianto): Icons for arrow_upward and arrow_downward were
// just added to the material icon list. However, they are not available
// through Flutter yet.
@@ -508,7 +506,7 @@
rotationAngle = -math.PI / 2; // up
break;
}
- if (game.phase == HeartsPhase.Take) {
+ if (game.phase == HeartsPhase.take) {
rotationAngle = rotationAngle + math.PI; // opposite
}
statusBarWidgets.add(new Transform(
@@ -558,7 +556,7 @@
List<Widget> cardCollections = new List<Widget>();
List<logic_card.Card> playOrBuffer =
- game.cardCollections[p + HeartsGame.OFFSET_PLAY];
+ game.cardCollections[p + HeartsGame.offsetPlay];
if (playOrBuffer.length == 0) {
playOrBuffer = bufferedPlay;
}
@@ -707,7 +705,7 @@
List<logic_card.Card> c3,
List<logic_card.Card> hand,
AcceptCb cb,
- NoArgCb buttoncb) {
+ VoidCallback buttoncb) {
bool completed = (buttoncb == null);
bool draggable = (cb != null) && !completed;
@@ -764,7 +762,7 @@
Widget _topCardWidget(List<logic_card.Card> cards, AcceptCb cb) {
HeartsGame game = config.game;
List<logic_card.Card> passCards =
- game.cardCollections[game.playerNumber + HeartsGame.OFFSET_PASS];
+ game.cardCollections[game.playerNumber + HeartsGame.offsetPass];
Widget ccc = new CardCollectionComponent(
cards, true, CardCollectionOrientation.show1,
@@ -789,7 +787,7 @@
HeartsGame game = config.game;
List<logic_card.Card> passCards =
- game.cardCollections[game.playerNumber + HeartsGame.OFFSET_PASS];
+ game.cardCollections[game.playerNumber + HeartsGame.offsetPass];
List<logic_card.Card> playerCards = game.cardCollections[game.playerNumber];
List<logic_card.Card> remainingCards = new List<logic_card.Card>();
@@ -819,7 +817,7 @@
List<logic_card.Card> playerCards = game.cardCollections[game.playerNumber];
List<logic_card.Card> takeCards =
- game.cardCollections[game.takeTarget + HeartsGame.OFFSET_PASS];
+ game.cardCollections[game.takeTarget + HeartsGame.offsetPass];
bool hasTaken = takeCards.length == 0;
diff --git a/lib/components/main_route.dart b/lib/components/main_route.dart
index 4eb733a..f85a86e 100644
--- a/lib/components/main_route.dart
+++ b/lib/components/main_route.dart
@@ -36,9 +36,6 @@
}
Widget build(BuildContext context) {
- // TODO(alexfandrianto): A better way to do this is to show the splash
- // screen while the Store is initializing.
- // https://github.com/vanadium/issues/issues/958
if (config.croupier.settings == null) {
return _buildSplashScreen();
}
@@ -54,7 +51,6 @@
drawer: _buildDrawer());
}
- // TODO(alexfandrianto): Can we do better than this?
Widget _buildSplashScreen() {
var stack = new Stack(children: [
new AssetImage(name: 'images/splash/background.png', fit: ImageFit.cover),
diff --git a/lib/components/proto/proto.part.dart b/lib/components/proto/proto.part.dart
index 5f39248..9071709 100644
--- a/lib/components/proto/proto.part.dart
+++ b/lib/components/proto/proto.part.dart
@@ -5,7 +5,7 @@
part of game_component;
class ProtoGameComponent extends GameComponent {
- ProtoGameComponent(Croupier croupier, SoundAssets sounds, NoArgCb cb,
+ ProtoGameComponent(Croupier croupier, SoundAssets sounds, VoidCallback cb,
{Key key, double width, double height})
: super(croupier, sounds, cb, key: key, width: width, height: height);
diff --git a/lib/components/solitaire/solitaire.part.dart b/lib/components/solitaire/solitaire.part.dart
index 83ad4ef..9bda63c 100644
--- a/lib/components/solitaire/solitaire.part.dart
+++ b/lib/components/solitaire/solitaire.part.dart
@@ -5,7 +5,7 @@
part of game_component;
class SolitaireGameComponent extends GameComponent {
- SolitaireGameComponent(Croupier croupier, SoundAssets sounds, NoArgCb cb,
+ SolitaireGameComponent(Croupier croupier, SoundAssets sounds, VoidCallback cb,
{Key key, double width, double height})
: super(croupier, sounds, cb, key: key, width: width, height: height);
@@ -30,7 +30,7 @@
width: config.width,
height: config.height,
child: solitaireWidget));
- if (game.phase == SolitairePhase.Play) {
+ if (game.phase == SolitairePhase.play) {
// All cards are visible.
List<int> visibleCardCollectionIndexes =
game.cardCollections.asMap().keys.toList();
@@ -74,7 +74,8 @@
}
@override
- Widget _makeButton(String text, NoArgCb callback, {bool inactive: false}) {
+ Widget _makeButton(String text, VoidCallback callback,
+ {bool inactive: false}) {
var borderColor = inactive ? Colors.grey[500] : Colors.white;
var backgroundColor = inactive ? Colors.grey[500] : null;
return new FlatButton(
@@ -91,11 +92,11 @@
SolitaireGame game = config.game as SolitaireGame;
switch (game.phase) {
- case SolitairePhase.Deal:
+ case SolitairePhase.deal:
return showDeal();
- case SolitairePhase.Play:
+ case SolitairePhase.play:
return showPlay();
- case SolitairePhase.Score:
+ case SolitairePhase.score:
return showScore();
default:
assert(false);
@@ -103,7 +104,7 @@
}
}
- NoArgCb _makeFlipCallback(int index) {
+ VoidCallback _makeFlipCallback(int index) {
SolitaireGame game = config.game as SolitaireGame;
return () {
game.flipCardUI(index);
@@ -131,7 +132,7 @@
List<Widget> row1 = new List<Widget>();
List<CardCollectionComponent> aces = [0, 1, 2, 3].map((int i) {
return new CardCollectionComponent(
- game.cardCollections[SolitaireGame.OFFSET_ACES + i],
+ game.cardCollections[SolitaireGame.offsetAces + i],
true,
CardCollectionOrientation.show1,
widthCard: cardSize,
@@ -145,7 +146,7 @@
row1.add(new Row(children: [
new CardCollectionComponent(
- game.cardCollections[SolitaireGame.OFFSET_DISCARD],
+ game.cardCollections[SolitaireGame.offsetDiscard],
true,
CardCollectionOrientation.show1,
widthCard: cardSize,
@@ -154,7 +155,7 @@
useKeys: true),
new GestureDetector(
child: new CardCollectionComponent(
- game.cardCollections[SolitaireGame.OFFSET_DRAW],
+ game.cardCollections[SolitaireGame.offsetDraw],
false,
CardCollectionOrientation.show1,
widthCard: cardSize,
@@ -167,20 +168,20 @@
for (int i = 0; i < 7; i++) {
row2.add(new GestureDetector(
child: new CardCollectionComponent(
- game.cardCollections[SolitaireGame.OFFSET_DOWN + i],
+ game.cardCollections[SolitaireGame.offsetDown + i],
false,
CardCollectionOrientation.show1,
widthCard: cardSize,
heightCard: cardSize,
useKeys: true),
- onTap: game.cardCollections[SolitaireGame.OFFSET_UP + i].length == 0
+ onTap: game.cardCollections[SolitaireGame.offsetUp + i].length == 0
? _makeFlipCallback(i)
: null));
}
List<Widget> row3 = new List<Widget>();
for (int i = 0; i < 7; i++) {
row3.add(new CardCollectionComponent(
- game.cardCollections[SolitaireGame.OFFSET_UP + i],
+ game.cardCollections[SolitaireGame.offsetUp + i],
true,
CardCollectionOrientation.vert,
widthCard: cardSize,
diff --git a/lib/logic/create_game.dart b/lib/logic/create_game.dart
index fbad529..fc97365 100644
--- a/lib/logic/create_game.dart
+++ b/lib/logic/create_game.dart
@@ -10,15 +10,15 @@
game_impl.Game createGame(game_impl.GameType gt, bool debugMode,
{int gameID, bool isCreator, int playerNumber}) {
switch (gt) {
- case game_impl.GameType.Proto:
+ case game_impl.GameType.proto:
return new proto_impl.ProtoGame(gameID: gameID, isCreator: isCreator)
..debugMode = debugMode
..playerNumber = playerNumber;
- case game_impl.GameType.Hearts:
+ case game_impl.GameType.hearts:
return new hearts_impl.HeartsGame(gameID: gameID, isCreator: isCreator)
..debugMode = debugMode
..playerNumber = playerNumber;
- case game_impl.GameType.Solitaire:
+ case game_impl.GameType.solitaire:
return new solitaire_impl.SolitaireGame(
gameID: gameID, isCreator: isCreator)
..debugMode = debugMode
diff --git a/lib/logic/croupier.dart b/lib/logic/croupier.dart
index 0970318..2d51962 100644
--- a/lib/logic/croupier.dart
+++ b/lib/logic/croupier.dart
@@ -13,15 +13,15 @@
show Game, GameType, GameStartData, stringToGameType, gameTypeToString;
enum CroupierState {
- Welcome,
- ChooseGame,
- JoinGame,
- ArrangePlayers,
- PlayGame,
- ResumeGame
+ welcome,
+ chooseGame,
+ joinGame,
+ arrangePlayers,
+ playGame,
+ resumeGame
}
-typedef void NoArgCb();
+typedef void VoidCallback();
class Croupier {
AppSettings appSettings;
@@ -33,7 +33,7 @@
Map<String, GameStartData> games_found; // empty, but loads asynchronously
Map<int, int> players_found; // empty, but loads asynchronously
Game game; // null until chosen
- NoArgCb informUICb;
+ VoidCallback informUICb;
// Futures to use in order to cancel scans and advertisements.
Future _scanFuture;
@@ -42,7 +42,7 @@
bool debugMode = false; // whether to show debug buttons or not
Croupier(this.appSettings) {
- state = CroupierState.Welcome;
+ state = CroupierState.welcome;
settings_everyone = new Map<int, CroupierSettings>();
games_found = new Map<String, GameStartData>();
players_found = new Map<int, int>();
@@ -160,10 +160,10 @@
}
switch (newStatus) {
case "RUNNING":
- if (state == CroupierState.ArrangePlayers) {
+ if (state == CroupierState.arrangePlayers) {
game.startGameSignal();
- setState(CroupierState.PlayGame, null);
- } else if (state == CroupierState.ResumeGame) {
+ setState(CroupierState.playGame, null);
+ } else if (state == CroupierState.resumeGame) {
game.startGameSignal();
}
break;
@@ -179,18 +179,18 @@
// Depending on the originating state, data can contain extra information that we need.
void setState(CroupierState nextState, var data) {
switch (state) {
- case CroupierState.Welcome:
+ case CroupierState.welcome:
// data should be empty unless nextState is ResumeGame.
- if (nextState != CroupierState.ResumeGame) {
+ if (nextState != CroupierState.resumeGame) {
assert(data == null);
}
break;
- case CroupierState.ChooseGame:
+ case CroupierState.chooseGame:
if (data == null) {
// Back button pressed.
break;
}
- assert(nextState == CroupierState.ArrangePlayers);
+ assert(nextState == CroupierState.arrangePlayers);
// data should be the game id here.
GameType gt = data as GameType;
@@ -204,7 +204,7 @@
}); // don't wait for this future.
break;
- case CroupierState.JoinGame:
+ case CroupierState.joinGame:
// Note that if we were in join game, we must have been scanning.
_scanFuture.then((_) {
settings_manager.stopScanSettings();
@@ -233,7 +233,7 @@
settings_manager.joinGameSyncgroup(sgName, gsd.gameID);
break;
- case CroupierState.ArrangePlayers:
+ case CroupierState.arrangePlayers:
// Note that if we were arranging players, we might have been advertising.
if (_advertiseFuture != null) {
_advertiseFuture.then((_) {
@@ -246,9 +246,9 @@
// data should be empty.
assert(data == null);
break;
- case CroupierState.PlayGame:
+ case CroupierState.playGame:
break;
- case CroupierState.ResumeGame:
+ case CroupierState.resumeGame:
// Data might be GameStartData. If so, then we must advertise it.
GameStartData gsd = data;
if (gsd != null) {
@@ -262,17 +262,17 @@
// A simplified way of clearing out the games and players found.
// They will need to be re-discovered in the future.
switch (nextState) {
- case CroupierState.Welcome:
+ case CroupierState.welcome:
games_found.clear();
players_found.clear();
_quitGame();
break;
- case CroupierState.JoinGame:
+ case CroupierState.joinGame:
// Start scanning for games since that's what's next for you.
_scanFuture =
settings_manager.scanSettings(); // don't wait for this future.
break;
- case CroupierState.ResumeGame:
+ case CroupierState.resumeGame:
// We need to create the game again.
int gameIDData = data;
_resumeGameAsynchronously(gameIDData);
@@ -305,12 +305,12 @@
switch (gameStatus) {
case "RUNNING":
// The game is running, so let's play it!
- setState(CroupierState.PlayGame, null);
+ setState(CroupierState.playGame, null);
break;
default:
// We are still arranging players, so we need to advertise our game
// start data.
- setState(CroupierState.ArrangePlayers, gsd);
+ setState(CroupierState.arrangePlayers, gsd);
break;
}
diff --git a/lib/logic/game/game_command.part.dart b/lib/logic/game/game_command.part.dart
index aff0ddd..99fb5f2 100644
--- a/lib/logic/game/game_command.part.dart
+++ b/lib/logic/game/game_command.part.dart
@@ -10,7 +10,7 @@
final SimulLevel simultaneity;
GameCommand(this.phase, this.data,
- {this.simultaneity: SimulLevel.INDEPENDENT});
+ {this.simultaneity: SimulLevel.independent});
// UNIMPLEMENTED
bool canExecute(Game game);
diff --git a/lib/logic/game/game_def.part.dart b/lib/logic/game/game_def.part.dart
index b6d5cd2..5de8037 100644
--- a/lib/logic/game/game_def.part.dart
+++ b/lib/logic/game/game_def.part.dart
@@ -4,16 +4,15 @@
part of game;
-// Note: Proto and Board are "fake" games intended to demonstrate what we can do.
+// Note: Proto and Poker are "fake" games intended to demonstrate what we can do.
// Proto is just a drag cards around "game".
-// Board is meant to show how one _could_ layout a game of Hearts. This one is not hooked up very well yet.
-enum GameType { Proto, Hearts, Poker, Solitaire, Board }
+enum GameType { proto, hearts, poker, solitaire }
Map<GameType, String> _gameTypeMap = <GameType, String>{
- GameType.Proto: "Proto",
- GameType.Hearts: "Hearts",
- GameType.Poker: "Poker",
- GameType.Solitaire: "Solitaire",
+ GameType.proto: "Proto",
+ GameType.hearts: "Hearts",
+ GameType.poker: "Poker",
+ GameType.solitaire: "Solitaire",
};
String gameTypeToString(GameType t) {
return _gameTypeMap[t];
@@ -83,7 +82,7 @@
}
}
-typedef void NoArgCb();
+typedef void VoidCallback();
/// A game consists of multiple decks and tracks a single deck of cards.
/// It also handles events; when cards are dragged to and from decks.
@@ -109,7 +108,7 @@
bool debugMode = false;
String debugString;
- NoArgCb updateCallback; // Used to inform components of when a change has occurred. This is especially important when something non-UI related changes what should be drawn.
+ VoidCallback updateCallback; // Used to inform components of when a change has occurred. This is especially important when something non-UI related changes what should be drawn.
// A super constructor, don't call this unless you're a subclass.
Game.create(this.gameType, this.gamelog, int numCollections,
diff --git a/lib/logic/hearts/hearts_command.part.dart b/lib/logic/hearts/hearts_command.part.dart
index 6bb709a..2e5d63f 100644
--- a/lib/logic/hearts/hearts_command.part.dart
+++ b/lib/logic/hearts/hearts_command.part.dart
@@ -16,47 +16,47 @@
// The following constructors are used for the player generating the HeartsCommand.
HeartsCommand.deal(int playerId, List<Card> cards)
: super("Deal", computeDeal(playerId, cards),
- simultaneity: SimulLevel.INDEPENDENT);
+ simultaneity: SimulLevel.independent);
HeartsCommand.pass(int senderId, List<Card> cards)
: super("Pass", computePass(senderId, cards),
- simultaneity: SimulLevel.INDEPENDENT);
+ simultaneity: SimulLevel.independent);
HeartsCommand.take(int takerId)
: super("Take", computeTake(takerId),
- simultaneity: SimulLevel.INDEPENDENT);
+ simultaneity: SimulLevel.independent);
HeartsCommand.play(int playerId, Card c)
: super("Play", computePlay(playerId, c),
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
HeartsCommand.ask()
- : super("Ask", computeAsk(), simultaneity: SimulLevel.TURN_BASED);
+ : super("Ask", computeAsk(), simultaneity: SimulLevel.turnBased);
HeartsCommand.takeTrick()
: super("TakeTrick", computeTakeTrick(),
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
HeartsCommand.ready(int playerId)
: super("Ready", computeReady(playerId),
- simultaneity: SimulLevel.INDEPENDENT);
+ simultaneity: SimulLevel.independent);
static SimulLevel computeSimul(String phase) {
switch (phase) {
case "Deal":
- return SimulLevel.INDEPENDENT;
+ return SimulLevel.independent;
case "Pass":
- return SimulLevel.INDEPENDENT;
+ return SimulLevel.independent;
case "Take":
- return SimulLevel.INDEPENDENT;
+ return SimulLevel.independent;
case "Play":
- return SimulLevel.TURN_BASED;
+ return SimulLevel.turnBased;
case "Ask":
- return SimulLevel.TURN_BASED;
+ return SimulLevel.turnBased;
case "TakeTrick":
- return SimulLevel.TURN_BASED;
+ return SimulLevel.turnBased;
case "Ready":
- return SimulLevel.INDEPENDENT;
+ return SimulLevel.independent;
default:
print(phase);
assert(false); // How could this have happened?
@@ -111,7 +111,7 @@
List<String> parts = data.split(":");
switch (phase) {
case "Deal":
- if (game.phase != HeartsPhase.Deal) {
+ if (game.phase != HeartsPhase.deal) {
return false;
}
// Deal appends cards to playerId's hand.
@@ -131,12 +131,12 @@
}
return true;
case "Pass":
- if (game.phase != HeartsPhase.Pass) {
+ if (game.phase != HeartsPhase.pass) {
return false;
}
// Pass moves a set of cards from senderId to receiverId.
int senderId = int.parse(parts[0]);
- int receiverId = senderId + HeartsGame.OFFSET_PASS;
+ int receiverId = senderId + HeartsGame.offsetPass;
List<Card> handS = game.cardCollections[senderId];
List<Card> handR = game.cardCollections[receiverId];
@@ -155,12 +155,12 @@
}
return true;
case "Take":
- if (game.phase != HeartsPhase.Take) {
+ if (game.phase != HeartsPhase.take) {
return false;
}
return true;
case "Play":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
return false;
}
@@ -171,7 +171,7 @@
// Play the card from the player's hand to their play pile.
int playerId = int.parse(parts[0]);
- int targetId = playerId + HeartsGame.OFFSET_PLAY;
+ int targetId = playerId + HeartsGame.offsetPlay;
List<Card> hand = game.cardCollections[playerId];
List<Card> discard = game.cardCollections[targetId];
@@ -185,7 +185,7 @@
bool canTransfer = this.transferCheck(hand, discard, c);
return canTransfer;
case "Ask":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
return false;
}
if (game.allPlayed) {
@@ -193,7 +193,7 @@
}
return !game.asking; // Can ask if you're not asking.
case "TakeTrick":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
return false;
}
@@ -203,7 +203,7 @@
if (game.hasGameEnded) {
return false;
}
- if (game.phase != HeartsPhase.Score) {
+ if (game.phase != HeartsPhase.score) {
return false;
}
return true;
@@ -222,7 +222,7 @@
List<String> parts = data.split(":");
switch (phase) {
case "Deal":
- if (game.phase != HeartsPhase.Deal) {
+ if (game.phase != HeartsPhase.deal) {
throw new StateError(
"Cannot process deal commands when not in Deal phase");
}
@@ -240,13 +240,13 @@
}
return;
case "Pass":
- if (game.phase != HeartsPhase.Pass) {
+ if (game.phase != HeartsPhase.pass) {
throw new StateError(
"Cannot process pass commands when not in Pass phase");
}
// Pass moves a set of cards from senderId to receiverId.
int senderId = int.parse(parts[0]);
- int receiverId = senderId + HeartsGame.OFFSET_PASS;
+ int receiverId = senderId + HeartsGame.offsetPass;
List<Card> handS = game.cardCollections[senderId];
List<Card> handR = game.cardCollections[receiverId];
@@ -262,19 +262,19 @@
}
return;
case "Take":
- if (game.phase != HeartsPhase.Take) {
+ if (game.phase != HeartsPhase.take) {
throw new StateError(
"Cannot process take commands when not in Take phase");
}
int takerId = int.parse(parts[0]);
- int senderPile = game.getTakeTarget(takerId) + HeartsGame.OFFSET_PASS;
+ int senderPile = game.getTakeTarget(takerId) + HeartsGame.offsetPass;
List<Card> handT = game.cardCollections[takerId];
List<Card> handS = game.cardCollections[senderPile];
handT.addAll(handS);
handS.clear();
return;
case "Play":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
throw new StateError(
"Cannot process play commands when not in Play phase");
}
@@ -286,7 +286,7 @@
// Play the card from the player's hand to their play pile.
int playerId = int.parse(parts[0]);
- int targetId = playerId + HeartsGame.OFFSET_PLAY;
+ int targetId = playerId + HeartsGame.offsetPlay;
List<Card> hand = game.cardCollections[playerId];
List<Card> discard = game.cardCollections[targetId];
@@ -302,7 +302,7 @@
game.asking = false;
return;
case "Ask":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
throw new StateError(
"Cannot process ask commands when not in Play phase");
}
@@ -315,7 +315,7 @@
game.asking = true;
return;
case "TakeTrick":
- if (game.phase != HeartsPhase.Play) {
+ if (game.phase != HeartsPhase.play) {
throw new StateError(
"Cannot process take trick commands when not in Play phase");
}
@@ -331,11 +331,11 @@
// Note: While some variants of Hearts allow the QUEEN_OF_SPADES to
// break hearts, this version does NOT implement that rule.
for (int i = 0; i < 4; i++) {
- List<Card> play = game.cardCollections[i + HeartsGame.OFFSET_PLAY];
+ List<Card> play = game.cardCollections[i + HeartsGame.offsetPlay];
if (!game.heartsBroken && game.isHeartsCard(play[0])) {
game.heartsBroken = true;
}
- game.cardCollections[winner + HeartsGame.OFFSET_TRICK]
+ game.cardCollections[winner + HeartsGame.offsetTrick]
.addAll(play); // or add(play[0])
play.clear();
}
@@ -350,7 +350,7 @@
throw new StateError(
"Game has already ended. Start a new one to play again.");
}
- if (game.phase != HeartsPhase.Score) {
+ if (game.phase != HeartsPhase.score) {
throw new StateError(
"Cannot process ready commands when not in Score phase");
}
diff --git a/lib/logic/hearts/hearts_game.part.dart b/lib/logic/hearts/hearts_game.part.dart
index 7e1b708..65a6eb8 100644
--- a/lib/logic/hearts/hearts_game.part.dart
+++ b/lib/logic/hearts/hearts_game.part.dart
@@ -5,41 +5,41 @@
part of hearts;
class HeartsGame extends Game {
- static const PLAYER_A = 0;
- static const PLAYER_B = 1;
- static const PLAYER_C = 2;
- static const PLAYER_D = 3;
- static const PLAYER_A_PLAY = 4;
- static const PLAYER_B_PLAY = 5;
- static const PLAYER_C_PLAY = 6;
- static const PLAYER_D_PLAY = 7;
- static const PLAYER_A_TRICK = 8;
- static const PLAYER_B_TRICK = 9;
- static const PLAYER_C_TRICK = 10;
- static const PLAYER_D_TRICK = 11;
- static const PLAYER_A_PASS = 12;
- static const PLAYER_B_PASS = 13;
- static const PLAYER_C_PASS = 14;
- static const PLAYER_D_PASS = 15;
+ static const playerA = 0;
+ static const playerB = 1;
+ static const playerC = 2;
+ static const playerD = 3;
+ static const playerPlayA = 4;
+ static const playerPlayB = 5;
+ static const playerPlayC = 6;
+ static const playerPlayD = 7;
+ static const playerTrickA = 8;
+ static const playerTrickB = 9;
+ static const playerTrickC = 10;
+ static const playerTrickD = 11;
+ static const playerPassA = 12;
+ static const playerPassB = 13;
+ static const playerPassC = 14;
+ static const playerPassD = 15;
- static const OFFSET_HAND = 0;
- static const OFFSET_PLAY = 4;
- static const OFFSET_TRICK = 8;
- static const OFFSET_PASS = 12;
+ static const offsetHand = 0;
+ static const offsetPlay = 4;
+ static const offsetTrick = 8;
+ static const offsetPass = 12;
- static const MAX_SCORE = 100; // Play until someone gets to 100.
+ static const maxScore = 100; // Play until someone gets to 100.
// Note: These cards are final because the "classic" deck has 52 cards.
// It is up to the renderer to reskin those cards as needed.
- final Card TWO_OF_CLUBS = new Card("classic", "c2");
- final Card QUEEN_OF_SPADES = new Card("classic", "sq");
+ final Card twoOfClubs = new Card("classic", "c2");
+ final Card queenOfSpades = new Card("classic", "sq");
@override
String get gameTypeName => "Hearts";
- HeartsType viewType = HeartsType.Player;
+ HeartsType viewType = HeartsType.player;
- HeartsPhase _phase = HeartsPhase.Deal;
+ HeartsPhase _phase = HeartsPhase.deal;
HeartsPhase get phase => _phase;
void set phase(HeartsPhase other) {
print('setting phase from ${_phase} to ${other}');
@@ -68,7 +68,7 @@
List<bool> ready;
HeartsGame({int gameID, bool isCreator})
- : super.create(GameType.Hearts, new HeartsLog(), 16,
+ : super.create(GameType.hearts, new HeartsLog(), 16,
gameID: gameID, isCreator: isCreator) {
resetGame();
unsetReady();
@@ -91,10 +91,10 @@
List<Card> forC = this.deckPeek(13, 26);
List<Card> forD = this.deckPeek(13, 39);
- deal(PLAYER_A, forA);
- deal(PLAYER_B, forB);
- deal(PLAYER_C, forC);
- deal(PLAYER_D, forD);
+ deal(playerA, forA);
+ deal(playerB, forB);
+ deal(playerC, forC);
+ deal(playerD, forD);
}
bool get isPlayer => this.playerNumber >= 0 && this.playerNumber < 4;
@@ -136,7 +136,7 @@
// Please only call this in the Play phase. Otherwise, it's pretty useless.
int get whoseTurn {
- if (phase != HeartsPhase.Play) {
+ if (phase != HeartsPhase.play) {
return null;
}
return (lastTrickTaker + this.numPlayed) % 4;
@@ -167,11 +167,11 @@
}
bool isQSCard(Card c) {
- return c == QUEEN_OF_SPADES;
+ return c == queenOfSpades;
}
bool isFirstCard(Card c) {
- return c == TWO_OF_CLUBS;
+ return c == twoOfClubs;
}
bool isPenaltyCard(Card c) {
@@ -179,7 +179,7 @@
}
bool hasSuit(int player, String suit) {
- Card matchesSuit = this.cardCollections[player + OFFSET_HAND].firstWhere(
+ Card matchesSuit = this.cardCollections[player + offsetHand].firstWhere(
(Card element) => (getCardSuit(element) == suit),
orElse: () => null);
return matchesSuit != null;
@@ -187,7 +187,7 @@
Card get leadingCard {
if (this.numPlayed >= 1) {
- return cardCollections[this.lastTrickTaker + OFFSET_PLAY][0];
+ return cardCollections[this.lastTrickTaker + offsetPlay][0];
}
return null;
}
@@ -195,26 +195,26 @@
int get numPlayed {
int count = 0;
for (int i = 0; i < 4; i++) {
- if (cardCollections[i + OFFSET_PLAY].length == 1) {
+ if (cardCollections[i + offsetPlay].length == 1) {
count++;
}
}
return count;
}
- bool get hasGameEnded => this.scores.reduce(math.max) >= HeartsGame.MAX_SCORE;
+ bool get hasGameEnded => this.scores.reduce(math.max) >= HeartsGame.maxScore;
- bool get allDealt => cardCollections[PLAYER_A].length == 13 &&
- cardCollections[PLAYER_B].length == 13 &&
- cardCollections[PLAYER_C].length == 13 &&
- cardCollections[PLAYER_D].length == 13;
+ bool get allDealt => cardCollections[playerA].length == 13 &&
+ cardCollections[playerB].length == 13 &&
+ cardCollections[playerC].length == 13 &&
+ cardCollections[playerD].length == 13;
bool hasPassed(int player) =>
- cardCollections[player + OFFSET_PASS].length == 3;
+ cardCollections[player + offsetPass].length == 3;
int get numPassed {
int count = 0;
for (int i = 0; i < 4; i++) {
- if (cardCollections[i + OFFSET_PASS].length == 3) {
+ if (cardCollections[i + offsetPass].length == 3) {
count++;
}
}
@@ -223,11 +223,11 @@
bool get allPassed => numPassed == 4;
bool hasTaken(int player) =>
- cardCollections[getTakeTarget(player) + OFFSET_PASS].length == 0;
- bool get allTaken => cardCollections[PLAYER_A_PASS].length == 0 &&
- cardCollections[PLAYER_B_PASS].length == 0 &&
- cardCollections[PLAYER_C_PASS].length == 0 &&
- cardCollections[PLAYER_D_PASS].length == 0;
+ cardCollections[getTakeTarget(player) + offsetPass].length == 0;
+ bool get allTaken => cardCollections[playerPassA].length == 0 &&
+ cardCollections[playerPassB].length == 0 &&
+ cardCollections[playerPassC].length == 0 &&
+ cardCollections[playerPassD].length == 0;
bool get allPlayed => this.numPlayed == 4;
bool get allReady => ready[0] && ready[1] && ready[2] && ready[3];
@@ -246,7 +246,7 @@
// Note that this will be called by the UI.
// It won't be possible to pass for other players, except via the GameLog.
void passCards(List<Card> cards) {
- assert(phase == HeartsPhase.Pass);
+ assert(phase == HeartsPhase.pass);
assert(this.passTarget != null);
if (cards.length != 3) {
throw new StateError('3 cards expected, but got: ${cards.toString()}');
@@ -257,9 +257,9 @@
// Note that this will be called by the UI.
// It won't be possible to take cards for other players, except via the GameLog.
void takeCards() {
- assert(phase == HeartsPhase.Take);
+ assert(phase == HeartsPhase.take);
assert(this.takeTarget != null);
- List<Card> cards = this.cardCollections[takeTarget + OFFSET_PASS];
+ List<Card> cards = this.cardCollections[takeTarget + offsetPass];
assert(cards.length == 3);
gamelog.add(new HeartsCommand.take(playerNumber));
@@ -268,7 +268,7 @@
// Note that this will be called by the UI.
// It won't be possible to set the readiness for other players, except via the GameLog.
void setReadyUI() {
- assert(phase == HeartsPhase.Score);
+ assert(phase == HeartsPhase.score);
if (this.debugMode) {
// Debug Mode should pretend this device is all players.
for (int i = 0; i < 4; i++) {
@@ -281,7 +281,7 @@
// Note that this will be called by the UI.
void askUI() {
- assert(phase == HeartsPhase.Play);
+ assert(phase == HeartsPhase.play);
if (this.asking) {
print("Already asked...");
return; // just don't call it again.
@@ -291,7 +291,7 @@
// Note that this will be called by the UI.
void takeTrickUI() {
- assert(phase == HeartsPhase.Play);
+ assert(phase == HeartsPhase.play);
assert(this.allPlayed);
gamelog.add(new HeartsCommand.takeTrick());
}
@@ -306,7 +306,7 @@
this.playerNumber = 0;
}
if (!this.isPlayer) {
- this.viewType = HeartsType.Board;
+ this.viewType = HeartsType.board;
}
// Only the creator should deal the cards once everyone is ready.
if (this.isCreator) {
@@ -322,7 +322,7 @@
// The UI will initiate pass separately.
@override
void move(Card card, List<Card> dest) {
- assert(phase == HeartsPhase.Play);
+ assert(phase == HeartsPhase.play);
assert(whoseTurn == playerNumber);
int i = findCard(card);
@@ -335,7 +335,7 @@
throw new StateError(
'destination list does not exist: ${dest.toString()}');
}
- if (destId != playerNumber + OFFSET_PLAY) {
+ if (destId != playerNumber + offsetPlay) {
throw new StateError(
'player ${playerNumber} is not playing to the correct list: ${destId}');
}
@@ -355,42 +355,42 @@
@override
void triggerEvents() {
switch (this.phase) {
- case HeartsPhase.Deal:
+ case HeartsPhase.deal:
if (this.allDealt) {
if (this.passTarget != null) {
- phase = HeartsPhase.Pass;
+ phase = HeartsPhase.pass;
} else {
// All cards are dealt. The person who "won" the last trick goes first.
// In this case, we'll just pretend it's the person with the 2 of clubs.
- this.lastTrickTaker = this.findCard(TWO_OF_CLUBS);
- phase = HeartsPhase.Play;
+ this.lastTrickTaker = this.findCard(twoOfClubs);
+ phase = HeartsPhase.play;
}
}
return;
- case HeartsPhase.Pass:
+ case HeartsPhase.pass:
if (this.allPassed) {
- phase = HeartsPhase.Take;
+ phase = HeartsPhase.take;
}
return;
- case HeartsPhase.Take:
+ case HeartsPhase.take:
if (this.allTaken) {
// All cards are dealt. The person who "won" the last trick goes first.
// In this case, we'll just pretend it's the person with the 2 of clubs.
- this.lastTrickTaker = this.findCard(TWO_OF_CLUBS);
- phase = HeartsPhase.Play;
+ this.lastTrickTaker = this.findCard(twoOfClubs);
+ phase = HeartsPhase.play;
}
return;
- case HeartsPhase.Play:
+ case HeartsPhase.play:
// If that was the last trick, move onto the score phase.
if (this.trickNumber == 13) {
- phase = HeartsPhase.Score;
+ phase = HeartsPhase.score;
this.prepareScore();
}
return;
- case HeartsPhase.Score:
+ case HeartsPhase.score:
if (!this.hasGameEnded && this.allReady) {
this.roundNumber++;
- phase = HeartsPhase.Deal;
+ phase = HeartsPhase.deal;
this.resetGame();
// Only the creator should deal the cards once everyone is ready.
@@ -406,7 +406,7 @@
// Returns null or the reason that the player cannot play the card.
String canPlay(int player, Card c, {bool lenient: false}) {
- if (phase != HeartsPhase.Play) {
+ if (phase != HeartsPhase.play) {
return "It is not the Play phase of Hearts.";
}
if (!cardCollections[player].contains(c)) {
@@ -418,7 +418,7 @@
if (this.whoseTurn != player && !lenient) {
return "It is not Player ${player}'s turn.";
}
- if (trickNumber == 0 && this.numPlayed == 0 && c != TWO_OF_CLUBS) {
+ if (trickNumber == 0 && this.numPlayed == 0 && c != twoOfClubs) {
return "You must play the 2 of Clubs";
}
if (this.numPlayed == 0 && isHeartsCard(c) && !heartsBroken) {
@@ -444,7 +444,7 @@
int highestIndex;
int highestValue; // oh no, aces are highest.
for (int i = 0; i < 4; i++) {
- Card c = cardCollections[i + OFFSET_PLAY][0];
+ Card c = cardCollections[i + offsetPlay][0];
int value = this.getCardValue(c);
String suit = this.getCardSuit(c);
if (suit == leadingSuit &&
@@ -499,7 +499,7 @@
int computeScore(int player) {
int total = 0;
- List<Card> trickCards = this.cardCollections[player + OFFSET_TRICK];
+ List<Card> trickCards = this.cardCollections[player + offsetTrick];
for (int i = 0; i < trickCards.length; i++) {
Card c = trickCards[i];
if (isHeartsCard(c)) {
@@ -518,16 +518,16 @@
for (int i = 0; i < 4; i++) {
// Move the hand cards, pass cards, etc. to the tricks for each player.
// If you're in the deal phase, this will probably do nothing.
- List<Card> trick = cardCollections[i + OFFSET_TRICK];
- trick.addAll(cardCollections[i + OFFSET_HAND]);
- cardCollections[i + OFFSET_HAND].clear();
- trick.addAll(cardCollections[i + OFFSET_PLAY]);
- cardCollections[i + OFFSET_PLAY].clear();
- trick.addAll(cardCollections[i + OFFSET_PASS]);
- cardCollections[i + OFFSET_PASS].clear();
+ List<Card> trick = cardCollections[i + offsetTrick];
+ trick.addAll(cardCollections[i + offsetHand]);
+ cardCollections[i + offsetHand].clear();
+ trick.addAll(cardCollections[i + offsetPlay]);
+ cardCollections[i + offsetPlay].clear();
+ trick.addAll(cardCollections[i + offsetPass]);
+ cardCollections[i + offsetPass].clear();
}
- phase = HeartsPhase.Score;
+ phase = HeartsPhase.score;
this.prepareScore();
}
}
diff --git a/lib/logic/hearts/hearts_phase.part.dart b/lib/logic/hearts/hearts_phase.part.dart
index 55894f5..eecc873 100644
--- a/lib/logic/hearts/hearts_phase.part.dart
+++ b/lib/logic/hearts/hearts_phase.part.dart
@@ -4,4 +4,4 @@
part of hearts;
-enum HeartsPhase { Deal, Pass, Take, Play, Score }
+enum HeartsPhase { deal, pass, take, play, score }
diff --git a/lib/logic/hearts/hearts_type.part.dart b/lib/logic/hearts/hearts_type.part.dart
index 4c3e51f..95ecb20 100644
--- a/lib/logic/hearts/hearts_type.part.dart
+++ b/lib/logic/hearts/hearts_type.part.dart
@@ -4,4 +4,4 @@
part of hearts;
-enum HeartsType { Player, Board }
+enum HeartsType { player, board }
diff --git a/lib/logic/proto/proto_game.part.dart b/lib/logic/proto/proto_game.part.dart
index cb76c20..3c38aba 100644
--- a/lib/logic/proto/proto_game.part.dart
+++ b/lib/logic/proto/proto_game.part.dart
@@ -13,15 +13,13 @@
GameArrangeData get gameArrangeData => _arrangeData;
ProtoGame({int gameID, bool isCreator})
- : super.create(GameType.Proto, new ProtoLog(), 6,
+ : super.create(GameType.proto, new ProtoLog(), 6,
gameID: gameID, isCreator: isCreator) {
// playerNumber would be used in a real game, but I have to ignore it for debugging.
// It would determine faceUp/faceDown status.faceDown
- // TODO: Set the number of piles created to either 9 (1x per player, 1 discard, 4 play piles) or 12 (2x per player, 4 play piles)
- // But for now, we will deal with 6. 1x per player, 1 discard, and 1 undrawn pile.
-
// We do some arbitrary things here... Just for setup.
+ // The first 4 of our 6 piles will get some random cards.
deck.shuffle();
deal(0, 8);
deal(1, 5);
diff --git a/lib/logic/solitaire/solitaire_command.part.dart b/lib/logic/solitaire/solitaire_command.part.dart
index f3c26eb..5435d2b 100644
--- a/lib/logic/solitaire/solitaire_command.part.dart
+++ b/lib/logic/solitaire/solitaire_command.part.dart
@@ -7,27 +7,27 @@
class SolitaireCommand extends GameCommand {
// Usually this constructor is used when reading from a log/syncbase.
SolitaireCommand(String phase, String data)
- : super(phase, data, simultaneity: SimulLevel.TURN_BASED);
+ : super(phase, data, simultaneity: SimulLevel.turnBased);
SolitaireCommand.fromCommand(String cmd)
: super(cmd.split("|")[0], cmd.split("|")[1],
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
// The following constructors are used for the player generating the SolitaireCommand.
SolitaireCommand.deal(List<Card> allCards)
: super("Deal", computeDeal(allCards),
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
SolitaireCommand.move(Card target, int targetPile)
: super("Move", computeMove(target, targetPile),
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
SolitaireCommand.draw()
- : super("Draw", computeDraw(), simultaneity: SimulLevel.TURN_BASED);
+ : super("Draw", computeDraw(), simultaneity: SimulLevel.turnBased);
SolitaireCommand.flip(int targetPile)
: super("Flip", computeFlip(targetPile),
- simultaneity: SimulLevel.TURN_BASED);
+ simultaneity: SimulLevel.turnBased);
static String computeDeal(List<Card> allCards) {
StringBuffer buff = new StringBuffer();
@@ -62,9 +62,9 @@
List<String> parts = data.split(":");
switch (phase) {
case "Deal":
- return game.phase == SolitairePhase.Deal && parts.length - 1 == 52;
+ return game.phase == SolitairePhase.deal && parts.length - 1 == 52;
case "Move":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
return false;
}
@@ -89,17 +89,17 @@
bool canTransfer = this.transferCheck(source, dest, c);
return canTransfer;
case "Draw":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
return false;
}
- List<Card> drawPile = game.cardCollections[SolitaireGame.OFFSET_DRAW];
+ List<Card> drawPile = game.cardCollections[SolitaireGame.offsetDraw];
List<Card> discardPile =
- game.cardCollections[SolitaireGame.OFFSET_DISCARD];
+ game.cardCollections[SolitaireGame.offsetDiscard];
return drawPile.length > 0 || discardPile.length > 0;
case "Flip":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
return false;
}
@@ -109,9 +109,9 @@
}
List<Card> flipSource =
- game.cardCollections[SolitaireGame.OFFSET_DOWN + flipId];
+ game.cardCollections[SolitaireGame.offsetDown + flipId];
List<Card> flipDest =
- game.cardCollections[SolitaireGame.OFFSET_UP + flipId];
+ game.cardCollections[SolitaireGame.offsetUp + flipId];
return flipDest.length == 0 && flipSource.length > 0;
default:
@@ -129,7 +129,7 @@
List<String> parts = data.split(":");
switch (phase) {
case "Deal":
- if (game.phase != SolitairePhase.Deal) {
+ if (game.phase != SolitairePhase.deal) {
throw new StateError(
"Cannot process deal commands when not in Deal phase");
}
@@ -144,13 +144,13 @@
for (int j = 0; j < i; j++) {
this.transfer(
game.deck,
- game.cardCollections[SolitaireGame.OFFSET_DOWN + i],
+ game.cardCollections[SolitaireGame.offsetDown + i],
new Card.fromString(parts[index]));
index++;
}
this.transfer(
game.deck,
- game.cardCollections[SolitaireGame.OFFSET_UP + i],
+ game.cardCollections[SolitaireGame.offsetUp + i],
new Card.fromString(parts[index]));
index++;
}
@@ -159,12 +159,12 @@
for (; index < 52; index++) {
this.transfer(
game.deck,
- game.cardCollections[SolitaireGame.OFFSET_DRAW],
+ game.cardCollections[SolitaireGame.offsetDraw],
new Card.fromString(parts[index]));
}
return;
case "Move":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
throw new StateError(
"Cannot process move commands when not in Play phase");
}
@@ -191,14 +191,14 @@
this.transferGroup(source, dest, c);
return;
case "Draw":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
throw new StateError(
"Cannot process draw commands when not in Play phase");
}
- List<Card> drawPile = game.cardCollections[SolitaireGame.OFFSET_DRAW];
+ List<Card> drawPile = game.cardCollections[SolitaireGame.offsetDraw];
List<Card> discardPile =
- game.cardCollections[SolitaireGame.OFFSET_DISCARD];
+ game.cardCollections[SolitaireGame.offsetDiscard];
if (drawPile.length != 0) {
this.transfer(drawPile, discardPile, drawPile[0]);
@@ -209,7 +209,7 @@
}
return;
case "Flip":
- if (game.phase != SolitairePhase.Play) {
+ if (game.phase != SolitairePhase.play) {
throw new StateError(
"Cannot process flip commands when not in Play phase");
}
@@ -221,9 +221,9 @@
}
List<Card> flipSource =
- game.cardCollections[SolitaireGame.OFFSET_DOWN + flipId];
+ game.cardCollections[SolitaireGame.offsetDown + flipId];
List<Card> flipDest =
- game.cardCollections[SolitaireGame.OFFSET_UP + flipId];
+ game.cardCollections[SolitaireGame.offsetUp + flipId];
if (flipDest.length != 0) {
throw new StateError(
diff --git a/lib/logic/solitaire/solitaire_game.part.dart b/lib/logic/solitaire/solitaire_game.part.dart
index b90df65..ebbe866 100644
--- a/lib/logic/solitaire/solitaire_game.part.dart
+++ b/lib/logic/solitaire/solitaire_game.part.dart
@@ -4,7 +4,7 @@
part of solitaire;
-enum SolitairePileType { ACES, DISCARD, DRAW, DOWN, UP }
+enum SolitairePileType { aces, discard, draw, down, up }
class SolitaireGame extends Game {
@override
@@ -12,18 +12,18 @@
// Constants for the index-based offsets of the Solitaire Game's card collection.
// There are 20 piles to track (4 aces, 1 discard, 1 draw, 7 down, 7 up).
- static const NUM_PILES = 20;
- static const OFFSET_ACES = 0;
- static const OFFSET_DISCARD = 4;
- static const OFFSET_DRAW = 5;
- static const OFFSET_DOWN = 6;
- static const OFFSET_UP = 13;
+ static const numPiles = 20;
+ static const offsetAces = 0;
+ static const offsetDiscard = 4;
+ static const offsetDraw = 5;
+ static const offsetDown = 6;
+ static const offsetUp = 13;
static final GameArrangeData _arrangeData =
new GameArrangeData(false, new Set());
GameArrangeData get gameArrangeData => _arrangeData;
- SolitairePhase _phase = SolitairePhase.Deal;
+ SolitairePhase _phase = SolitairePhase.deal;
SolitairePhase get phase => _phase;
void set phase(SolitairePhase other) {
print('setting phase from ${_phase} to ${other}');
@@ -31,7 +31,7 @@
}
SolitaireGame({int gameID, bool isCreator})
- : super.create(GameType.Solitaire, new SolitaireLog(), NUM_PILES,
+ : super.create(GameType.solitaire, new SolitaireLog(), numPiles,
gameID: gameID, isCreator: isCreator) {
resetGame();
}
@@ -74,8 +74,8 @@
return getCardSuit(c) == 's' || getCardSuit(c) == 'c';
}
- bool get canDrawCard => cardCollections[OFFSET_DISCARD].length +
- cardCollections[OFFSET_DRAW].length >
+ bool get canDrawCard => cardCollections[offsetDiscard].length +
+ cardCollections[offsetDraw].length >
0;
bool get isGameWon {
@@ -125,14 +125,14 @@
new Set<String>.from(<String>['c', 'd', 'h', 's']);
int minLen = null;
for (int i = 0; i < 4; i++) {
- int len = cardCollections[OFFSET_ACES + i].length;
+ int len = cardCollections[offsetAces + i].length;
if (minLen == null || len < minLen) {
minLen = len;
}
if (len > 0) {
- suits[i] = getCardSuit(cardCollections[OFFSET_ACES + i][0]);
+ suits[i] = getCardSuit(cardCollections[offsetAces + i][0]);
remainingSuits.remove(suits[i]);
}
}
@@ -148,7 +148,7 @@
// With all suits assigned, and the minLen known, we know which cards to pull.
for (int i = 0; i < 4; i++) {
- List<Card> cards = cardCollections[OFFSET_ACES + i];
+ List<Card> cards = cardCollections[offsetAces + i];
if (cards.length == minLen) {
// Let us pull a card from either the down cards, up cards, or deck.
@@ -191,17 +191,17 @@
@override
void triggerEvents() {
switch (this.phase) {
- case SolitairePhase.Deal:
+ case SolitairePhase.deal:
if (this.deck.length == 0) {
- phase = SolitairePhase.Play;
+ phase = SolitairePhase.play;
}
return;
- case SolitairePhase.Play:
+ case SolitairePhase.play:
if (this.isGameWon) {
- phase = SolitairePhase.Score;
+ phase = SolitairePhase.score;
}
return;
- case SolitairePhase.Score:
+ case SolitairePhase.score:
return;
default:
assert(false);
@@ -209,16 +209,16 @@
}
SolitairePileType pileType(int index) {
- if (index >= OFFSET_ACES && index < OFFSET_DISCARD) {
- return SolitairePileType.ACES;
- } else if (index == OFFSET_DISCARD) {
- return SolitairePileType.DISCARD;
- } else if (index == OFFSET_DRAW) {
- return SolitairePileType.DRAW;
- } else if (index >= OFFSET_DOWN && index < OFFSET_UP) {
- return SolitairePileType.DOWN;
- } else if (index >= OFFSET_UP && index < 20) {
- return SolitairePileType.UP;
+ if (index >= offsetAces && index < offsetDiscard) {
+ return SolitairePileType.aces;
+ } else if (index == offsetDiscard) {
+ return SolitairePileType.discard;
+ } else if (index == offsetDraw) {
+ return SolitairePileType.draw;
+ } else if (index >= offsetDown && index < offsetUp) {
+ return SolitairePileType.down;
+ } else if (index >= offsetUp && index < 20) {
+ return SolitairePileType.up;
} else {
assert(false);
return null;
@@ -297,7 +297,7 @@
int source = findCard(c);
print("Can play? ${c}, ${source} ${destination}");
- if (phase != SolitairePhase.Play) {
+ if (phase != SolitairePhase.play) {
return "It is not the Play phase of Solitaire.";
}
if (source == -1) {
@@ -312,26 +312,26 @@
SolitairePileType sType = pileType(source);
SolitairePileType dType = pileType(destination);
switch (sType) {
- case SolitairePileType.ACES:
- if (dType != SolitairePileType.UP) {
+ case SolitairePileType.aces:
+ if (dType != SolitairePileType.up) {
return "Destination Pile for ACES pile should be an UP pile.";
}
return _checkUpDestination(c, source, destination, true);
- case SolitairePileType.DISCARD:
- if (dType == SolitairePileType.UP) {
+ case SolitairePileType.discard:
+ if (dType == SolitairePileType.up) {
return _checkUpDestination(c, source, destination, true);
- } else if (dType == SolitairePileType.ACES) {
+ } else if (dType == SolitairePileType.aces) {
return _checkAcesDestination(c, source, destination);
}
return "Destination Pile for DISCARD should be an UP or ACES pile.";
- case SolitairePileType.DRAW:
+ case SolitairePileType.draw:
return "Source Pile should not be a DRAW pile.";
- case SolitairePileType.DOWN:
+ case SolitairePileType.down:
return "Source Pile should not be a DOWN pile.";
- case SolitairePileType.UP:
- if (dType == SolitairePileType.UP) {
+ case SolitairePileType.up:
+ if (dType == SolitairePileType.up) {
return _checkUpDestination(c, source, destination, false);
- } else if (dType == SolitairePileType.ACES) {
+ } else if (dType == SolitairePileType.aces) {
return _checkAcesDestination(c, source, destination);
}
return "Destination Pile for UP should be an UP or ACES pile.";
diff --git a/lib/logic/solitaire/solitaire_phase.part.dart b/lib/logic/solitaire/solitaire_phase.part.dart
index cf6718d..461d613 100644
--- a/lib/logic/solitaire/solitaire_phase.part.dart
+++ b/lib/logic/solitaire/solitaire_phase.part.dart
@@ -4,4 +4,4 @@
part of solitaire;
-enum SolitairePhase { Deal, Play, Score }
+enum SolitairePhase { deal, play, score }
diff --git a/lib/src/mocks/log_writer.dart b/lib/src/mocks/log_writer.dart
index bc8cc97..de01547 100644
--- a/lib/src/mocks/log_writer.dart
+++ b/lib/src/mocks/log_writer.dart
@@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:convert' show JSON;
-enum SimulLevel { TURN_BASED, INDEPENDENT, DEPENDENT }
+enum SimulLevel { turnBased, independent, dependent }
typedef void keyValueCallback(String key, String value);
@@ -33,7 +33,7 @@
assert(!inProposalMode);
String key = _logKey(associatedUser);
- if (s == SimulLevel.DEPENDENT) {
+ if (s == SimulLevel.dependent) {
// We have to do extra work with "proposals".
inProposalMode = true;
String proposalData = JSON.encode({"key": key, "value": value});
diff --git a/lib/src/mocks/settings_manager.dart b/lib/src/mocks/settings_manager.dart
index d3509cf..3b1525f 100644
--- a/lib/src/mocks/settings_manager.dart
+++ b/lib/src/mocks/settings_manager.dart
@@ -4,10 +4,10 @@
import 'dart:async';
+import '../../logic/croupier_settings.dart' show CroupierSettings;
+import '../../logic/game/game.dart' as logic_game;
import '../../settings/client.dart' as settings_client;
import 'util.dart' as util;
-import '../../logic/game/game.dart' as logic_game;
-import '../../logic/croupier_settings.dart' show CroupierSettings;
class SettingsManager {
final util.keyValueCallback updateCallback;
diff --git a/lib/src/syncbase/log_writer.dart b/lib/src/syncbase/log_writer.dart
index 16a6dfc..ea7d5ef 100644
--- a/lib/src/syncbase/log_writer.dart
+++ b/lib/src/syncbase/log_writer.dart
@@ -28,7 +28,7 @@
import 'package:syncbase/syncbase_client.dart'
show SyncbaseDatabase, SyncbaseTable, WatchChange, WatchChangeTypes;
-enum SimulLevel { TURN_BASED, INDEPENDENT, DEPENDENT }
+enum SimulLevel { turnBased, independent, dependent }
class LogWriter {
// This callback is called on each watch update, passing the key and value.
@@ -143,7 +143,7 @@
assert(!inProposalMode);
String key = _logKey(associatedUser);
- if (s == SimulLevel.DEPENDENT) {
+ if (s == SimulLevel.dependent) {
inProposalMode = true;
proposalsKnown = new Map<String, String>();
diff --git a/lib/src/syncbase/settings_manager.dart b/lib/src/syncbase/settings_manager.dart
index 336c38c..60b17b0 100644
--- a/lib/src/syncbase/settings_manager.dart
+++ b/lib/src/syncbase/settings_manager.dart
@@ -122,7 +122,6 @@
}
// Forward any player changes and game status signals to Croupier's logic.
- // TODO(alexfandrianto): This also watches the log (but doesn't process it.
Future _onGameChange(String key, String value, bool duringScan) async {
if (key.indexOf("/players") != -1) {
if (this.updatePlayerFoundCallback != null) {
diff --git a/lib/src/syncbase/util.dart b/lib/src/syncbase/util.dart
index 83ec86e..2715e30 100644
--- a/lib/src/syncbase/util.dart
+++ b/lib/src/syncbase/util.dart
@@ -22,7 +22,6 @@
const String settingsPersonalKey = "personal";
const String settingsWatchSyncPrefix = "users";
-typedef void NoArgCb();
typedef void keyValueCallback(String key, String value);
typedef Future asyncKeyValueCallback(String key, String value, bool duringScan);
diff --git a/test/hearts_test.dart b/test/hearts_test.dart
index 95ed019..1fc19aa 100644
--- a/test/hearts_test.dart
+++ b/test/hearts_test.dart
@@ -11,88 +11,88 @@
void main() {
group("Initialization", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
test("Dealing", () {
game.dealCards(); // What the dealer actually runs to get cards to everybody.
// By virtue of creating the game, HeartsGame should have 4 collections with 13 cards and 8 collections with 0 cards each.
expect(
- game.cardCollections[HeartsGame.PLAYER_A + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerA + HeartsGame.offsetHand]
.length,
equals(13),
reason: "Dealt 13 cards to A");
expect(
- game.cardCollections[HeartsGame.PLAYER_B + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerB + HeartsGame.offsetHand]
.length,
equals(13),
reason: "Dealt 13 cards to B");
expect(
- game.cardCollections[HeartsGame.PLAYER_C + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerC + HeartsGame.offsetHand]
.length,
equals(13),
reason: "Dealt 13 cards to C");
expect(
- game.cardCollections[HeartsGame.PLAYER_D + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerD + HeartsGame.offsetHand]
.length,
equals(13),
reason: "Dealt 13 cards to D");
expect(
- game.cardCollections[HeartsGame.PLAYER_A + HeartsGame.OFFSET_PLAY]
+ game.cardCollections[HeartsGame.playerA + HeartsGame.offsetPlay]
.length,
equals(0),
reason: "Not playing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_B + HeartsGame.OFFSET_PLAY]
+ game.cardCollections[HeartsGame.playerB + HeartsGame.offsetPlay]
.length,
equals(0),
reason: "Not playing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_C + HeartsGame.OFFSET_PLAY]
+ game.cardCollections[HeartsGame.playerC + HeartsGame.offsetPlay]
.length,
equals(0),
reason: "Not playing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_D + HeartsGame.OFFSET_PLAY]
+ game.cardCollections[HeartsGame.playerD + HeartsGame.offsetPlay]
.length,
equals(0),
reason: "Not playing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_A + HeartsGame.OFFSET_PASS]
+ game.cardCollections[HeartsGame.playerA + HeartsGame.offsetPass]
.length,
equals(0),
reason: "Not passing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_B + HeartsGame.OFFSET_PASS]
+ game.cardCollections[HeartsGame.playerB + HeartsGame.offsetPass]
.length,
equals(0),
reason: "Not passing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_C + HeartsGame.OFFSET_PASS]
+ game.cardCollections[HeartsGame.playerC + HeartsGame.offsetPass]
.length,
equals(0),
reason: "Not passing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_D + HeartsGame.OFFSET_PASS]
+ game.cardCollections[HeartsGame.playerD + HeartsGame.offsetPass]
.length,
equals(0),
reason: "Not passing yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_A + HeartsGame.OFFSET_TRICK]
+ game.cardCollections[HeartsGame.playerA + HeartsGame.offsetTrick]
.length,
equals(0),
reason: "No tricks yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_B + HeartsGame.OFFSET_TRICK]
+ game.cardCollections[HeartsGame.playerB + HeartsGame.offsetTrick]
.length,
equals(0),
reason: "No tricks yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_C + HeartsGame.OFFSET_TRICK]
+ game.cardCollections[HeartsGame.playerC + HeartsGame.offsetTrick]
.length,
equals(0),
reason: "No tricks yet");
expect(
- game.cardCollections[HeartsGame.PLAYER_D + HeartsGame.OFFSET_TRICK]
+ game.cardCollections[HeartsGame.playerD + HeartsGame.offsetTrick]
.length,
equals(0),
reason: "No tricks yet");
@@ -104,7 +104,7 @@
HeartsGame game = new HeartsGame()..playerNumber = 0;
test("Compute/Prepare Score", () {
// In this situation, what's the score?
- game.cardCollections[HeartsGame.PLAYER_A_TRICK] = <Card>[
+ game.cardCollections[HeartsGame.playerTrickA] = <Card>[
new Card("classic", "dq"),
new Card("classic", "dk"),
new Card("classic", "h1"),
@@ -113,11 +113,11 @@
new Card("classic", "h4")
];
- expect(game.computeScore(HeartsGame.PLAYER_A), equals(4),
+ expect(game.computeScore(HeartsGame.playerA), equals(4),
reason: "Player A has 4 hearts");
// In this alternative situation, what's the score?
- game.cardCollections[HeartsGame.PLAYER_B_TRICK] = <Card>[
+ game.cardCollections[HeartsGame.playerTrickB] = <Card>[
new Card("classic", "h6"),
new Card("classic", "h7"),
new Card("classic", "h8"),
@@ -130,15 +130,15 @@
new Card("classic", "s2")
];
- expect(game.computeScore(HeartsGame.PLAYER_B), equals(8),
+ expect(game.computeScore(HeartsGame.playerB), equals(8),
reason: "Player B has 8 hearts.");
// Should prepare C as well.
- game.cardCollections[HeartsGame.PLAYER_C_TRICK] = <Card>[
+ game.cardCollections[HeartsGame.playerTrickC] = <Card>[
new Card("classic", "h5"),
new Card("classic", "sq")
];
- expect(game.computeScore(HeartsGame.PLAYER_C), equals(14),
+ expect(game.computeScore(HeartsGame.playerC), equals(14),
reason: "Player C has 1 heart and the queen of spades.");
// Now, update the score, modifying game.scores.
@@ -152,10 +152,10 @@
expect(game.deltaScores, equals([4, 8, 14, 0]));
// Shoot the moon!
- game.cardCollections[HeartsGame.PLAYER_A_TRICK] = <Card>[];
- game.cardCollections[HeartsGame.PLAYER_B_TRICK] = <Card>[];
- game.cardCollections[HeartsGame.PLAYER_C_TRICK] = <Card>[];
- game.cardCollections[HeartsGame.PLAYER_D_TRICK] = Card.All;
+ game.cardCollections[HeartsGame.playerTrickA] = <Card>[];
+ game.cardCollections[HeartsGame.playerTrickB] = <Card>[];
+ game.cardCollections[HeartsGame.playerTrickC] = <Card>[];
+ game.cardCollections[HeartsGame.playerTrickD] = Card.All;
game.updateScore();
expect(game.scores, equals([34, 42, 54, 0]));
expect(game.deltaScores, equals([26, 26, 26, 0]));
@@ -167,12 +167,12 @@
test("Has the game ended? Yes", () {
// Check if the game has ended. Should be yes.
- game.scores = <int>[HeartsGame.MAX_SCORE + 5, 40, 35, 0];
+ game.scores = <int>[HeartsGame.maxScore + 5, 40, 35, 0];
expect(game.hasGameEnded, isTrue);
});
test("Has the game ended? No", () {
// Check if the game has ended. Should be no.
- game.scores = <int>[HeartsGame.MAX_SCORE - 5, 40, 35, 0];
+ game.scores = <int>[HeartsGame.maxScore - 5, 40, 35, 0];
expect(game.hasGameEnded, isFalse);
});
});
@@ -200,7 +200,7 @@
}
test("Deal Phase", () {
- expect(game.phase, equals(HeartsPhase.Deal));
+ expect(game.phase, equals(HeartsPhase.deal));
// Deal consists of 4 deal commands.
runCommand();
@@ -221,13 +221,13 @@
List<Card> expectedDHand =
new List<Card>.from(Card.All.getRange(0, 0 + 5))
..addAll(Card.All.getRange(26 + 5, 39));
- expect(game.cardCollections[HeartsGame.PLAYER_A], equals(expectedAHand));
- expect(game.cardCollections[HeartsGame.PLAYER_B], equals(expectedBHand));
- expect(game.cardCollections[HeartsGame.PLAYER_C], equals(expectedCHand));
- expect(game.cardCollections[HeartsGame.PLAYER_D], equals(expectedDHand));
+ expect(game.cardCollections[HeartsGame.playerA], equals(expectedAHand));
+ expect(game.cardCollections[HeartsGame.playerB], equals(expectedBHand));
+ expect(game.cardCollections[HeartsGame.playerC], equals(expectedCHand));
+ expect(game.cardCollections[HeartsGame.playerD], equals(expectedDHand));
});
test("Pass Phase", () {
- expect(game.phase, equals(HeartsPhase.Pass));
+ expect(game.phase, equals(HeartsPhase.pass));
// Pass consists of 4 pass commands.
runCommand();
@@ -256,21 +256,21 @@
new List<Card>.from(Card.All.getRange(39, 39 + 3));
List<Card> expectedDPass =
new List<Card>.from(Card.All.getRange(0, 0 + 3));
- expect(game.cardCollections[HeartsGame.PLAYER_A], equals(expectedAHand));
- expect(game.cardCollections[HeartsGame.PLAYER_B], equals(expectedBHand));
- expect(game.cardCollections[HeartsGame.PLAYER_C], equals(expectedCHand));
- expect(game.cardCollections[HeartsGame.PLAYER_D], equals(expectedDHand));
- expect(game.cardCollections[HeartsGame.PLAYER_A_PASS],
- equals(expectedAPass));
- expect(game.cardCollections[HeartsGame.PLAYER_B_PASS],
- equals(expectedBPass));
- expect(game.cardCollections[HeartsGame.PLAYER_C_PASS],
- equals(expectedCPass));
- expect(game.cardCollections[HeartsGame.PLAYER_D_PASS],
- equals(expectedDPass));
+ expect(game.cardCollections[HeartsGame.playerA], equals(expectedAHand));
+ expect(game.cardCollections[HeartsGame.playerB], equals(expectedBHand));
+ expect(game.cardCollections[HeartsGame.playerC], equals(expectedCHand));
+ expect(game.cardCollections[HeartsGame.playerD], equals(expectedDHand));
+ expect(
+ game.cardCollections[HeartsGame.playerPassA], equals(expectedAPass));
+ expect(
+ game.cardCollections[HeartsGame.playerPassB], equals(expectedBPass));
+ expect(
+ game.cardCollections[HeartsGame.playerPassC], equals(expectedCPass));
+ expect(
+ game.cardCollections[HeartsGame.playerPassD], equals(expectedDPass));
});
test("Take Phase", () {
- expect(game.phase, equals(HeartsPhase.Take));
+ expect(game.phase, equals(HeartsPhase.take));
// Take consists of 4 take commands.
runCommand();
@@ -296,13 +296,13 @@
new List<Card>.from(Card.All.getRange(0 + 3, 0 + 5))
..addAll(Card.All.getRange(26 + 5, 39))
..addAll(Card.All.getRange(26, 26 + 3));
- expect(game.cardCollections[HeartsGame.PLAYER_A], equals(expectedAHand));
- expect(game.cardCollections[HeartsGame.PLAYER_B], equals(expectedBHand));
- expect(game.cardCollections[HeartsGame.PLAYER_C], equals(expectedCHand));
- expect(game.cardCollections[HeartsGame.PLAYER_D], equals(expectedDHand));
+ expect(game.cardCollections[HeartsGame.playerA], equals(expectedAHand));
+ expect(game.cardCollections[HeartsGame.playerB], equals(expectedBHand));
+ expect(game.cardCollections[HeartsGame.playerC], equals(expectedCHand));
+ expect(game.cardCollections[HeartsGame.playerD], equals(expectedDHand));
});
test("Play Phase - Trick 1", () {
- expect(game.phase, equals(HeartsPhase.Play));
+ expect(game.phase, equals(HeartsPhase.play));
// Play Trick 1 consists of 4 ask + 4 play + 1 take trick command.
for (int i = 0; i < 8; i++) {
@@ -316,11 +316,11 @@
// Confirm the winner of the round.
expect(game.lastTrickTaker, equals(3),
reason: "Player 3 played 4 of Clubs");
- expect(game.cardCollections[HeartsGame.PLAYER_D_TRICK].length, equals(4),
+ expect(game.cardCollections[HeartsGame.playerTrickD].length, equals(4),
reason: "Player 3 won 1 trick.");
});
test("Play Phase - Trick 2", () {
- expect(game.phase, equals(HeartsPhase.Play));
+ expect(game.phase, equals(HeartsPhase.play));
// Play Trick 2 consists of 4 ask + 4 play + 1 take trick command.
for (int i = 0; i < 8; i++) {
@@ -334,13 +334,13 @@
// Confirm the winner of the round.
expect(game.lastTrickTaker, equals(2),
reason: "Player 2 played Ace of Clubs");
- expect(game.cardCollections[HeartsGame.PLAYER_C_TRICK].length, equals(4),
+ expect(game.cardCollections[HeartsGame.playerTrickC].length, equals(4),
reason: "Player 2 won 1 trick.");
- expect(game.cardCollections[HeartsGame.PLAYER_D_TRICK].length, equals(4),
+ expect(game.cardCollections[HeartsGame.playerTrickD].length, equals(4),
reason: "Player 3 won 1 trick.");
});
test("Play Phase - Trick 13", () {
- expect(game.phase, equals(HeartsPhase.Play));
+ expect(game.phase, equals(HeartsPhase.play));
// Play Trick 13 consists of 44 ask + 44 play + 11 take trick command.
// Read line by line until the game is "over".
@@ -350,22 +350,22 @@
// Assert that hands/plays/passes are empty.
expect(
- game.cardCollections[HeartsGame.PLAYER_A + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerA + HeartsGame.offsetHand]
.length,
equals(0),
reason: "Played all cards");
expect(
- game.cardCollections[HeartsGame.PLAYER_B + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerB + HeartsGame.offsetHand]
.length,
equals(0),
reason: "Played all cards");
expect(
- game.cardCollections[HeartsGame.PLAYER_C + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerC + HeartsGame.offsetHand]
.length,
equals(0),
reason: "Played all cards");
expect(
- game.cardCollections[HeartsGame.PLAYER_D + HeartsGame.OFFSET_HAND]
+ game.cardCollections[HeartsGame.playerD + HeartsGame.offsetHand]
.length,
equals(0),
reason: "Played all cards");
@@ -374,19 +374,19 @@
expect(game.lastTrickTaker, equals(0),
reason: "Player 0 won the last trick.");
expect(
- game.cardCollections[HeartsGame.PLAYER_A_TRICK].length, equals(4 * 8),
+ game.cardCollections[HeartsGame.playerTrickA].length, equals(4 * 8),
reason: "Player 0 won 8 tricks.");
expect(
- game.cardCollections[HeartsGame.PLAYER_B_TRICK].length, equals(4 * 2),
+ game.cardCollections[HeartsGame.playerTrickB].length, equals(4 * 2),
reason: "Player 1 won 2 tricks.");
expect(
- game.cardCollections[HeartsGame.PLAYER_C_TRICK].length, equals(4 * 2),
+ game.cardCollections[HeartsGame.playerTrickC].length, equals(4 * 2),
reason: "Player 2 won 2 tricks.");
- expect(game.cardCollections[HeartsGame.PLAYER_D_TRICK].length, equals(4),
+ expect(game.cardCollections[HeartsGame.playerTrickD].length, equals(4),
reason: "Player 3 won 1 trick.");
});
test("Score Phase", () {
- expect(game.phase, equals(HeartsPhase.Score));
+ expect(game.phase, equals(HeartsPhase.score));
// Check score to ensure it matches the expectation.
expect(game.scores, equals([21, 3, 2, 0]));
@@ -402,7 +402,7 @@
runCommand();
// Back to the deal phase once everyone indicates that they are ready.
- expect(game.phase, equals(HeartsPhase.Deal));
+ expect(game.phase, equals(HeartsPhase.deal));
});
test("Score Phase - end of game", () {
expect(game.hasGameEnded, isFalse);
@@ -460,7 +460,7 @@
group("Card Manipulation - Error Cases", () {
test("Dealing - wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Score;
+ game.phase = HeartsPhase.score;
expect(() {
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
@@ -468,7 +468,7 @@
});
test("Dealing - missing card", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
expect(() {
game.gamelog.add(
new HeartsCommand.deal(0, <Card>[new Card("fake", "not real")]));
@@ -476,14 +476,14 @@
});
test("Dealing - too many cards dealt", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
expect(() {
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 15))));
}, throwsA(new isInstanceOf<StateError>()));
game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
expect(() {
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 5))));
@@ -493,7 +493,7 @@
});
test("Passing - wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
expect(() {
@@ -503,10 +503,10 @@
});
test("Passing - missing card", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Pass;
+ game.phase = HeartsPhase.pass;
expect(() {
game.gamelog.add(new HeartsCommand.pass(
0, new List<Card>.from(Card.All.getRange(13, 16))));
@@ -514,20 +514,20 @@
});
test("Passing - wrong number of cards", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Pass;
+ game.phase = HeartsPhase.pass;
expect(() {
game.gamelog.add(new HeartsCommand.pass(
0, new List<Card>.from(Card.All.getRange(0, 2))));
}, throwsA(new isInstanceOf<StateError>()));
game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Pass;
+ game.phase = HeartsPhase.pass;
expect(() {
game.gamelog.add(new HeartsCommand.pass(
0, new List<Card>.from(Card.All.getRange(0, 4))));
@@ -535,14 +535,14 @@
});
test("Taking - wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
expect(() {
game.gamelog.add(new HeartsCommand.take(3));
}, throwsA(new isInstanceOf<StateError>()));
});
test("Asking - wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
expect(() {
@@ -551,10 +551,10 @@
});
test("Asking - already asking", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.gamelog.add(new HeartsCommand.ask());
expect(() {
game.gamelog.add(new HeartsCommand.ask());
@@ -562,7 +562,7 @@
});
test("Playing - wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
expect(() {
@@ -571,20 +571,20 @@
});
test("Playing - not asking", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
expect(() {
game.gamelog.add(new HeartsCommand.play(0, Card.All[0]));
}, throwsA(new isInstanceOf<StateError>()));
});
test("Playing - missing card", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.gamelog.add(new HeartsCommand.ask());
expect(() {
game.gamelog.add(new HeartsCommand.play(0, Card.All[13]));
@@ -592,10 +592,10 @@
});
test("Playing - invalid card (not 2 of clubs as first card)", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
expect(() {
@@ -606,7 +606,7 @@
// NOTE: It is actually possible to be forced to play a penalty card on round 1.
// But the odds are miniscule, so this rule will be enforced.
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
game.gamelog.add(new HeartsCommand.deal(
@@ -615,7 +615,7 @@
2, new List<Card>.from(Card.All.getRange(26, 39))));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
game.gamelog.add(new HeartsCommand.play(0, Card.All[1]));
@@ -628,7 +628,7 @@
});
test("Playing - wrong turn", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 13))));
game.gamelog.add(new HeartsCommand.deal(
@@ -637,7 +637,7 @@
2, new List<Card>.from(Card.All.getRange(26, 39))));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
expect(() {
@@ -647,7 +647,7 @@
});
test("Playing - invalid card (suit mismatch)", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 12))..add(Card.All[25])));
game.gamelog.add(new HeartsCommand.deal(
@@ -656,7 +656,7 @@
2, new List<Card>.from(Card.All.getRange(26, 39))));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
game.gamelog.add(new HeartsCommand.play(0, Card.All[1]));
@@ -668,7 +668,7 @@
});
test("Playing - invalid card (hearts not broken yet)", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 12))..add(Card.All[38])));
game.gamelog.add(new HeartsCommand.deal(
@@ -677,7 +677,7 @@
new List<Card>.from(Card.All.getRange(26, 38))..add(Card.All[12])));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
game.gamelog.add(new HeartsCommand.play(0, Card.All[1]));
@@ -696,7 +696,7 @@
});
test("Asking - trick not taken yet", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0,
new List<Card>.from(Card.All.getRange(0, 11))
@@ -711,7 +711,7 @@
..add(Card.All[11])));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
game.gamelog.add(new HeartsCommand.play(0, Card.All[1]));
@@ -729,14 +729,14 @@
});
test("Playing - take trick wrong phase", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
expect(() {
game.gamelog.add(new HeartsCommand.takeTrick()); // bad phase
}, throwsA(new isInstanceOf<StateError>()));
});
test("Playing - take trick too soon", () {
HeartsGame game = new HeartsGame()..playerNumber = 0;
- game.phase = HeartsPhase.Deal;
+ game.phase = HeartsPhase.deal;
game.gamelog.add(new HeartsCommand.deal(
0, new List<Card>.from(Card.All.getRange(0, 12))..add(Card.All[38])));
game.gamelog.add(new HeartsCommand.deal(
@@ -745,7 +745,7 @@
new List<Card>.from(Card.All.getRange(26, 38))..add(Card.All[12])));
game.gamelog.add(new HeartsCommand.deal(
3, new List<Card>.from(Card.All.getRange(39, 52))));
- game.phase = HeartsPhase.Play;
+ game.phase = HeartsPhase.play;
game.lastTrickTaker = 0;
game.gamelog.add(new HeartsCommand.ask());
game.gamelog.add(new HeartsCommand.play(0, Card.All[1]));
diff --git a/test/solitaire_test.dart b/test/solitaire_test.dart
index f41e5b9..be18af3 100644
--- a/test/solitaire_test.dart
+++ b/test/solitaire_test.dart
@@ -47,22 +47,22 @@
// 0 to 6 in each down pile
// 1 in each up pile
for (int i = 0; i < 4; i++) {
- expect(game.cardCollections[SolitaireGame.OFFSET_ACES + i].length,
+ expect(game.cardCollections[SolitaireGame.offsetAces + i].length,
equals(0),
reason: "Ace piles start empty");
}
expect(
- game.cardCollections[SolitaireGame.OFFSET_DISCARD].length, equals(0),
+ game.cardCollections[SolitaireGame.offsetDiscard].length, equals(0),
reason: "Discard pile starts empty");
- expect(game.cardCollections[SolitaireGame.OFFSET_DRAW].length, equals(24),
+ expect(game.cardCollections[SolitaireGame.offsetDraw].length, equals(24),
reason: "Draw pile gets the remaining 24 cards");
for (int i = 0; i < 7; i++) {
- expect(game.cardCollections[SolitaireGame.OFFSET_DOWN + i].length,
+ expect(game.cardCollections[SolitaireGame.offsetDown + i].length,
equals(i),
reason: "Down pile ${i} starts with ${i} cards");
expect(
- game.cardCollections[SolitaireGame.OFFSET_UP + i].length, equals(1),
+ game.cardCollections[SolitaireGame.offsetUp + i].length, equals(1),
reason: "Up piles start with 1 card");
}
});
@@ -78,7 +78,7 @@
for (int cheatNum = 0; cheatNum < 13; cheatNum++) {
game.cheatUI();
for (int i = 0; i < 4; i++) {
- expect(game.cardCollections[SolitaireGame.OFFSET_ACES + i].length,
+ expect(game.cardCollections[SolitaireGame.offsetAces + i].length,
equals(cheatNum + 1));
}
}
@@ -94,13 +94,13 @@
SolitaireGame game = new SolitaireGame();
test("Has not won pre-deal", () {
- expect(game.phase, equals(SolitairePhase.Deal));
+ expect(game.phase, equals(SolitairePhase.deal));
expect(game.isGameWon, isFalse);
});
test("Has not won immediately after deal", () {
game.dealCardsUI(); // What we run when starting the game.
- expect(game.phase, equals(SolitairePhase.Play));
+ expect(game.phase, equals(SolitairePhase.play));
expect(game.isGameWon, isFalse);
});
@@ -108,17 +108,17 @@
for (int i = 0; i < 13; i++) {
game.cheatUI(); // What we run when cheating.
}
- expect(game.phase, equals(SolitairePhase.Score));
+ expect(game.phase, equals(SolitairePhase.score));
expect(game.isGameWon, isTrue);
// Now check an alternative suit order.
List<Card> aces0 =
- new List<Card>.from(game.cardCollections[SolitaireGame.OFFSET_ACES]);
+ new List<Card>.from(game.cardCollections[SolitaireGame.offsetAces]);
List<Card> aces1 = new List<Card>.from(
- game.cardCollections[SolitaireGame.OFFSET_ACES + 1]);
+ game.cardCollections[SolitaireGame.offsetAces + 1]);
- game.cardCollections[SolitaireGame.OFFSET_ACES].clear();
- game.cardCollections[SolitaireGame.OFFSET_ACES + 1].clear();
+ game.cardCollections[SolitaireGame.offsetAces].clear();
+ game.cardCollections[SolitaireGame.offsetAces + 1].clear();
// This expectation can be removed if isGameWon becomes a parameter, as
// opposed to a computed property. However, if that happens, this test
@@ -126,8 +126,8 @@
expect(game.isGameWon, isFalse);
// Swap the piles
- game.cardCollections[SolitaireGame.OFFSET_ACES].addAll(aces1);
- game.cardCollections[SolitaireGame.OFFSET_ACES + 1].addAll(aces0);
+ game.cardCollections[SolitaireGame.offsetAces].addAll(aces1);
+ game.cardCollections[SolitaireGame.offsetAces + 1].addAll(aces0);
expect(game.isGameWon, isTrue);
});
@@ -145,11 +145,11 @@
bool keepGoing = true;
for (int i = 0; keepGoing; i++) {
if (i == 0) {
- expect(game.phase, equals(SolitairePhase.Deal));
+ expect(game.phase, equals(SolitairePhase.deal));
} else if (!game.isGameWon) {
- expect(game.phase, equals(SolitairePhase.Play));
+ expect(game.phase, equals(SolitairePhase.play));
} else {
- expect(game.phase, equals(SolitairePhase.Score));
+ expect(game.phase, equals(SolitairePhase.score));
}
// Play the next step of the game until we run out.
@@ -160,7 +160,7 @@
// Naturally, we should ensure that we haven't won the game.
test("Solitaire Win == False", () {
expect(game.isGameWon, isFalse);
- expect(game.phase, equals(SolitairePhase.Play));
+ expect(game.phase, equals(SolitairePhase.play));
});
});
@@ -176,11 +176,11 @@
bool keepGoing = true;
for (int i = 0; keepGoing; i++) {
if (i == 0) {
- expect(game.phase, equals(SolitairePhase.Deal));
+ expect(game.phase, equals(SolitairePhase.deal));
} else if (!game.isGameWon) {
- expect(game.phase, equals(SolitairePhase.Play));
+ expect(game.phase, equals(SolitairePhase.play));
} else {
- expect(game.phase, equals(SolitairePhase.Score));
+ expect(game.phase, equals(SolitairePhase.score));
}
// Play the next step of the game until we run out.
@@ -191,7 +191,7 @@
// Check that we won the game.
test("Solitaire Win == True", () {
expect(game.isGameWon, isTrue);
- expect(game.phase, equals(SolitairePhase.Score));
+ expect(game.phase, equals(SolitairePhase.score));
});
});
@@ -199,7 +199,7 @@
test("Dealing - wrong phase", () {
expect(() {
SolitaireGame game = new SolitaireGame();
- game.phase = SolitairePhase.Score;
+ game.phase = SolitairePhase.score;
game.gamelog
.add(new SolitaireCommand.deal(new List<Card>.from(Card.All)));
}, throwsA(new isInstanceOf<StateError>()));
@@ -248,20 +248,20 @@
SolitaireGame g = new SolitaireGame();
// Top row
- g.cardCollections[SolitaireGame.OFFSET_ACES].add(s2);
- g.cardCollections[SolitaireGame.OFFSET_ACES + 2].add(h2);
- g.cardCollections[SolitaireGame.OFFSET_DISCARD].add(d2);
- g.cardCollections[SolitaireGame.OFFSET_DRAW].add(c11);
+ g.cardCollections[SolitaireGame.offsetAces].add(s2);
+ g.cardCollections[SolitaireGame.offsetAces + 2].add(h2);
+ g.cardCollections[SolitaireGame.offsetDiscard].add(d2);
+ g.cardCollections[SolitaireGame.offsetDraw].add(c11);
// Bottom row
- g.cardCollections[SolitaireGame.OFFSET_UP + 1].add(c3);
- g.cardCollections[SolitaireGame.OFFSET_UP + 2].add(h3);
- g.cardCollections[SolitaireGame.OFFSET_UP + 3].add(d1);
- g.cardCollections[SolitaireGame.OFFSET_UP + 4].add(s13);
- g.cardCollections[SolitaireGame.OFFSET_UP + 5].add(d3);
- g.cardCollections[SolitaireGame.OFFSET_UP + 6].add(d12);
+ g.cardCollections[SolitaireGame.offsetUp + 1].add(c3);
+ g.cardCollections[SolitaireGame.offsetUp + 2].add(h3);
+ g.cardCollections[SolitaireGame.offsetUp + 3].add(d1);
+ g.cardCollections[SolitaireGame.offsetUp + 4].add(s13);
+ g.cardCollections[SolitaireGame.offsetUp + 5].add(d3);
+ g.cardCollections[SolitaireGame.offsetUp + 6].add(d12);
- g.phase = SolitairePhase.Play;
+ g.phase = SolitairePhase.play;
return g;
}
@@ -269,9 +269,9 @@
// Cannot move d1 up to empty ACES slot if not in Play phase.
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
- game.phase = SolitairePhase.Deal;
+ game.phase = SolitairePhase.deal;
game.gamelog
- .add(new SolitaireCommand.move(d1, SolitaireGame.OFFSET_ACES + 1));
+ .add(new SolitaireCommand.move(d1, SolitaireGame.offsetAces + 1));
}, throwsA(new isInstanceOf<StateError>()));
// Cannot move d1 to nonexistent slot.
@@ -284,7 +284,7 @@
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(d1, SolitaireGame.OFFSET_ACES + 2));
+ .add(new SolitaireCommand.move(d1, SolitaireGame.offsetAces + 2));
}, throwsA(new isInstanceOf<StateError>()));
// However, we can move d1 to the unused ACES slot in the Play phase.
@@ -294,21 +294,21 @@
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(c11, SolitaireGame.OFFSET_UP + 6));
+ .add(new SolitaireCommand.move(c11, SolitaireGame.offsetUp + 6));
}, throwsA(new isInstanceOf<StateError>()));
// We cannot move d2 (discard) to the DRAW pile.
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(d2, SolitaireGame.OFFSET_DRAW));
+ .add(new SolitaireCommand.move(d2, SolitaireGame.offsetDraw));
}, throwsA(new isInstanceOf<StateError>()));
// We cannot move d1 (up) to the DISCARD pile either.
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(d1, SolitaireGame.OFFSET_DISCARD));
+ .add(new SolitaireCommand.move(d1, SolitaireGame.offsetDiscard));
}, throwsA(new isInstanceOf<StateError>()));
// There are restrictions on what can be played on ACES piles.
@@ -316,14 +316,14 @@
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(h3, SolitaireGame.OFFSET_ACES));
+ .add(new SolitaireCommand.move(h3, SolitaireGame.offsetAces));
}, throwsA(new isInstanceOf<StateError>()));
// Next, non-ace on empty ACES slot. (c3 to empty ACE)
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(c3, SolitaireGame.OFFSET_ACES + 3));
+ .add(new SolitaireCommand.move(c3, SolitaireGame.offsetAces + 3));
}, throwsA(new isInstanceOf<StateError>()));
// Below, we'll show that moving to ACES works for various cases.
@@ -333,21 +333,21 @@
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(h2, SolitaireGame.OFFSET_ACES + 5));
+ .add(new SolitaireCommand.move(h2, SolitaireGame.offsetAces + 5));
}, throwsA(new isInstanceOf<StateError>()));
// Next, number that isn't 1 lower. (c3 to h3)
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(c3, SolitaireGame.OFFSET_ACES + 2));
+ .add(new SolitaireCommand.move(c3, SolitaireGame.offsetAces + 2));
}, throwsA(new isInstanceOf<StateError>()));
// Last, an empty that doesn't receive a king. (c3 to empty UP)
expect(() {
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(c3, SolitaireGame.OFFSET_ACES));
+ .add(new SolitaireCommand.move(c3, SolitaireGame.offsetAces));
}, throwsA(new isInstanceOf<StateError>()));
// Below, we'll show that moving to UP works for various cases.
@@ -359,19 +359,19 @@
// Going to UP (empty) with a king. (s13 to empty)
SolitaireGame game = _makeArbitrarySolitaireGame();
game.gamelog
- .add(new SolitaireCommand.move(d1, SolitaireGame.OFFSET_ACES + 1));
+ .add(new SolitaireCommand.move(d1, SolitaireGame.offsetAces + 1));
game.gamelog
- .add(new SolitaireCommand.move(h3, SolitaireGame.OFFSET_ACES + 2));
+ .add(new SolitaireCommand.move(h3, SolitaireGame.offsetAces + 2));
game.gamelog
- .add(new SolitaireCommand.move(d2, SolitaireGame.OFFSET_ACES + 1));
+ .add(new SolitaireCommand.move(d2, SolitaireGame.offsetAces + 1));
game.gamelog
- .add(new SolitaireCommand.move(d12, SolitaireGame.OFFSET_UP + 4));
+ .add(new SolitaireCommand.move(d12, SolitaireGame.offsetUp + 4));
game.gamelog
- .add(new SolitaireCommand.move(s2, SolitaireGame.OFFSET_UP + 5));
+ .add(new SolitaireCommand.move(s2, SolitaireGame.offsetUp + 5));
game.gamelog
- .add(new SolitaireCommand.move(d2, SolitaireGame.OFFSET_UP + 1));
+ .add(new SolitaireCommand.move(d2, SolitaireGame.offsetUp + 1));
game.gamelog
- .add(new SolitaireCommand.move(s13, SolitaireGame.OFFSET_UP + 0));
+ .add(new SolitaireCommand.move(s13, SolitaireGame.offsetUp + 0));
});
// Consider various situations in which you cannot flip.
@@ -390,7 +390,7 @@
game.dealCardsUI();
// Remove some cards...
- game.cardCollections[SolitaireGame.OFFSET_UP + 1].clear();
+ game.cardCollections[SolitaireGame.offsetUp + 1].clear();
// Try to flip a pile that doesn't exist.
game.gamelog.add(new SolitaireCommand.flip(-1));
@@ -404,7 +404,7 @@
game.dealCardsUI();
// Remove some cards...
- game.cardCollections[SolitaireGame.OFFSET_UP + 1].clear();
+ game.cardCollections[SolitaireGame.offsetUp + 1].clear();
// Try to flip a pile that doesn't exist.
game.gamelog.add(new SolitaireCommand.flip(7));
@@ -418,8 +418,8 @@
game.dealCardsUI();
// Remove some cards...
- game.cardCollections[SolitaireGame.OFFSET_UP + 1].clear();
- game.cardCollections[SolitaireGame.OFFSET_DOWN + 1].clear();
+ game.cardCollections[SolitaireGame.offsetUp + 1].clear();
+ game.cardCollections[SolitaireGame.offsetDown + 1].clear();
// Try to flip a pile that doesn't exist.
game.gamelog.add(new SolitaireCommand.flip(1));
@@ -442,7 +442,7 @@
// Deal. Clear away pile 1. Flip pile 1.
game.dealCardsUI();
- game.cardCollections[SolitaireGame.OFFSET_UP + 1].clear();
+ game.cardCollections[SolitaireGame.offsetUp + 1].clear();
game.gamelog.add(new SolitaireCommand.flip(1));
});
@@ -460,7 +460,7 @@
game.dealCardsUI();
// Remove all draw cards.
- game.cardCollections[SolitaireGame.OFFSET_DRAW].clear();
+ game.cardCollections[SolitaireGame.offsetDraw].clear();
game.gamelog.add(new SolitaireCommand.draw());
}, throwsA(new isInstanceOf<StateError>()));