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 piazza. 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 Piazza. Piazza 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.).
A note about submission: We have changed how it expects the files in order to be compatible with github. We're still figuring out the exact file structure it wants. Put your work in the following directory: CS209Homework2. Zip the directory with the files in it.
In this homework, you'll add to the sprite we created.
You should submit several files for this assignment ( Sprite.cs, TestSprite.cs, TestPoint.cs, Point.cs, testsprite.txt, testpoint.txt Makefile). You will submit your work in a zip file to Gradescope.
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: TestSprite.cs Point.cs Sprite.cs mcs TestSprite.cs Sprite.cs Point.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; }
public static void 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.
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
// Display the file contents by using a foreach loop.
// this is just for illustrative and debugging purposes
System.Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
// Use a tab to indent each line of the file.
Console.WriteLine("\t" + line);
}
Here is code to parse a string into different pieces, split by spaces.
string phrase = "The quick brown fox jumps over the lazy dog.";
string[] words = phrase.Split(' ');
foreach (var word in words)
{
System.Console.WriteLine($"<{word}>");
}
Hopefully, you can take those examples and figure out how to divide the
line and feed that data into new sprites.
After changing your Sprite to use Point instead of separate variables for XCoor, YCoor, and ZCoor, you will add inventory functionality to your Sprite class. There will be a full inventory (everything that is in their "backpack") The inventory is stored in name, number pairs. The name is the name of the item and the number is the number of that item they are holding. For example, if they are holding 3 small potions, inventory shows ("SmallPotion",3). as well as 6 quick slots (everything they can use with a single keystroke). The full inventory will be a dictionary, whereas the 6 quick slots will be an array. You need to implement the following functions.