* Fixed off by one error in the number of clicks to finish the game (it can
hardly be odd). * Fixed spelling error Genarate -> Generate. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26941 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Copyright 2008, Ralf Schülke, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "PairsView.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -47,7 +48,7 @@ PairsView::CreateGameBoard()
|
||||
if (child->IsHidden())
|
||||
child->Show();
|
||||
}
|
||||
_GenarateCardPos();
|
||||
_GenerateCardPos();
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +172,7 @@ PairsView::_SetPairsBoard()
|
||||
|
||||
|
||||
void
|
||||
PairsView::_GenarateCardPos()
|
||||
PairsView::_GenerateCardPos()
|
||||
{
|
||||
_ReadRandomIcons();
|
||||
|
||||
@@ -213,5 +214,3 @@ PairsView::GetIconFromPos(int pos)
|
||||
{
|
||||
return fRandPos[pos];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
* Copyright 2008, Ralf Schülke, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef PAIRS_VIEW_H
|
||||
#define PAIRS_VIEW_H
|
||||
|
||||
|
||||
#include <View.h>
|
||||
|
||||
|
||||
class TopButton;
|
||||
|
||||
class PairsView : public BView {
|
||||
@@ -26,7 +27,7 @@ public:
|
||||
private:
|
||||
void _SetPairsBoard();
|
||||
void _ReadRandomIcons();
|
||||
void _GenarateCardPos();
|
||||
void _GenerateCardPos();
|
||||
|
||||
BMessage* fButtonMessage;
|
||||
BBitmap* fCard[8];
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "PairsWindow.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Application.h>
|
||||
@@ -14,7 +16,6 @@
|
||||
|
||||
#include "Pairs.h"
|
||||
#include "PairsGlobal.h"
|
||||
#include "PairsWindow.h"
|
||||
#include "PairsView.h"
|
||||
#include "PairsTopButton.h"
|
||||
|
||||
@@ -52,13 +53,13 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
switch (message->what) {
|
||||
case kMsgCardButton:
|
||||
if (fIsPairsActive) {
|
||||
fButtonClicks = fButtonClicks + 1;
|
||||
fButtonClicks++;
|
||||
|
||||
int32 num;
|
||||
if (message->FindInt32("ButtonNum", &num) < B_OK)
|
||||
break;
|
||||
|
||||
//look what Icon is behind a button
|
||||
// look what Icon is behind a button
|
||||
for (int h = 0; h < 16; h++) {
|
||||
if (fPairsView->GetIconFromPos(h) == num) {
|
||||
fPairCard = (h % 8);
|
||||
@@ -67,7 +68,7 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
}
|
||||
|
||||
//gameplay
|
||||
// gameplay
|
||||
fPairsView->fDeckCard[fButton]->Hide();
|
||||
|
||||
if (fIsFirstClick) {
|
||||
@@ -100,7 +101,7 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
fPairsView->fDeckCard[fButtonTmp]->Show();
|
||||
}
|
||||
|
||||
//game end and results
|
||||
// game end and results
|
||||
if (fFinishPairs == 8) {
|
||||
BString strAbout;
|
||||
strAbout
|
||||
@@ -108,11 +109,11 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
<< "\twritten by Ralf Schülke\n"
|
||||
<< "\tCopyright 2008, Haiku Inc.\n"
|
||||
<< "\n"
|
||||
<< "You completed the game in " << fButtonClicks + 1
|
||||
<< "You completed the game in " << fButtonClicks
|
||||
<< " clicks.\n";
|
||||
|
||||
BAlert* alert = new BAlert("about", strAbout.String(), "New game",
|
||||
"Quit game");
|
||||
BAlert* alert = new BAlert("about", strAbout.String(),
|
||||
"New game", "Quit game");
|
||||
|
||||
BTextView* view = alert->TextView();
|
||||
BFont font;
|
||||
@@ -126,12 +127,12 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
view->ResizeToPreferred();
|
||||
|
||||
if (alert->Go() == 0) {
|
||||
//New game
|
||||
// New game
|
||||
fButtonClicks = 0;
|
||||
fFinishPairs = 0;
|
||||
fPairsView->CreateGameBoard();
|
||||
} else {
|
||||
//Quit game
|
||||
// Quit game
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
}
|
||||
@@ -142,5 +143,3 @@ PairsWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user