void TicTacToeLogic::WinGame(const NsString& winPlay) { for (NsSize row = 0; row < 3; ++row) { for (NsSize col = 0; col < 3; ++col) { mBoard[row][col].btn->SetIsEnabled(false); } } mStatusMsg = NsString::Format("Player %d Wins", mPlayer == Player_1 ? 1 : 2); TimelineCollection* timelines = mWinAnimation->GetChildren(); NS_ASSERT(timelines->Count() == 3); DependencyObject* anim0 = NsStaticCast<DependencyObject*>(timelines->Get(0)); Storyboard::SetTargetName(anim0, winPlay.c_str()); DependencyObject* anim1 = NsStaticCast<DependencyObject*>(timelines->Get(1)); Storyboard::SetTargetName(anim1, winPlay.c_str()); DependencyObject* anim2 = NsStaticCast<DependencyObject*>(timelines->Get(2)); Storyboard::SetTargetName(anim2, winPlay.c_str()); mProgressFadeAnimation->Begin(mRoot); mWinAnimation->Begin(mRoot); mStatusHalfAnimation->Begin(mRoot); }
TicTacToeLogic::TicTacToeLogic(Noesis::Gui::FrameworkElement* uiRoot): mRoot(uiRoot) { NS_ASSERT(mRoot); mBoardPanel = NsStaticCast<FrameworkElement*>(mRoot->FindName("Board")); NS_ASSERT(mBoardPanel); mBoardPanel->MouseLeftButtonDown() += MakeDelegate(this, &TicTacToeLogic::BoardClicked); for (NsSize row = 0; row < 3; ++row) { for (NsSize col = 0; col < 3; ++col) { NsString cellName = NsString::Format("Cell%u%u", row, col); ToggleButton* btn = NsStaticCast<ToggleButton*>(mRoot->FindName(cellName.c_str())); NS_ASSERT(btn); Cell& cell = mBoard[row][col]; cell.btn = btn; Ptr<Boxing::BoxedValue> boxedCell = Boxing::Box<Cell*>(&cell); btn->SetTag(boxedCell.GetPtr()); btn->SetIsEnabled(false); btn->Checked() += MakeDelegate(this, &TicTacToeLogic::CellChecked); } } mStatusText = NsStaticCast<TextBlock*>(mRoot->FindName("StatusText")); NS_ASSERT(mStatusText); mScorePlayer1Text = NsStaticCast<TextBlock*>(mRoot->FindName("ScorePlayer1")); NS_ASSERT(mScorePlayer1Text); mScorePlayer2Text = NsStaticCast<TextBlock*>(mRoot->FindName("ScorePlayer2")); NS_ASSERT(mScorePlayer2Text); mScoreTiesText = NsStaticCast<TextBlock*>(mRoot->FindName("ScoreTies")); NS_ASSERT(mScoreTiesText); mScoreText = 0; Ptr<ResourceKeyString> key; key = ResourceKeyString::Create("WinAnim"); mWinAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mWinAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::WinAnimationCompleted); key = ResourceKeyString::Create("TieAnim"); mTieAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mTieAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::TieAnimationCompleted); key = ResourceKeyString::Create("ResetAnim"); mResetAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mResetAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::ResetAnimationCompleted); key = ResourceKeyString::Create("ProgressAnim"); mProgressAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); key = ResourceKeyString::Create("ProgressFadeAnim"); mProgressFadeAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mProgressFadeAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::ProgressFadeAnimationCompleted); key = ResourceKeyString::Create("ScoreHalfAnim"); mScoreHalfAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mScoreHalfAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::ScoreHalfAnimationCompleted); key = ResourceKeyString::Create("ScoreEndAnim"); mScoreEndAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); key = ResourceKeyString::Create("StatusHalfAnim"); mStatusHalfAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mStatusHalfAnimation->Completed() += MakeDelegate(this, &TicTacToeLogic::StatusHalfAnimationCompleted); key = ResourceKeyString::Create("StatusEndAnim"); mStatusEndAnimation = NsStaticCast<Storyboard*>(mRoot->FindResource(key.GetPtr())); mStatusText->SetText("Player 1 Turn"); mPlayer = Player_1; mLastStarterPlayer = Player_1; mScorePlayer1 = 0; mScorePlayer2 = 0; mScoreTies = 0; mScore = 0; StartGame(); }
void NsConsole::AddMessage(const NsString & sMessage) { AddMessage(sMessage.c_str()); }