-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (53 loc) · 2.28 KB
/
Copy pathmain.cpp
File metadata and controls
68 lines (53 loc) · 2.28 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
56
57
58
59
60
61
62
63
64
65
66
67
68
// Charlie Conner & Brett Abitante
// 2450953 & 2443690
// chconner@chapman.edu & abitante@chapman.edu
// CPSC-350-01
// Assignment 2: Not So Super Mario Bros.
#include "FileProcessor.h"
#include "World.h"
#include "Logger.h"
#include <iostream>
#include <stdexcept>
#include <ctime> // Include ctime for time()
int main(int argc, char* argv[]) {
if (argc != 3) { // Check if the correct number of arguments is provided
std::cerr << "Usage: " << argv[0] << " <input_file> <log_file>" << std::endl;
return 1;
}
std::string inputFileName = argv[1];
std::string logFileName = argv[2];
/*"""BEGIN CODE FROM CHAT GPT, PROMPT ASKED: how do I seed my random number generator in c++?*/
srand(static_cast<unsigned int>(time(0)));
/*"""END OF CODE FROM CHAT GPT"""*/
// Seed the random number generator with the current tim
try {
// Create and process the input file using FileProcessor
FileProcessor fileProcessor;
fileProcessor.processFile(inputFileName);
// Create the Logger object to record game events
Logger logger(logFileName);
// Create the World object using 8 parameters, including the percentage of empty spaces
World world(fileProcessor.getNumOfLevels(),
fileProcessor.getGridDimension(),
fileProcessor.getNumOfInitialLives(),
fileProcessor.getPercentageCoins(),
fileProcessor.getPercentageEmpty(),
fileProcessor.getPercentageGoombas(),
fileProcessor.getPercentageKoopas(),
fileProcessor.getPercentageMushrooms());
// Initialize the game world
world.initialize();
// Log the initial state of the world
world.logState(logger);
// Main game loop: Update game state until the game is over
while (world.updateGameState(logger)) {
world.printWorldState(logger); // Print the state of the world to the log file
}
std::cout << "Game over!" << std::endl; // Print message when the game ends
}
catch (const std::exception &e) { // Catch and handle any exceptions
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0; // Exit the program successfully
}