* 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:
Axel Dörfler
2008-08-12 13:03:36 +00:00
parent fb6d782320
commit 0eb592d7fe
3 changed files with 49 additions and 50 deletions
+3 -4
View File
@@ -2,6 +2,7 @@
* Copyright 2008, Ralf Schülke, [email protected]. All rights reserved. * Copyright 2008, Ralf Schülke, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "PairsView.h" #include "PairsView.h"
#include <stdio.h> #include <stdio.h>
@@ -47,7 +48,7 @@ PairsView::CreateGameBoard()
if (child->IsHidden()) if (child->IsHidden())
child->Show(); child->Show();
} }
_GenarateCardPos(); _GenerateCardPos();
} }
@@ -171,7 +172,7 @@ PairsView::_SetPairsBoard()
void void
PairsView::_GenarateCardPos() PairsView::_GenerateCardPos()
{ {
_ReadRandomIcons(); _ReadRandomIcons();
@@ -213,5 +214,3 @@ PairsView::GetIconFromPos(int pos)
{ {
return fRandPos[pos]; return fRandPos[pos];
} }
+3 -2
View File
@@ -2,12 +2,13 @@
* Copyright 2008, Ralf Schülke, [email protected]. All rights reserved. * Copyright 2008, Ralf Schülke, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef PAIRS_VIEW_H #ifndef PAIRS_VIEW_H
#define PAIRS_VIEW_H #define PAIRS_VIEW_H
#include <View.h> #include <View.h>
class TopButton; class TopButton;
class PairsView : public BView { class PairsView : public BView {
@@ -26,7 +27,7 @@ public:
private: private:
void _SetPairsBoard(); void _SetPairsBoard();
void _ReadRandomIcons(); void _ReadRandomIcons();
void _GenarateCardPos(); void _GenerateCardPos();
BMessage* fButtonMessage; BMessage* fButtonMessage;
BBitmap* fCard[8]; BBitmap* fCard[8];
+11 -12
View File
@@ -3,6 +3,8 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "PairsWindow.h"
#include <stdio.h> #include <stdio.h>
#include <Application.h> #include <Application.h>
@@ -14,7 +16,6 @@
#include "Pairs.h" #include "Pairs.h"
#include "PairsGlobal.h" #include "PairsGlobal.h"
#include "PairsWindow.h"
#include "PairsView.h" #include "PairsView.h"
#include "PairsTopButton.h" #include "PairsTopButton.h"
@@ -52,13 +53,13 @@ PairsWindow::MessageReceived(BMessage* message)
switch (message->what) { switch (message->what) {
case kMsgCardButton: case kMsgCardButton:
if (fIsPairsActive) { if (fIsPairsActive) {
fButtonClicks = fButtonClicks + 1; fButtonClicks++;
int32 num; int32 num;
if (message->FindInt32("ButtonNum", &num) < B_OK) if (message->FindInt32("ButtonNum", &num) < B_OK)
break; break;
//look what Icon is behind a button // look what Icon is behind a button
for (int h = 0; h < 16; h++) { for (int h = 0; h < 16; h++) {
if (fPairsView->GetIconFromPos(h) == num) { if (fPairsView->GetIconFromPos(h) == num) {
fPairCard = (h % 8); fPairCard = (h % 8);
@@ -67,7 +68,7 @@ PairsWindow::MessageReceived(BMessage* message)
} }
} }
//gameplay // gameplay
fPairsView->fDeckCard[fButton]->Hide(); fPairsView->fDeckCard[fButton]->Hide();
if (fIsFirstClick) { if (fIsFirstClick) {
@@ -100,7 +101,7 @@ PairsWindow::MessageReceived(BMessage* message)
fPairsView->fDeckCard[fButtonTmp]->Show(); fPairsView->fDeckCard[fButtonTmp]->Show();
} }
//game end and results // game end and results
if (fFinishPairs == 8) { if (fFinishPairs == 8) {
BString strAbout; BString strAbout;
strAbout strAbout
@@ -108,11 +109,11 @@ PairsWindow::MessageReceived(BMessage* message)
<< "\twritten by Ralf Schülke\n" << "\twritten by Ralf Schülke\n"
<< "\tCopyright 2008, Haiku Inc.\n" << "\tCopyright 2008, Haiku Inc.\n"
<< "\n" << "\n"
<< "You completed the game in " << fButtonClicks + 1 << "You completed the game in " << fButtonClicks
<< " clicks.\n"; << " clicks.\n";
BAlert* alert = new BAlert("about", strAbout.String(), "New game", BAlert* alert = new BAlert("about", strAbout.String(),
"Quit game"); "New game", "Quit game");
BTextView* view = alert->TextView(); BTextView* view = alert->TextView();
BFont font; BFont font;
@@ -126,12 +127,12 @@ PairsWindow::MessageReceived(BMessage* message)
view->ResizeToPreferred(); view->ResizeToPreferred();
if (alert->Go() == 0) { if (alert->Go() == 0) {
//New game // New game
fButtonClicks = 0; fButtonClicks = 0;
fFinishPairs = 0; fFinishPairs = 0;
fPairsView->CreateGameBoard(); fPairsView->CreateGameBoard();
} else { } else {
//Quit game // Quit game
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
} }
} }
@@ -142,5 +143,3 @@ PairsWindow::MessageReceived(BMessage* message)
break; break;
} }
} }