blob: 7711ba064fd0af4975703ddfe91f106c914b1ff4 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
part of game_component;
class ProtoGameComponent extends GameComponent {
ProtoGameComponent(Game game, NoArgCb cb,
{double width, double height})
: super(game, cb, width: width, height: height);
ProtoGameComponentState createState() => new ProtoGameComponentState();
}
class ProtoGameComponentState extends GameComponentState<ProtoGameComponent> {
@override
Widget build(BuildContext context) {
List<Widget> cardCollections = new List<Widget>();
cardCollections.add(new Text(config.game.debugString));
for (int i = 0; i < 4; i++) {
List<logic_card.Card> cards = config.game.cardCollections[i];
CardCollectionComponent c = new CardCollectionComponent(
cards, config.game.playerNumber == i, CardCollectionOrientation.horz,
dragChildren: true,
acceptType: DropType.card,
acceptCallback: _makeGameMoveCallback,
width: config.width);
cardCollections.add(c); // flex
}
cardCollections.add(new Container(
decoration: new BoxDecoration(
backgroundColor: Colors.green[500], borderRadius: 5.0),
child: new CardCollectionComponent(
config.game.cardCollections[4], true, CardCollectionOrientation.show1,
dragChildren: true,
acceptType: DropType.card,
acceptCallback: _makeGameMoveCallback,
width: config.width)));
cardCollections.add(_makeDebugButtons());
return new Container(
decoration:
new BoxDecoration(backgroundColor: Colors.pink[500]),
child: new Flex(cardCollections, direction: FlexDirection.vertical));
}
void _makeGameMoveCallback(logic_card.Card card, List<logic_card.Card> dest) {
setState(() {
try {
config.game.move(card, dest);
} catch (e) {
print("You can't do that! ${e.toString()}");
config.game.debugString = e.toString();
}
});
}
Widget _makeDebugButtons() => new Flex([
new Text('P${config.game.playerNumber}'),
_makeButton('Switch View', _switchPlayersCallback),
_makeButton('Quit', _quitGameCallback)
]);
void _switchPlayersCallback() {
setState(() {
config.game.playerNumber = (config.game.playerNumber + 1) % 4;
});
}
}