-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSaveAction.cpp
More file actions
55 lines (47 loc) · 1.42 KB
/
SaveAction.cpp
File metadata and controls
55 lines (47 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "SaveAction.h"
#include "Input.h"
#include "Output.h"
#include "Grid.h"
#include "Ladder.h"
#include "Snake.h"
#include "Card.h"
SaveAction::SaveAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
bool SaveAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Read the startPos parameter
pOut->PrintMessage("Save Grid: Enter The Name of The File ...");
filename = pIn->GetSrting(pOut);
if (filename == "") return false;
// Clear messages
pOut->ClearStatusBar();
return true;
}
void SaveAction::Execute()
{
Grid* pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
if (!ReadActionParameters())
{
pGrid->PrintErrorMessage("Error: Invalid File Name ! Click to continue ...");
return;
}
save.open("SavedGrids/" + filename + ".txt");
save << Ladder::Getnumofladders() << "\n";
pGrid->SaveAll(save, Ladders);
save << Snake::GetNumberOfSnakes() << "\n";
pGrid->SaveAll(save, Snakes);
save << Card::GetNumberOfCards() << "\n";
pGrid->SaveAll(save, Cards);
save.close();
}
SaveAction::~SaveAction()
{
}