You are expected to complete this assignment individually. If you need help, you are invited to come to office hours and/or ask questions on Ed. Clarification questions about the assignments may be asked publicly. Once you have specific bugs related to your code, make the posts private.
Another note about Ed. Ed is your community resource - please use those as discussions amongst yourselves. We are not monitoring it all day, rather we each have check-in times once a day. Therefore, you need to start early enough to wait for feedback and/or build a vibrant, supportive community that helps each other while we are completing other necessary tasks (research, developing assignments, preparing for lecture, performing advising tasks, etc.).
In this homework, you'll create what we a sprite - a moveable object in a game. This sprite has specific elements of state. You will then write functions that modify the state based on actions in the game.
You should submit several files for this assignment (Lab1SampleFunctions.cs, Puppy.cs, TestLab1.cs, testlab1.txt, Sprite.cs, TestSprite.cs, testsprite.txt, Makefile). You will submit your work in a zip file to Gradescope. More detailed submission instructions will come later.
Error handling capabilities vary by language, and what you want to do in an error varies by the situation. When an error occurs in a function, the question becomes, what should you do, and how do you notify the caller that an error occurred?
In C#, there is a construct for this. We'll use this when calling functions that use it but, right now, we won't implement them ourselves. This is an exercise because if you write a function, and it's used in a variety of different circumstances, it is bad programming practice to determine within the function what will be done. For example, one program might want to exit, whereas another might want to notify the user that there was bad input and to try again.
In this course, we will print the error message in a special way (see below). If there is an opportunity, we will designate a specific return value for an error condition. If there is no available return value, then we will exit from within the function.
Console.WriteLine("error: too many widgets for the number of grommets"); Console.WriteLine("error: need ten boondoggles, but only have "+ num_bds);
Sometimes, these lines will be followed by exit(1); This immediately exits the program and returns a code. If you were writing a large program, you might assign a different code to each type of error that would result in an exit.
TestSprite.exe: Sprite.cs TestSprite.cs mcs TestSprite.cs Sprite.csTo compile, type:
make TestSprite.exe
public float surface_area_cylinder(float height, float radius) { Console.WriteLine("surface_area_cylinder not yet implemented"); return 0.0; }
int Main(string[] args) { float fval; LabXMethods lxm = new LabXMethods(); fval = lxm.surface_area_cylinder(3.5, 7.9); }
First get this compiling and running. It won't do anything useful, but this will mean that your code will compile and execute with our infrastructure. This must work in order to get any points in this course. Do this first, not last.
The Sprite class holds all information necessary to display a Sprite in a game. This may be set up slightly differently within Unity, which we will learn later, but we're making a generic class that could be the starting point for any game system. As our working example, we will use the players in Fortnite.
When we design a class, we split it up into two parts. First, what is the information we need to track at any moment in time? Second, what actions occur that change that information?
When we think of a character in a game, there are several attributes to keep track of. We need the character's location (x, y, z coordinates), direction they are pointing (of 360 degrees), their health points (out of 100) and, in the case of Fortnite, their shield points (out of 100). Of course, Fortnite has many more than that - the character's "skin" (the look), the items they currently possess, the item they currently hold. whether they are doing an emote, whether they are flying, etc. For this assignment, we will focus on location, health, and shield.
The next step is to identify the actions that affect location, health, and shield.
If a person's health gets to 0, regardless of the state of the shield, the person is dead. Some actions affect the shield before the health, but others operate directly on the health.
We must not forget to decide the starting state of the sprite. This is performed in the constructor
public Sprite()Finally, we think about what methods would be useful for testing. For testing, we will provide a function that sets the state to whatever we want it to be.