Remove unneeded block place parameters + refactor
This commit is contained in:
parent
74c2eb03e6
commit
f1592d88fa
2 changed files with 44 additions and 35 deletions
|
@ -53,9 +53,9 @@ struct Block {
|
|||
void undo(deque<int> &prev);
|
||||
};
|
||||
|
||||
void update(int &time, deque<int> &turn, Block* root, Rectangle &dst);
|
||||
void undo(Block *root, deque<int> &prev, Rectangle &dst, int &time);
|
||||
bool valid(Block* root, Rectangle &dst, deque<int> &turn);
|
||||
void update(Block* root, int time, deque<int> &turn);
|
||||
void undo(Block *root, deque<int> &prev, int time);
|
||||
bool valid(Block* root, Rectangle play_area, deque<int> &turn);
|
||||
|
||||
class Renderer {
|
||||
array<Texture2D, IMG_COUNT> textures;
|
||||
|
|
|
@ -23,14 +23,14 @@ deque<int> to_deque(Vector2 v, int depth, int size) {
|
|||
}
|
||||
|
||||
|
||||
void save_state(Block* root, int depth, int time, deque<int> &turn) {
|
||||
void save_state(Block* root, int time, deque<int> &turn) {
|
||||
vector<tile> state = {};
|
||||
root->save(&state);
|
||||
|
||||
string filename; std::cin >> filename;
|
||||
std::ofstream outfile("saves/" + filename);
|
||||
|
||||
outfile << depth << "\n" << time << "\n" << turn.size() << "\n";
|
||||
outfile << root->depth << "\n" << time << "\n" << turn.size() << "\n";
|
||||
|
||||
// Save turns
|
||||
for(int play : turn)
|
||||
|
@ -40,48 +40,57 @@ void save_state(Block* root, int depth, int time, deque<int> &turn) {
|
|||
for(tile t : state)
|
||||
outfile << int(t) << std::endl;
|
||||
}
|
||||
void load_state(Block** root, deque<int> &turn, int &depth, int &time, char* argv) {
|
||||
depth = atoi(argv);
|
||||
if(depth)
|
||||
void load_state(Block** root, deque<int> &turn, int &time, char* argv) {
|
||||
int depth = atoi(argv);
|
||||
if(depth) {
|
||||
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||
else {
|
||||
string path = "saves/" + string(argv);
|
||||
std::ifstream infile(path);
|
||||
infile >> depth >> time;
|
||||
int K; infile >> K;
|
||||
for(int k = 0; k < K; k++) {
|
||||
int play; infile >> play;
|
||||
turn.push_back(play);
|
||||
cout << play;
|
||||
}
|
||||
vector<tile> state = {};
|
||||
long long pw = 1;
|
||||
for(int i = 0; i < depth; i++) pw *= 9;
|
||||
for(int i = 0; i < pw; i++) {
|
||||
int next; infile >> next;
|
||||
state.push_back((tile)next);
|
||||
}
|
||||
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||
(*root)->load_state(state, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load file
|
||||
string path = "saves/" + string(argv);
|
||||
std::ifstream infile(path);
|
||||
infile >> depth >> time;
|
||||
|
||||
// Load turns
|
||||
int K; infile >> K;
|
||||
for(int k = 0; k < K; k++) {
|
||||
int play; infile >> play;
|
||||
turn.push_back(play);
|
||||
cout << play;
|
||||
}
|
||||
|
||||
// Load board
|
||||
vector<tile> state = {};
|
||||
|
||||
long long pw = 1;
|
||||
for(int i = 0; i < depth; i++)
|
||||
pw *= 9;
|
||||
|
||||
for(int i = 0; i < pw; i++) {
|
||||
int next; infile >> next;
|
||||
state.push_back((tile)next);
|
||||
}
|
||||
|
||||
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||
(*root)->load_state(state, 0);
|
||||
}
|
||||
|
||||
void update(int &time, deque<int> &turn, Block* root, Rectangle &dst) {
|
||||
void update(Block *root, int time, deque<int> &turn) {
|
||||
time++;
|
||||
turn.erase(turn.begin());
|
||||
int rval_2 = root->play(turn, pas(time));
|
||||
for(int i = 0; i <= rval_2; i++)
|
||||
turn.pop_back();
|
||||
dst = root->getRect(turn);
|
||||
}
|
||||
void undo(Block *root, deque<int> &prev, Rectangle &dst, int &time) {
|
||||
void undo(Block *root, deque<int> &prev, int time) {
|
||||
if(prev.size() == 0) return;
|
||||
time--;
|
||||
root->undo(prev);
|
||||
// TODO
|
||||
}
|
||||
bool valid(Block* root, Rectangle &dst, deque<int> &turn) {
|
||||
return CheckCollisionRecs(root->getRect(turn), dst) && root->playable(turn);
|
||||
bool valid(Block *root, Rectangle play_area, deque<int> &turn) {
|
||||
return CheckCollisionRecs(root->getRect(turn), play_area) && root->playable(turn);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,7 +104,7 @@ int main(int argc, char** argv) {
|
|||
root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||
}
|
||||
else
|
||||
load_state(&root, turn, depth, time, argv[1]);
|
||||
load_state(&root, turn, time, argv[1]);
|
||||
|
||||
Rectangle play_area = root->getRect(turn);
|
||||
|
||||
|
@ -124,7 +133,7 @@ int main(int argc, char** argv) {
|
|||
end = true;
|
||||
break;
|
||||
case OKAY:
|
||||
update(time, turn, root, play_area);
|
||||
update(root, time, turn);
|
||||
pturn = turn;
|
||||
break;
|
||||
}
|
||||
|
@ -132,7 +141,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
// Key presses
|
||||
if(IsKeyPressed(KEY_X))
|
||||
save_state(root, depth, time, turn), end = true;
|
||||
save_state(root, time, turn), end = true;
|
||||
else if(IsKeyPressed(KEY_Z))
|
||||
{} // TODO undo
|
||||
|
||||
|
|
Loading…
Reference in a new issue