-
Notifications
You must be signed in to change notification settings - Fork 2
/
SaveGridAction.cpp
55 lines (40 loc) · 1.13 KB
/
SaveGridAction.cpp
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 "SaveGridAction.h"
SaveGridAction::SaveGridAction(ApplicationManager* pApp) : Action(pApp)
{
}
void SaveGridAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Get the name of the file to be saved
pOut->PrintMessage("Please, Enter the File Name: ");
this->Fname = pIn->GetSrting(pOut) + ".txt";
}
void SaveGridAction::Execute()
{
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
this->ReadActionParameters();
// Create a file with entered name
ofstream fout(this->Fname);
if (fout.is_open())
{
// Save ladders
fout << pGrid->GetLaddersCount() << "\n";
pGrid->SaveAll(fout, TypeLadder);
// Save Snakes
fout << pGrid->GetSnakesCount() << "\n";
pGrid->SaveAll(fout, TypeSnake);
// Save Cards
fout << pGrid->GetCardsCount() << "\n";
pGrid->SaveAll(fout, TypeCard);
// Close the file
fout.close();
}
pOut->PrintMessage("Grid is Saved to " + Fname + " Successfully!");
}
SaveGridAction::~SaveGridAction()
{
}