Comments (1)
Hi Alan
Sorry for the delay in getting back to you!
I'm sure that you've probably either solved this by now or moved on to a different solution, but I'll answer the question anyway!
If I'm honest, I'm not sure exactly what the issue is with the code that you had at this point. I can give you some general advice on this type of issue though.
In a game, you often have some sort of state that you want to 'reset' back to how it was when you started. The thing that can catch you out is that something isn't exactly as it was in the beginning after the reset. Like you were experiencing here, you then have to try and track down which of the things you wanted to reset that is out of place, which can be a pain.
One trick to avoiding that problem is to put everything that needs to be reset under a single object that you can deallocate a reallocate. For instance, rather than having three variables that you need to reset back to their original positions, have one object that holds the three variables and then just create a brand new instance of that object. This way you know that everything is exactly how it was when you originally started.
One solution to this particular problem is to just reallocate the view controller, as this is the parent of the all of the properties that you need to reset. You might need to then put it in a parent view controller so that you have a persistent view on screen when you recreate it. That might not give you the right experience that you're looking for, but hopefully gives you the idea about how you might solve such an issue. If you want to get around that then you might be able to refactor the example implementation so that all of the state is kept under a child object that you can recreate within the view controller.
There are of course other approaches to solving these sorts of problems, but hopefully that at least points you in the right direction!
from swiftchess.
Related Issues (17)
- Images for readme
- How can I implement undo function? HOT 2
- [Feature Request] Use K/k for king and N/n for knight. HOT 6
- Levels HOT 2
- Multi player HOT 1
- Timer HOT 2
- App is crashing when I navigate back to MenuViewController. HOT 1
- [Request] Add Castling HOT 1
- undo options HOT 3
- PGN Parser HOT 1
- Some time moves not working. HOT 1
- add legal moves? HOT 2
- How strong the engine is? HOT 1
- Locking mechanism for resources
- Can you build a Korean chess engine?
- The code doesn't work. Please see the log below. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftchess.