-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveGrid.cpp
48 lines (36 loc) · 1.04 KB
/
SaveGrid.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
#include "SaveGrid.h"
#include "Grid.h"
#include "Input.h"
#include "Output.h"
#include <fstream>
SaveGrid::SaveGrid(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
SaveGrid::~SaveGrid()
{
}
void SaveGrid::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut ->PrintMessage("Name the file to save: ");
FileName = pIn ->GetSrting(pOut);
pOut ->ClearStatusBar();
}
void SaveGrid::Execute()
{
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
ofstream OutFile(FileName + ".txt");
OutFile << pGrid->GetNumberOfGameObject(LADDERS) << std::endl;
pGrid->SaveAll(OutFile, LADDERS);
OutFile << pGrid->GetNumberOfGameObject(SNAKES) << std::endl;
pGrid->SaveAll(OutFile, SNAKES);
OutFile << pGrid->GetNumberOfGameObject(COINSETS) << std::endl;
pGrid->SaveAll(OutFile, COINSETS);
OutFile << pGrid->GetNumberOfGameObject(CARDS) << std::endl;
pGrid->SaveAll(OutFile, CARDS);
OutFile.close();
}