Added Start button + minor UI changes
parent
aab6fc4af5
commit
412bb1a18c
|
@ -62,7 +62,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
game = Game(this);
|
||||
_grid = List.generate(widget.gridSize,
|
||||
(index) => List.generate(widget.gridSize, (index) => Stone()));
|
||||
game.start();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -78,7 +77,24 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
child: game.running ? _buildGameGrid() : _buildStartButton(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStartButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
game.start();
|
||||
});
|
||||
},
|
||||
child: const Text("Start"),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGameGrid() {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
|
@ -88,6 +104,22 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
double gridSize = widget.gridSize * 104.0;
|
||||
double maxGridSize =
|
||||
constraints.maxWidth < constraints.maxHeight
|
||||
? constraints.maxWidth
|
||||
: constraints.maxHeight;
|
||||
|
||||
double adjustedGridSize =
|
||||
gridSize > maxGridSize ? maxGridSize : gridSize;
|
||||
|
||||
return SizedBox(
|
||||
width: adjustedGridSize,
|
||||
height: adjustedGridSize,
|
||||
child: GridView.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: widget.gridSize,
|
||||
|
@ -96,11 +128,13 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
int row = index ~/ widget.gridSize;
|
||||
int col = index % widget.gridSize;
|
||||
StoneLocation location = StoneLocation(row: row, column: col);
|
||||
StoneLocation location =
|
||||
StoneLocation(row: row, column: col);
|
||||
Stone? stone = game.getStone(location);
|
||||
|
||||
// Überprüfen, ob der Stein in sl1 gespeichert ist
|
||||
bool isSelected = (sl1 != null && sl1!.row == row && sl1!.column == col);
|
||||
bool isSelected = (sl1 != null &&
|
||||
sl1!.row == row &&
|
||||
sl1!.column == col);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
|
@ -109,29 +143,30 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
});
|
||||
},
|
||||
child: Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
margin: const EdgeInsets.all(2),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: _getColorForStone(stone),
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.black : Colors.transparent,
|
||||
color: isSelected
|
||||
? Colors.black
|
||||
: Colors.transparent,
|
||||
width: 5,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_getStoneColorText(stone) + row.toString() + col.toString(),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -153,11 +188,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
String _getStoneColorText(Stone? stone) {
|
||||
if (stone == null) return 'Unknown';
|
||||
return stone.getStoneColor().toString().split('.').last;
|
||||
}
|
||||
|
||||
@override
|
||||
void gameStopped() {
|
||||
// TODO: implement gameStopped
|
||||
|
@ -191,12 +221,11 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
return game;
|
||||
}
|
||||
|
||||
void handleTap(int row, int col){
|
||||
if(sl1 == null){
|
||||
void handleTap(int row, int col) {
|
||||
if (sl1 == null) {
|
||||
sl1 = StoneLocation(row: row, column: col);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
||||
sl1 = null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue