![]() ![]() Geometryx is a simple calculator using trigonometric functions, Pythagorean theorem and Thales' theorem. The application calculates an area, perimeter, circumference, diagonal length, volume, coordinates of the geometric centroid, height, side lenght, angle (acute, right, obtuse, straight, reflex), radius (inner, outer), edges, arc length, line segments, base area, lateral surface area and total surface area of three-dimensional geometric shapes. While yes Fire() is related to a ship object, but if you think about the physical battleship board game, the ship really isn't the one doing the firing action (the player does).Īnd take all this just as pointers, it will become more clear as you get more experience with it and see more existing code.Geometryx is an application that allows you to calculate quickly and easily the most important values and parameters of plane and solid figures and shapes. Methods that are just related to the object is too broad, methods represent what an object does, or has done to it.Ī good example of this is the Ship class and the Fire() method. cs Class file will generally have a constructor, Variables (for object state), and Methods (for object behavior). (for example about half of MapLocation should be in a new Map class) Yes a. The data model being a little lacking is causing you to have to resort to a procedural thinking for some of the concepts. This is especially important when you are working with a team and other people will be developing on the same project. Like i said it is ok here on this small app but when you get to more complex applications you could have a ton of custom exceptions and if they were all on one file and you could have to scroll through hundreds of lines of code to find what you are looking for. This would be better in two separate files (BattleshipException.cs and OutOfBoundsException.cs) with those files inside a folder called 'Exceptions'. But the only file you have with multiple classes is the Exception.cs. It should have stuff like Players (also another object id suggest), a Map (same thing here), etc. Have your Game.cs/class as the engine of the game. ![]() Look at what is in your Main() method as a large group of properties and methods that need to be sorted into categories. ![]() Create a Program.cs that contains only the Program class and Main() method. I would start with dealing with the structure fist. use names like 'isTouching' only for boolean values (this is actually used as a bool later in the code just with 1 and 2 instead of true and false).That way it will read a little better when dealing with the Ship Object. when creating a ship instead of copying the values from the MapLocation object, just store the whole MapLocation as a custom field.It could use a couple more classes to encapsulate most of whats is going on int the Main() method.While they are small classes and it would be fine in this instance, but its best practice for larger projects Grouping the custom exceptions together should be done with a folder. one class per file *Note this is a general rule so it does have its exceptions.The Objects you have are modeled well and encapsulate the functionality pretty well. ![]() I am sorry to hear that and wish you a speedy recovery! Life > code hahaĪnyway as for the code, this is definitely heading in the right direction. Console.ReadLine() should wait for input anyway so they may not be needed. Lastly, 'while(true)' is valid but bad form, you will be able to find better ways to control the logic flow (ones that don't have inherent risks of an infinite loop : ) ). Try creating classes that model objects using the properties as the dimensions and the methods to do all the computations. Try to think about the objects involved, namely triangles, circles, and rectangles (being squares are rectangles you can use some inheritance magic here). Secondly, this is a very procedural approach, the classes you have are static helper classes that handle the computations and the main method handles the interaction with the user. if there is more than trivial logic it should be in its own method at the very least (better if its in another class I dont like having other methods on the Main.cs to keep the whole file as minimal as possible). Now I am not sure what the instructions for the calculator are specifically but i have a few pointers just based on what you have.įirst, try to keep you Main() method to a minimum. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |