Added Start button + minor UI changes
parent
aab6fc4af5
commit
412bb1a18c
|
@ -62,7 +62,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
game = Game(this);
|
game = Game(this);
|
||||||
_grid = List.generate(widget.gridSize,
|
_grid = List.generate(widget.gridSize,
|
||||||
(index) => List.generate(widget.gridSize, (index) => Stone()));
|
(index) => List.generate(widget.gridSize, (index) => Stone()));
|
||||||
game.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -78,7 +77,24 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Center(
|
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: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
@ -88,6 +104,22 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
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(
|
child: GridView.builder(
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: widget.gridSize,
|
crossAxisCount: widget.gridSize,
|
||||||
|
@ -96,11 +128,13 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
int row = index ~/ widget.gridSize;
|
int row = index ~/ widget.gridSize;
|
||||||
int col = 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);
|
Stone? stone = game.getStone(location);
|
||||||
|
|
||||||
// Überprüfen, ob der Stein in sl1 gespeichert ist
|
bool isSelected = (sl1 != null &&
|
||||||
bool isSelected = (sl1 != null && sl1!.row == row && sl1!.column == col);
|
sl1!.row == row &&
|
||||||
|
sl1!.column == col);
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
@ -109,29 +143,30 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
margin: const EdgeInsets.all(2),
|
margin: const EdgeInsets.all(2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
color: _getColorForStone(stone),
|
color: _getColorForStone(stone),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isSelected ? Colors.black : Colors.transparent,
|
color: isSelected
|
||||||
|
? Colors.black
|
||||||
|
: Colors.transparent,
|
||||||
width: 5,
|
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
|
@override
|
||||||
void gameStopped() {
|
void gameStopped() {
|
||||||
// TODO: implement gameStopped
|
// TODO: implement gameStopped
|
||||||
|
@ -195,8 +225,7 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
if (sl1 == null) {
|
if (sl1 == null) {
|
||||||
sl1 = StoneLocation(row: row, column: col);
|
sl1 = StoneLocation(row: row, column: col);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
game.swapStones(sl1!, StoneLocation(row: row, column: col));
|
||||||
sl1 = null;
|
sl1 = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue