In this assignment you will begin to construct your game following the description that you handed in for the last assignment. You will do this by creating at least 2 new classes that implement two of the interfaces I have provided and modifying one class that I provided you so that it uses those new classes. Exactly what type of classes you create will depend upon the design of your particular game. What you will be constructing now is the beginning of the "static" background that the player plays on. To do this you will write a class that implements the Screen interface and at least one class that implements the Block interface to populate your screens with. Once you have done this, you will edit the appropriate methods in the GameSetup class so that they use these new classes. You will also create a common supertype for your entities and edit a small implementation of a Player. These last two steps are formalities. The main focus of this assignment is on the Screen and the Blocks.
The design for this assignment will should include text descriptions of the classes you add for this assignment, their methods, and what they do in the game.
Again, follow the directions on the general project description for submitting the design.
This assignment will have you writing and editing a fair bit of code. To begin with, we need you to set up some common supertypes for your game. In assignment #1 you made a MainFrame<BasicBlock,BasicEntity>. That is a MainFrame that will work with the types BasicBlock and BasicEntity instead of the more general Block and GameEntity. Your game isn't going to use BasicBlock and BasicEntity. You need to create your own supertypes that are themselves subtypes of Block and GameEntity. You are given code for BasicBlock below that can help guide you for this though most of the code in BasicBlock will not go in the supertype. For example, if you were writing Tetris you could write an abstract class or an interface called TetrisBlock and an interface called TetrisEntity. The entity type needs to be an interface because of some of the details related to the player class you will be using. You could change it to a class later and put common functionality in it. Both should be abstract (remember that interfaces are completely abstract) so they don't have implement every method of the interface they inherit from.
Your block and entity supertypes will have a fundamental value in the project. You can put methods in them that give you critical information about instances of them. For example, in the game of Tetris you need to know if a block on a screen is filled or not. You will have two classes that are subtypes of TetrisBlock, one for and unfilled block and one for a filled block. You could add a method to TetrisBlock named isFilled that tells you if the block is filled or not. the unfilled class will return false while the filed one will return true. A similar situation would arise if you have some blocks that entities can go through and some that they can't.
After you have made your supertypes there are three basic parts to the code for this assignment. First you will write a class that implements the Screen interface. You can call it whatever you want. Something that reflects you or your game followed by Screen would be appropriate. For example, if you were writing a version of Pac-Man you might call it PacManScreen. There are a number of different methods that you have to implement for Screen. Each is described in the Javadocs for the project. Eclipse will put in the methods, but it won't do the generics quite right so you will have to edit those by hand. Your Screen class should implement Screen<MyBlock,MyEntity>, where MyBlock and MyEntity are the typed you created above.
The screen class will require a two dimensional array of Blocks and some form of list of GameEntities. For the list, you should use the GameEntityList class that is in the JAR file to simplify your life. Look in the Javadocs for information on this class and the methods you can call on it. Just put a member of the GameEntityList class in your Screen class. You will write a full list of your own in a later assignment. Unfortunately, doing so will "break" the screens that you create now with the editor so don't spend too much time making elaborate maps at this point. There are two methods that are used by the ScreenEditor that you won't be able to fully implement at this point. You should make getNumEntityTypes return zero and getEntityOfType return null. You will change both of those for assignment #4. It should be noted that getBlock should never return null. Open squares should be denoted with an open block type. A null value will crash the infrastructure.
In order for your Screen class to be useful you also have to create some Block classes to populate it with. Here again I recommend giving them names that reflect both the game and their prupose (i.e. PacManWall or maybe just WallBlock). The Block interface has documentation describing the purpose of each of the methods in it. Some of them you will leave blank or simply have them return null at this point because you can't complete them yet. The documentation gives you hints as to when this is the case. You will also implement any methods that you might have added to your block supertype (like isFilled or isPassable). I'm providing you with one sample Block that you can model yours after. You should probably create your own subclass of your block supertype and then copy methods over from BasicBlock. The Block classes are probably the simplest classes you will write because they don't really do much. The only part of them that is in any way difficult is producing an image for them to draw. We will be talking about that in significant detail later in the semester. For now you can build off of the example that I have given you. (See the links below for the sample code.) You can also load in images from files using the java.imageio.ImageIO class.
After you have a Screen class and a few Block classes, you will need to edit the BasicGameSetup class so that reflects your game and uses what you have written. There are comments in the code pointing you to what types of changes you should make. You should probably create your own subclass of GameSetup and copy the contents across. If you want to test your screen with the ScreenEditor, you can uncomment the code in constructVariables() that calls the readScreenVector(...) method of ScreenEditor. It is a static method. However, for debugging you will want code that directly instantiates a screen and fills it with appropreate blocks for your testing. You might want to keep that code around for testing in assignment #3 as well.
Once your screen and block classes are done and tested, you can use the ScreenEditor that I have written for you to easily build a few screens. I don't recommend that you spend much time on that at this point in the semester because odds are high that you will make changes in the next few weeks that will invalidate any of the files you save now. However, you should play with it a bit just to make sure that you are properly following the interface and that your screen class works with it. For help on how the editor works click the link below.
Help with the screen editor program.
To run the ScreenEditor use the command line and run "java -cp PAD2Assn#.jar:. edu.cs.trinity.gamecore.ScreenEditor MyScreen SavedFile.bin", where # is replaced by a number and MyScreen is the name of your screen class. In windows the : is replaced by a ;. The SavedFile.bin is the name of the file you want it to be saved in. Also, if the JAR file is not in the same directory you are running this in you will need to specify the path. You can also run the screen editor from inside of Eclipse by selecting the main in the ScreenEditor class. You will need to specify the proper command line arguments in the dialog box if you do that.
JAR file for assignment #2.
Source for BasicGameSetup, BasicBlock, and BasicPlayer. GameSetup you should edit. BasicBlock is provided just for your reference. You can take code from it. This is especially for the graphics code in it because we haven't talked about how to write that yet. You can either put the BasicBlock class in your project and rename it, or you can copy the code from it into your own class.