generated from me/template-mit
Added lots of code, not completely showing value yet, but seems to be on the right track.
This commit is contained in:
+194
-22
@@ -18,6 +18,7 @@ class GameBoard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
gameReset();
|
||||
var text = "hello test lalala";
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -25,7 +26,7 @@ class GameBoard extends StatelessWidget {
|
||||
children: [
|
||||
// Player 1 Goal
|
||||
Column(
|
||||
children: [Center(child: PlayerHole(text: "P1"))],
|
||||
children: [Center(child: PlayerSpot(text: SCORE[0].toString()))],
|
||||
),
|
||||
// Center holes
|
||||
Column(
|
||||
@@ -36,12 +37,24 @@ class GameBoard extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(children: [BoardSpot(text: "0,0")]),
|
||||
Column(children: [BoardSpot(text: "1,0")]),
|
||||
Column(children: [BoardSpot(text: "2,0")]),
|
||||
Column(children: [BoardSpot(text: "3,0")]),
|
||||
Column(children: [BoardSpot(text: "4,0")]),
|
||||
Column(children: [BoardSpot(text: "5,0")]),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 11, text: BOARD[11].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 10, text: BOARD[10].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 09, text: BOARD[09].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 08, text: BOARD[08].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 07, text: BOARD[07].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 06, text: BOARD[06].toString())],
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
@@ -49,20 +62,33 @@ class GameBoard extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(children: [BoardSpot(text: "0,1")]),
|
||||
Column(children: [BoardSpot(text: "1,1")]),
|
||||
Column(children: [BoardSpot(text: "2,1")]),
|
||||
Column(children: [BoardSpot(text: "3,1")]),
|
||||
Column(children: [BoardSpot(text: "4,1")]),
|
||||
Column(children: [BoardSpot(text: "5,1")]),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 00, text: BOARD[00].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 01, text: BOARD[01].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 02, text: BOARD[02].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 03, text: BOARD[03].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 04, text: BOARD[04].toString())],
|
||||
),
|
||||
Column(
|
||||
children: [BoardSpot(spot: 05, text: BOARD[05].toString())],
|
||||
),
|
||||
],
|
||||
),
|
||||
BoardSpot(text: text, w: 75, h: 200),
|
||||
Text(text),
|
||||
ButtonReset(),
|
||||
],
|
||||
),
|
||||
// Player 2 Goal
|
||||
Column(
|
||||
children: [Center(child: PlayerHole(text: "P2"))],
|
||||
children: [Center(child: PlayerSpot(text: SCORE[1].toString()))],
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -71,17 +97,23 @@ class GameBoard extends StatelessWidget {
|
||||
|
||||
class BoardSpot extends StatefulWidget {
|
||||
final String text;
|
||||
final int spot;
|
||||
final double w;
|
||||
final double h;
|
||||
|
||||
BoardSpot({super.key, required this.text, this.w = 50, this.h = 50});
|
||||
BoardSpot({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.spot,
|
||||
this.w = 50,
|
||||
this.h = 50,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BoardSpot> createState() => _BoardSpotState();
|
||||
}
|
||||
|
||||
class _BoardSpotState extends State<BoardSpot> {
|
||||
var _marbles = 4;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
@@ -89,26 +121,166 @@ class _BoardSpotState extends State<BoardSpot> {
|
||||
onTap: () {
|
||||
// 3. Update the state
|
||||
setState(() {
|
||||
_marbles++;
|
||||
if (widget.text == "Reset") {
|
||||
gameReset();
|
||||
} else {
|
||||
gameTurn(widget.spot, BOARD[widget.spot]);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 4. The sized box containing the text
|
||||
child: SizedBox(
|
||||
width: widget.w,
|
||||
height: widget.h,
|
||||
child: Center(child: Text("$_marbles", textAlign: TextAlign.center)),
|
||||
child: Center(child: Text(widget.text, textAlign: TextAlign.center)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerHole extends StatelessWidget {
|
||||
class PlayerSpot extends StatelessWidget {
|
||||
final String text;
|
||||
|
||||
PlayerHole({super.key, required this.text});
|
||||
PlayerSpot({super.key, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BoardSpot(w: 50, h: 100, text: text);
|
||||
return BoardSpot(w: 50, h: 100, text: text, spot: 50);
|
||||
}
|
||||
}
|
||||
|
||||
/* Gameplay Implementation Notes (2026-05-06)
|
||||
Initial thought is to have an array for all the holes, a method to tell which hole is being played, and a mnethod which gets passed the "next step" while the previous loops over the number of marbles.
|
||||
The next step one will call anther method which checks if the player hole needs to be filled or not, and it knows based on globl variables like who's turn it is and whether spot 5 or 11 are being played in the index (0-11, not 1-12).
|
||||
So, if the board was like this:
|
||||
11 10 09 08 07 06
|
||||
00 01 02 03 04 05
|
||||
|
||||
Bottom chooses 02 which passes (spot: 02, marbles:4) to Method1.
|
||||
If the player is Bottom, and the spot just went from 6 -> 7, give them a point and marble--.
|
||||
if the player is Top, and the spot just went from 11 -> 00, "".
|
||||
|
||||
Soo...
|
||||
|
||||
Method1 says while marbles > 0, check if player needs rearded, spot++, Method2(spot % 12), marbles--;
|
||||
Mathod2 simply adds a marble to the spot.
|
||||
Method3 simply adds a marble to the player's hole.
|
||||
|
||||
Pseudo code...
|
||||
|
||||
playMove (int spot, int marbles, bool topPlayer) {
|
||||
marbleReduce(spot, marbles)
|
||||
whie marbles > 0 {
|
||||
if (spot == 6 && !boolTopPlayerTurn) {
|
||||
rewardPlayer(boolTopPlayerTurn)
|
||||
marbles--;
|
||||
} else if (spot == 11 && boolTopPlayerTurn) {
|
||||
rewardPlayer(boolTopPlayerTurn)
|
||||
marbles--
|
||||
}
|
||||
if (marbles == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
spot++;
|
||||
addMarble(spot);
|
||||
marble--;
|
||||
}
|
||||
}
|
||||
|
||||
marbleAdd (int: spot) {
|
||||
BOARD[spot]++;
|
||||
}
|
||||
|
||||
marbleReward (bool boolTopPlayer, int marbles) {
|
||||
if (boolTopPlayer) {
|
||||
SCORE[0] += marbles;
|
||||
} else {
|
||||
SCORE[1] += marbles;
|
||||
}
|
||||
}
|
||||
|
||||
Oh, also need too removve the marbles from the originally called spot befpre the while loop!
|
||||
|
||||
marbleRemove (int spot, int marbles) {
|
||||
// This should always be taking it down to 0, but doing the math anyways
|
||||
// just t make sure nothing wonky is going on, like 4 being removed then
|
||||
// 5 being moved across the board or something. Which would likely be unrelated
|
||||
// code elsewhere, but oh well.
|
||||
|
||||
BOARD[spot] -= marbles;
|
||||
}
|
||||
*/
|
||||
|
||||
void gameTurn(int spot, int marbles) {
|
||||
marbleRemove(spot, marbles);
|
||||
while (marbles > 0) {
|
||||
if (spot == 6 && !boolTopPlayerTurn) {
|
||||
marbleReward(boolTopPlayerTurn, 1);
|
||||
marbles--;
|
||||
} else if (spot == 11 && boolTopPlayerTurn) {
|
||||
marbleReward(boolTopPlayerTurn, 1);
|
||||
marbles--;
|
||||
}
|
||||
if (marbles == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
spot++;
|
||||
marbleAdd(spot % 12);
|
||||
marbles--;
|
||||
}
|
||||
|
||||
// TODO: Check if this is the only marble in the hole, and if it's on the player's side, and if so, steal all the marbles on the opposite side.
|
||||
if (BOARD[spot % 12] == 1 &&
|
||||
((boolTopPlayerTurn && spot >= 6) || (!boolTopPlayerTurn && spot <= 5))) {
|
||||
// Spot 00 steals 11, 01 steals 10, ... 05 steals 06.
|
||||
// This is a function of (spot_to_check = 11 - spot)
|
||||
int spotToCheck = 11 - spot;
|
||||
int theft = BOARD[spotToCheck];
|
||||
marbleReward(boolTopPlayerTurn, theft);
|
||||
marbleRemove(spotToCheck, marbles);
|
||||
}
|
||||
|
||||
boolTopPlayerTurn = !boolTopPlayerTurn;
|
||||
}
|
||||
|
||||
List<int> BOARD = [];
|
||||
List<int> SCORE = [];
|
||||
bool boolTopPlayerTurn = false;
|
||||
|
||||
void gameReset() {
|
||||
BOARD = [];
|
||||
for (int i = 0; i < 12; i++) {
|
||||
BOARD.add(4);
|
||||
}
|
||||
SCORE = [0, 0];
|
||||
}
|
||||
|
||||
void marbleAdd(int spot) {
|
||||
BOARD[spot]++;
|
||||
}
|
||||
|
||||
void marbleReward(bool boolTopPlayer, int marbles) {
|
||||
if (boolTopPlayer) {
|
||||
SCORE[0] += marbles;
|
||||
} else {
|
||||
SCORE[1] += marbles;
|
||||
}
|
||||
}
|
||||
|
||||
void marbleRemove(int spot, int marbles) {
|
||||
// This should always be taking it down to 0, but doing the math anyways
|
||||
// just t make sure nothing wonky is going on, like 4 being removed then
|
||||
// 5 being moved across the board or something. Which would likely be unrelated
|
||||
// code elsewhere, but oh well.
|
||||
|
||||
BOARD[spot] -= marbles;
|
||||
}
|
||||
|
||||
class ButtonReset extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BoardSpot(w: 50, h: 100, text: 'Reset', spot: 50);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user