Progress
This commit is contained in:
@ -17,4 +17,9 @@ namespace Dawn {
|
||||
const std::map<uint8_t, enum TicTacToeTileState> board,
|
||||
std::vector<uint8_t> *winningCombo
|
||||
);
|
||||
|
||||
int32_t ticTacToeGetAiMove(
|
||||
std::map<uint8_t, enum TicTacToeTileState> board,
|
||||
enum TicTacToeTileState player
|
||||
);
|
||||
}
|
@ -10,7 +10,11 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {}
|
||||
TicTacToeGame::TicTacToeGame(SceneItem *item) :
|
||||
SceneItemComponent(item),
|
||||
winner(TIC_TAC_TOE_EMPTY),
|
||||
nextMove(TIC_TAC_TOE_NOUGHT)
|
||||
{}
|
||||
|
||||
void TicTacToeGame::onStart() {
|
||||
// Map tiles by tile number = tile
|
||||
@ -21,8 +25,20 @@ void TicTacToeGame::onStart() {
|
||||
++itTiles;
|
||||
}
|
||||
|
||||
// Listen
|
||||
useEffect([&]{
|
||||
if(nextMove != TIC_TAC_TOE_CROSS) return;
|
||||
std::cout << "AI Move" << std::endl;
|
||||
}, nextMove);
|
||||
|
||||
useEffect([&]{
|
||||
if(winner == TIC_TAC_TOE_NOUGHT) return;
|
||||
std::cout << "Winner is " << winner << std::endl;
|
||||
}, winner);
|
||||
|
||||
useEvent([&](float_t delta) {
|
||||
// Only allow player input if it's their turn.
|
||||
if(nextMove != TIC_TAC_TOE_NOUGHT) return;
|
||||
|
||||
// Get mouse in screen space.
|
||||
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
|
||||
mouse *= 2.0f;
|
||||
@ -75,6 +91,6 @@ void TicTacToeGame::onStart() {
|
||||
|
||||
// Determine winner
|
||||
std::vector<uint8_t> winningCombo;
|
||||
auto winner = ticTacToeDetermineWinner(tileMap, &winningCombo);
|
||||
winner = ticTacToeDetermineWinner(tileMap, &winningCombo);
|
||||
}, getScene()->eventSceneUpdate);
|
||||
}
|
@ -11,8 +11,9 @@
|
||||
namespace Dawn {
|
||||
class TicTacToeGame : public SceneItemComponent {
|
||||
public:
|
||||
StateProperty<TicTacToeTileState> winner;
|
||||
std::map<int32_t, TicTacToeTile*> tiles;
|
||||
enum TicTacToeTileState nextMove = TIC_TAC_TOE_NOUGHT;
|
||||
StateProperty<enum TicTacToeTileState> nextMove;
|
||||
|
||||
TicTacToeGame(SceneItem *item);
|
||||
|
||||
|
Reference in New Issue
Block a user