From 13449472f2b2930cb09bcb685bf1d9a49c0d8ed1 Mon Sep 17 00:00:00 2001 From: urukgit Date: Sat, 23 Nov 2013 07:50:24 +0100 Subject: AVALANCHE: Implement Nim::playNim(). Repair naming of variables in Nim and add some helper functions. --- engines/avalanche/avalanche.cpp | 1 + engines/avalanche/avalot.cpp | 1 + engines/avalanche/nim.cpp | 73 +++++++++++++++++++++++++++++++++++++++-- engines/avalanche/nim.h | 28 +++++++++------- engines/avalanche/parser.cpp | 43 ++---------------------- engines/avalanche/parser.h | 1 - 6 files changed, 91 insertions(+), 56 deletions(-) diff --git a/engines/avalanche/avalanche.cpp b/engines/avalanche/avalanche.cpp index 573f9abe71..eacb01f132 100644 --- a/engines/avalanche/avalanche.cpp +++ b/engines/avalanche/avalanche.cpp @@ -213,6 +213,7 @@ const char *AvalancheEngine::getCopyrightString() const { void AvalancheEngine::synchronize(Common::Serializer &sz) { _animation->synchronize(sz); _parser->synchronize(sz); + _nim->synchronize(sz); _sequence->synchronize(sz); _background->synchronize(sz); diff --git a/engines/avalanche/avalot.cpp b/engines/avalanche/avalot.cpp index 27c02449e2..8b2a590e35 100644 --- a/engines/avalanche/avalot.cpp +++ b/engines/avalanche/avalot.cpp @@ -1481,6 +1481,7 @@ void AvalancheEngine::resetVariables() { _startTime = getTimeInSeconds(); _parser->resetVariables(); + _nim->resetVariables(); _animation->resetVariables(); _sequence->resetVariables(); _background->resetVariables(); diff --git a/engines/avalanche/nim.cpp b/engines/avalanche/nim.cpp index cc4681bf3b..faca3e491d 100644 --- a/engines/avalanche/nim.cpp +++ b/engines/avalanche/nim.cpp @@ -30,14 +30,83 @@ namespace Avalanche { -const char * const Nim::names[2] = {"Avalot", "Dogfood"}; +const char * const Nim::kNames[2] = {"Avalot", "Dogfood"}; Nim::Nim(AvalancheEngine *vm) { _vm = vm; + + _playedNim = 0; +} + +void Nim::resetVariables() { + _playedNim = 0; +} + +void Nim::synchronize(Common::Serializer &sz) { + sz.syncAsByte(_playedNim); } void Nim::playNim() { - warning("STUB: Nim::playNim()"); + if (_vm->_wonNim) { // Already won the game. + _vm->_dialogs->displayScrollChain('Q',6); + return; + } + + if (!_vm->_askedDogfoodAboutNim) { + _vm->_dialogs->displayScrollChain('q',84); + return; + } + + _vm->_dialogs->displayScrollChain('Q',3); + _playedNim++; + _vm->fadeOut(); + + _vm->_graphics->saveScreen(); + + CursorMan.showMouse(false); + setup(); + board(); + CursorMan.showMouse(true); + + do { + startMove(); + if (_dogfoodsTurn) + dogFood(); + else + takeSome(); + _stones[_row] -= _number; + showChanges(); + } while (_stonesLeft != 0); + + endOfGame(); // Winning sequence is A1, B3, B1, C1, C1, btw. + + _vm->fadeOut(); + CursorMan.showMouse(false); + + _vm->_graphics->restoreScreen(); + _vm->_graphics->removeBackup(); + + CursorMan.showMouse(true); + _vm->fadeIn(); + + if (_dogfoodsTurn) { // Dogfood won - as usual. + if (_playedNim == 1) // Your first game. + _vm->_dialogs->displayScrollChain('Q',4); // Goody! Play me again? + else + _vm->_dialogs->displayScrollChain('Q',5); // Oh, look at that! I've won again! + _vm->decreaseMoney(4); // And you've just lost 4d! + } + else { // You won - strange! + _vm->_dialogs->displayScrollChain('Q', 7); + _vm->_objects[kObjectLute - 1] = true; + _vm->refreshObjectList(); + _vm->_wonNim = true; + _vm->_background->draw(-1, -1, 0); // Show the settle with no lute on it. + _vm->incScore(7); // 7 points for winning! + } + + if (_playedNim == 1) + _vm->incScore(3); // 3 points for playing your 1st game. } void Nim::chalk(int x,int y, Common::String z) { diff --git a/engines/avalanche/nim.h b/engines/avalanche/nim.h index fba34f5b01..a76afcfe22 100644 --- a/engines/avalanche/nim.h +++ b/engines/avalanche/nim.h @@ -33,23 +33,27 @@ namespace Avalanche { class Nim { public: Nim(AvalancheEngine *vm); + void resetVariables(); + void synchronize(Common::Serializer &sz); void playNim(); private: AvalancheEngine *_vm; - static const char * const names[2]; - byte old[3]; - byte stones[3]; - byte stonePic[4][23][7]; // Picture of Nimstone. - byte turns; - bool dogfoodsTurn; - byte stonesLeft; - bool clicked; - byte row; - byte number; - bool squeak; - int8 mNum, mRow; + static const char * const kNames[2]; + + byte _old[3]; + byte _stones[3]; + byte _stonePic[4][23][7]; // Picture of Nimstone. + byte _turns; + bool _dogfoodsTurn; + byte _stonesLeft; + bool _clicked; + byte _row; + byte _number; + bool _squeak; + int8 _mNum, _mRow; + byte _playedNim; // How many times you've played Nim. void chalk(int x,int y, Common::String z); void setup(); diff --git a/engines/avalanche/parser.cpp b/engines/avalanche/parser.cpp index d5f57919b5..a77a71d157 100644 --- a/engines/avalanche/parser.cpp +++ b/engines/avalanche/parser.cpp @@ -51,7 +51,7 @@ Parser::Parser(AvalancheEngine *vm) { _thing2 = 0; _sworeNum = 0; _alcoholLevel = 0; - _playedNim = 0; + _boughtOnion = false; } @@ -1987,44 +1987,7 @@ void Parser::doThat() { // They just typed "play"... switch (_vm->_room) { case kRoomArgentPub: - // ...in the pub, => play Nim. - _vm->_nim->playNim(); - - // The following parts are copied from the original play_nim() and a little plus. - // The player automatically wins the game everytime he plays, until I implement the mini-game. - if (_vm->_wonNim) { // Already won the game. - _vm->_dialogs->displayScrollChain('Q', 6); - return; - } - - if (!_vm->_askedDogfoodAboutNim) { - _vm->_dialogs->displayScrollChain('q', 84); - return; - } - - _vm->_dialogs->displayScrollChain('Q', 3); - _playedNim++; - - // You won - strange! - - // You won! Give us a lute! - _vm->_dialogs->displayScrollChain('Q', 7); - _vm->_objects[kObjectLute - 1] = true; - _vm->refreshObjectList(); - _vm->_wonNim = true; - // Show the settle with no lute on it. - _vm->_background->draw(-1, -1, 0); - // 7 points for winning! - _vm->incScore(7); - - if (_playedNim == 1) - // 3 points for playing your 1st game. - _vm->incScore(3); - - // A warning to the player that there should have been a mini-game. TODO: Remove it later!!! - _vm->_dialogs->displayText(Common::String("P.S.: There should have been the mini-game called \"Nim\", " \ - "but I haven't implemented it yet: you win and get the lute automatically.") - + kControlNewLine + kControlNewLine + "Peter (uruk)"); + _vm->_nim->playNim(); // ...in the pub, => play Nim. break; case kRoomMusicRoom: playHarp(); @@ -2501,7 +2464,6 @@ void Parser::resetVariables() { _wearing = kNothing; _sworeNum = 0; _alcoholLevel = 0; - _playedNim = 0; _boughtOnion = false; } @@ -2509,7 +2471,6 @@ void Parser::synchronize(Common::Serializer &sz) { sz.syncAsByte(_wearing); sz.syncAsByte(_sworeNum); sz.syncAsByte(_alcoholLevel); - sz.syncAsByte(_playedNim); sz.syncAsByte(_boughtOnion); } diff --git a/engines/avalanche/parser.h b/engines/avalanche/parser.h index fe46170e65..20066329e5 100644 --- a/engines/avalanche/parser.h +++ b/engines/avalanche/parser.h @@ -108,7 +108,6 @@ private: byte _thing2; byte _sworeNum; // number of times you've sworn byte _alcoholLevel; // Your blood alcohol level. - byte _playedNim; // How many times you've played Nim. bool _boughtOnion; // Have you bought an onion yet? byte wordNum(Common::String word); -- cgit v1.2.3