AVALANCHE: Implement Nim::playNim().

Repair naming of variables in Nim and add some helper functions.
This commit is contained in:
urukgit 2013-11-23 07:50:24 +01:00
parent d58775f792
commit 13449472f2
6 changed files with 91 additions and 56 deletions

View File

@ -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);

View File

@ -1481,6 +1481,7 @@ void AvalancheEngine::resetVariables() {
_startTime = getTimeInSeconds();
_parser->resetVariables();
_nim->resetVariables();
_animation->resetVariables();
_sequence->resetVariables();
_background->resetVariables();

View File

@ -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) {

View File

@ -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();

View File

@ -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);
}

View File

@ -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);