Ashley Bye wrote:can I use assertThat for an equals, i.e. `assertThat((numberOfItems == 2), is(true))`?
Player moves into Space. The PLAYER (the person playing the game) is informed of the options available to the Player. PLAYER chooses an option to for the next Player action - say "press T to pick up Treasure". Player is sent message to pickupTreasure: player.pickupTreasure().
Tell Space to collect treasure. Space will give back a collection of treasures. If Space has 2 treasures in it, then the collection it gives back will include those 2 treasures
If Space has two treasures and the Player occupying it is told to collect any treasures available, then the Player should end up with two treasures collected and there will be no more available treasures in the Space.
Wait a minute! Before we follow this line of thought into the deep end, let's consider backing up a bit. How about we work on World, Player, Spaces, and getting the player to move around a bit? This way, we have the most basic functionality of the game done and we could use it to help us work out details for interactions with things that are in the Spaces as the Player moves around in the World.
Wouldn't it be a great first step to see that the Player can actually move around in the World of Spaces, even if the Spaces are all empty?
I don't know if it would work. Best way to answer that is to write some tests and code, then read it to see if it makes sense. My gut says that having a Space "observe a Player" is not going to make a lot of sense to a reader of the code. However, making the Player aware of the current Space he's occupying seems to make sense. I can relate to that thought, the same way I can relate to the similar thought that "When I enter a room, I am aware of things that are in the room." I can't really relate to "When I enter a room, the room tells me what things are in it."
Ashley Bye wrote:I was thinking about making the spaces an observer of player, then whenever a player method moveInto(space) is run, the space with that ID knows to tell the player there is treasure, enemy etc. I'm not sure if this would work because the player would then need to tell the player to pick up the treasure and to fight an enemy.
Also, would that mean needing to load all the spaces from the outset of the game? Not really an issue with it this size, but if it was a massive game with graphics etc, I can foresee it would have memory issues.
Ashley Bye wrote:Question: how much of a program should be written before TDD begins in ernest? According to the information I have read the first thing written should be a test, but that means writing tests for constructors, setters, etc and taking a long time to getting round to the basic functionality which is where I see TDD then starting to be beneficial.
You mentioned before that you thought there was a better way of organising my spaces in the world without each space knowing what spaces were adjacent to it and what were valid moves. I've hit a stump when it comes to figuring out how to do that. Surely a space needs to know which ones are next to it otherwise it could just load any old space? Other than an array of spaces by ID and valid moves in the space object, how would you tackle the problem?
N Sam wrote:Great job Ashley. As a beginner, i am more than impressed with your first java program. I would like to go through this thread more closely, to see the feedback from the master to the student. As far as i see, the source has evolved as follows (in GIT):
1. DragonSlayer -> nbproject
2. DragonSlayer -> src
3. DragonSlayer2 -> src
Is this correct order of src ? It would be hard to associate the feedback without seeing the intermediate evolutions of the first draft.
OOps. I just now took a closer look at DragonSlayer ->nbproject and there is only .xml and .properties files in here. Are you using Netbeans as your IDE ? (perhaps the .xml files are IDE stuff ?) Obviously the initial source is in DragonSlayer->src (perhaps with some modifications of original draft). BTW, can you describe your thinking process, when you took upon this project ? How did you translate the objective of the game and rules of game into the initial draft of code and classes ? You seem to be a very good programmer, and perhaps i can learn something from you.
Ashley Bye wrote:I now have a basic level of the game setup. The way the player is controlled definitely needs some work but it gets me moving throughout the world and makes sure I can access the spaces. I now need to find a way to ask the world for what spaces are available for moving into.
Code as follows:
The DragonSlayer WORLD is a grid of SPACES. The grid is rectangular, with a fixed width and fixed height that can be configured at the start of the game. One SPACE occupies one unit of height and one unit of width on the grid. Each SPACE on the grid can be referenced by its coordinates, starting from (0, 0) being at the Southwest (bottom left) corner up to (WorldWidth - 1, WorldHeight - 1) being at the Northeast (top right) corner of the grid
Ashley Bye wrote:I also think findSpaces could probably be renamed getNeighboursOfSpace(Space space), which means the test name would be getNeighboursOfSpace_returns_2_for_space_at_position_0_0(). What do you think?
I have heard of the Stroop Test but only about colours and the written colour names. I hand't considered how it could be transferred across to programming and probably many other areas of life too. I will definitely strive harder to come up with good names that actually mean what I want the program to do.
Regarding the World constructor we have in the above post, what are the values of int x and in y supposed to do? What is the constructor going to do? Where are we going to get the spaces from? Do we have a data layer that the World constructor needs to access to get this information? How will it know what spaces to put in the world and where will it know to put them?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton