Comments (5)
Hi! Thanks so much for reporting this. I'm trying to understand the issue you're raising—I definitely want to fix it if it's a problem, but I'm not sure I get it yet.
You're looking at the code from page 11 of Chapter_10_project.pdf, right? That code definitely works—it's copied and pasted from HouseTests.cs, and I just downloaded and tested that solution, it compiles and all the tests pass. I just checked, and the code is identical. So there doesn't seem to be a syntax error in it. But that doesn't mean there isn't an issue! It might just be that I need to add some notes to the code to explain it a little better, because I could definitely see that it might not be 100% clear at first glance.
The idea with the way that test is structured is that first it's trying to test the layout of the house. It starts with the entry, using House.Entry, and makes sure it's correct by checking its Name. Then it uses the GetExit that Entry inherits because it extends Location—that's how it gets a reference to the hallway location, and it checks its Name property to make sure it has the right location. Then it uses the hallway object's GetExit to get to the kitchen and the bathroom, and tests their names to make sure they're the right object.
The reason it uses House.Entry to get the reference to the first location but uses GetExit to get to the rest of the locations is because it's navigating throughout the layout of the house, the same way the player will later in the project.
Does that help explain what's going on? If that helps, I'll add that to the PDF to help other readers.
If it's still confusing, I'd love to hear your thoughts! I really want to try to make this project as effective as possible. And the nice thing about PDF downloads is that I can update them immediately, so I definitely want to help out here if I can.
from fourth-edition.
from fourth-edition.
I think maybe you're just overthinking it a bit! Here's how this all works.
It all starts with Entry, a readonly field in the static House class:
public static readonly Location Entry;
That field is set in the House constructor:
Entry = new Location("Entry");
And now Entry points to a Location object. The constructor then creates two new Locations objects:
var hallway = new Location("Hallway"); var livingRoom = new Location("Living Room");
And later it uses Entry.AddExit to add them to the Entry location's exit collection:
Entry.AddExit(Direction.East, hallway); Entry.AddExit(Direction.Out, garage);
It's fine to use var for those declarations, because the static House object doesn't need to keep track of them. It just needs to keep track of the one Location reference, Entry, and then it can use its Exits collection to get to them.
The rest of the constructor just uses var
to define variables to reference new locations, because House doesn't need to keep track of any of the other Location objects, either. Any time it needs a Location for a new place in the house, it will look it up in another Location object's Exits collection.
Does that help make sense of it?
from fourth-edition.
from fourth-edition.
I'm glad to help And thanks for explaining what went wrong—that's really useful to me. I'll think about how I might be able to help other readers prevent this in the future.
from fourth-edition.
Related Issues (20)
- Exercise suggestions HOT 4
- Events & Delegates, page 8 typo
- Ch 8 Two Decks Downloadable exercise problem HOT 7
- Chapter 8 Unity Lab : foreach loop HOT 3
- Chapter 9 HOT 1
- typo in Page 22 HOT 1
- Chapter 1 - Matchgame HOT 3
- The east room is repeated. This line should be "the Southwest Room is to the Southwest" instead of "the East Room is to the Southwest"
- Match game can't display emoji HOT 4
- Page 376 second paragraph HOT 1
- Something of note for the next edition HOT 1
- Chapter 9 Long Exercise. HOT 3
- Mac-friendly version of MVVM bonus chapter? HOT 1
- No downloadable source for Blazor version of BeehiveManagementSystem HOT 1
- Unanswered question on p. 324 (main book and Blazor PDF) HOT 1
- Chapter 7 BeehiveManagementSystem download does not integrate all Chapter 7 additions HOT 1
- MatchGame.exe HOT 1
- Events and Delegates, baseball simulator does not print fan and pitcher reactions HOT 1
- MainWindow 'no accessible extension method error HOT 3
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 fourth-edition.