Changes between Version 5 and Version 6 of ControlSystems/SoftwareTeam/Training/VirtualTraining/JuniorRobot
- Timestamp:
- Aug 31, 2020, 11:51:31 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/VirtualTraining/JuniorRobot
v5 v6 37 37 38 38 === Classes === 39 We're going to cover classes in much more detail later, but most things in Java programs are either a class or a part of a class. When you create a type of robot, you create a class and give it a name (e.g. !RoboJojo). That class can be based on (extend) another class (e.g. !JuniorRobot). You must indicate whether your class can be imported and used in other packages (e.g. is public). Finally, everything you want to be in your class isplaced inside a pair of curly braces: { }39 We're going to cover classes in much more detail later, but most things in Java programs are either a class or a part of a class. When you define a new type of robot, you create a class and give it a name (e.g. !RoboJojo). That class can be based on (extend) another class (e.g. !JuniorRobot). When a class is based on another class, it inherits all of the behaviors and attributes of that class and extends them with new behaviors and attributes. You must indicate whether your class can be imported and used in other packages (e.g. is public). Finally, everything that is part of your class must be placed inside a pair of curly braces: { } 40 40 41 41 {{{ … … 43 43 { 44 44 }}} 45 46 You can read more about Java classes [https://www.tutorialspoint.com/java/java_object_classes.htm here] 45 47 46 48 === Methods === … … 64 66 }}} 65 67 68 You can read more about Java methods [https://www.tutorialspoint.com/java/java_methods.htm here] 69 66 70 === Loops === 67 71 One of the nice things about programs is that they can do things repetitively without you having to write the same instructions (methods) over and over. Once your robocode robot starts running in the battle arena, you want it to keep running until the battle is over so it should continue doing its behaviors indefinitely. In Java, one of the repetition methods is '''while''' which will repeatedly execute some set of methods (specified inside the curly braces) until some condition (specified inside the parentheses) is false. Since we want the robot to keep doing its thing indefinitely, we use the while(true) syntax which will repeat forever. In this case, the robot moves forward 100 spaces, turns in a full circle, then moves back 100 spaces and turns in a full circle. It will keep doing this forever. … … 76 80 } 77 81 }}} 82 83 You can read more about Java while loops [https://www.tutorialspoint.com/java/java_while_loop.htm here] 78 84 79 85 === Observers === … … 111 117 }}} 112 118 119 You can read more about Java Observers [https://www.baeldung.com/java-observer-pattern here] 120 113 121 == Exercises == 114 122 1. Run !RoboJojo again and observe how the behaviors of the robot relate to the methods.