Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: humdinger <[email protected]>
  • Loading branch information
dospuntos and humdingerb authored Mar 31, 2024
1 parent ff69380 commit 24b50bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Game::MessageReceived(BMessage *message)
case H2048_SAVE_GAME:
{
BRect frame;
message->FindRect("frame",&frame);
message->FindRect("frame", &frame);
save(frame);
break;
}
Expand Down Expand Up @@ -475,38 +475,38 @@ Game::undoMove()
status_t
Game::save(BRect frame)
{
BFile saveFile(fSaveFile_path,B_WRITE_ONLY | B_CREATE_FILE);
BFile saveFile(fSaveFile_path, B_WRITE_ONLY | B_CREATE_FILE);

BMessage saveMessage(H2048_SAVE_MESSAGE);

for(int i =0;i<fSizeX*fSizeY;i++){
saveMessage.AddUInt32("board",fBoard[i]);
for (int i = 0; i < fSizeX * fSizeY; i++) {
saveMessage.AddUInt32("board", fBoard[i]);
saveMessage.AddUInt32("previousBoard", fPreviousBoard[i]);
}

saveMessage.AddUInt32("score",fScore);
saveMessage.AddUInt32("previousScore",fPreviousScore);
saveMessage.AddUInt32("score", fScore);
saveMessage.AddUInt32("previousScore", fPreviousScore);

saveMessage.AddBool("canUndo",fCanUndo);
saveMessage.AddRect("windowFrame",frame);
saveMessage.AddBool("canUndo", fCanUndo);
saveMessage.AddRect("windowFrame", frame);

return saveMessage.Flatten(&saveFile);
}

bool
Game::load()
{
BFile saveFile(fSaveFile_path,B_READ_ONLY);
BFile saveFile(fSaveFile_path, B_READ_ONLY);

BMessage saveMessage(H2048_SAVE_MESSAGE);
status_t result = saveMessage.Unflatten(&saveFile);
if(result!= B_OK) {
if (result != B_OK)
return false;
}

bool loadOK = true;

for(int i =0;i<fSizeX*fSizeY;i++) {
for (int i = 0; i < fSizeX * fSizeY; i++) {
loadOK = loadOK && saveMessage.FindUInt32("board",i,&fBoard[i]) == B_OK;
loadOK = loadOK && saveMessage.FindUInt32("previousBoard",i,&fPreviousBoard[i]) == B_OK;
}
Expand Down
6 changes: 3 additions & 3 deletions WindowBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GameWindow::QuitRequested()
{
BMessenger game(NULL, fMaster->fTarget);
BMessage saveMessage(H2048_SAVE_GAME);
saveMessage.AddRect("frame",Frame());
saveMessage.AddRect("frame", Frame());
game.SendMessage(&saveMessage);
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
return true;
Expand All @@ -140,11 +140,11 @@ GameWindow::MessageReceived(BMessage *message)
case H2048_SET_FRAME:
{
BRect frame;
message->FindRect("frame",&frame);
message->FindRect("frame", &frame);
MoveTo(frame.LeftTop());
prevWidth = (int)frame.Width();
prevHeight = (int)frame.Height();
ResizeTo((int)frame.Width(),(int)frame.Height());
ResizeTo((int)frame.Width(), (int)frame.Height());
break;
}
case H2048_UNDO_MOVE:
Expand Down

0 comments on commit 24b50bb

Please sign in to comment.