AVALANCHE: Rework mouse handling in Nim.
This commit is contained in:
parent
a869e76376
commit
3b341cff79
2 changed files with 28 additions and 31 deletions
|
@ -47,8 +47,6 @@ void Nim::resetVariables() {
|
||||||
_row = 0;
|
_row = 0;
|
||||||
_number = 0;
|
_number = 0;
|
||||||
_squeak = false;
|
_squeak = false;
|
||||||
_mNum = 0;
|
|
||||||
_mRow = 0;
|
|
||||||
_lmo = false;
|
_lmo = false;
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -223,32 +221,35 @@ void Nim::blip() {
|
||||||
_vm->_sound->playNote(1771, 3);
|
_vm->_sound->playNote(1771, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Nim::checkMouse() {
|
bool Nim::checkInput() {
|
||||||
Common::Point cursorPos = _vm->getMousePos();
|
while (!_vm->shouldQuit()) {
|
||||||
_vm->_graphics->refreshScreen();
|
|
||||||
Common::Event event;
|
|
||||||
// This loop needs "some" revision!!!
|
|
||||||
while (_vm->getEvent(event)) {
|
|
||||||
_vm->_graphics->refreshScreen();
|
_vm->_graphics->refreshScreen();
|
||||||
if (event.type == Common::EVENT_LBUTTONUP) {
|
Common::Event event;
|
||||||
_mRow = (cursorPos.y / 2 - 38) / 35 - 1;
|
while (_vm->getEvent(event)) {
|
||||||
if ((_mRow < 0) || (_mRow > 2)) {
|
if (event.type == Common::EVENT_LBUTTONUP) {
|
||||||
blip();
|
Common::Point cursorPos = _vm->getMousePos();
|
||||||
return false;
|
|
||||||
|
int8 mRow = (cursorPos.y / 2 - 38) / 35 - 1;
|
||||||
|
if ((mRow < 0) || (mRow > 2)) {
|
||||||
|
blip();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8 mNum = _stones[mRow] - ((cursorPos.x - 64) / 64);
|
||||||
|
if ((mNum < 1) || (mNum > _stones[mRow])) {
|
||||||
|
blip();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_number = mNum;
|
||||||
|
_row = mRow;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_mNum = _stones[_mRow] - ((cursorPos.x - 64) / 64);
|
|
||||||
if ((_mNum < 1) || (_mNum > _stones[_mRow])) {
|
|
||||||
blip();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Nim::less() {
|
|
||||||
if (_number > 1)
|
|
||||||
_number--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nim::takeSome() {
|
void Nim::takeSome() {
|
||||||
|
@ -272,16 +273,14 @@ void Nim::takeSome() {
|
||||||
_vm->_graphics->drawRectangle(Common::Rect(63 + (sr - _number) * 64, 38 + 35 * (_row + 1), 54 + sr * 64, 63 + 35 * (_row + 1)), kColorBlue);
|
_vm->_graphics->drawRectangle(Common::Rect(63 + (sr - _number) * 64, 38 + 35 * (_row + 1), 54 + sr * 64, 63 + 35 * (_row + 1)), kColorBlue);
|
||||||
_vm->_graphics->refreshScreen();
|
_vm->_graphics->refreshScreen();
|
||||||
|
|
||||||
bool clicked = false;
|
bool validInput = false;
|
||||||
do {
|
do {
|
||||||
clicked = checkMouse();
|
validInput = checkInput();
|
||||||
} while (clicked == false);
|
} while (!validInput);
|
||||||
|
|
||||||
_vm->_graphics->drawRectangle(Common::Rect(63 + (sr - _number) * 64, 38 + 35 * (_row + 1), 54 + sr * 64, 63 + 35 * (_row + 1)), kColorBlack);
|
_vm->_graphics->drawRectangle(Common::Rect(63 + (sr - _number) * 64, 38 + 35 * (_row + 1), 54 + sr * 64, 63 + 35 * (_row + 1)), kColorBlack);
|
||||||
_vm->_graphics->refreshScreen();
|
_vm->_graphics->refreshScreen();
|
||||||
|
|
||||||
_number = _mNum;
|
|
||||||
_row = _mRow;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
|
@ -51,7 +51,6 @@ private:
|
||||||
byte _row;
|
byte _row;
|
||||||
byte _number;
|
byte _number;
|
||||||
bool _squeak;
|
bool _squeak;
|
||||||
int8 _mNum, _mRow;
|
|
||||||
byte _playedNim; // How many times you've played Nim.
|
byte _playedNim; // How many times you've played Nim.
|
||||||
|
|
||||||
// Inner variables for dogFood(), find() and findAp().
|
// Inner variables for dogFood(), find() and findAp().
|
||||||
|
@ -65,8 +64,7 @@ private:
|
||||||
void startMove();
|
void startMove();
|
||||||
void showChanges();
|
void showChanges();
|
||||||
void blip();
|
void blip();
|
||||||
bool checkMouse();
|
bool checkInput();
|
||||||
void less();
|
|
||||||
void takeSome();
|
void takeSome();
|
||||||
void endOfGame();
|
void endOfGame();
|
||||||
bool find(byte x); // This gives TRUE if there's a pile with x stones in.
|
bool find(byte x); // This gives TRUE if there's a pile with x stones in.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue