-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveGridAction.cpp
More file actions
54 lines (43 loc) · 1.4 KB
/
Copy pathSaveGridAction.cpp
File metadata and controls
54 lines (43 loc) · 1.4 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
#include "SaveGridAction.h"
#include "Input.h"
#include "Output.h"
#include "Grid.h"
#include <fstream>
SaveGridAction::SaveGridAction(ApplicationManager* pApp) :Action(pApp) {
}
SaveGridAction::~SaveGridAction() {
}
void SaveGridAction::ReadActionParameters() {
//get a pointer to the grid, input and output
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
//get the name of the file from the user
pOut->PrintMessage("Enter the name of the file to save");
this->fname = pIn->GetString(pOut);
//then clear the status bar
pOut->ClearStatusBar();
}
void SaveGridAction::Execute() {
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
this->fname += ".txt";
int ladderNum = pGrid->ladderCount(); //total number of ladders
int snakeNum = pGrid->snakeCount();//total numebr of snakes
int cardNum = pGrid->cardCount(); //total number of cards
int coinNum = pGrid->coinCount();
//this is the stream for reading and writing to files
std::ofstream outputFile(this->fname, ios::out);
outputFile << ladderNum << std::endl;
pGrid->Save(outputFile, 1);
outputFile << snakeNum << std::endl;
pGrid->Save(outputFile, 2);
outputFile << cardNum << std::endl;
pGrid->Save(outputFile, 3);
outputFile << coinNum << std::endl;
pGrid->Save(outputFile, 4);
outputFile.close();
}
//Mohamed Shams