CPSC 215 Lab 6 and Reading Week Project: TANKS! (Due Thursday during reading week) Download the tanks.java program from the class webpage. This program creates a 500X400 pixel applet (also get tanks.html) in which two tanks, tank 0 (black turret) and tank 1 (blue turret) fights to destroy eachother. Also download the gif image "skull9.gif" which is used to display a skeleton when a target is destroyed. You are to find a competing team, and modify the tank1 (black) and tank2 (blue) classes at the very end of the file. These are the ONLY classes you can modify. The "manuver" method determines the algorithm your tank follows. I'm assuming you were in class when I gave the demonstration. Here are the methods and variables you can access in your tank subclass: ID : an integer identifying yourself (0 - black, 1 - blue); xcord() : method that returns your x coordinate ycord() : method that returns your y coordinate These methods ensure you can't change your position arbitrarily gunposition : Position of your high-velocity anti-tank laser cannon, expressed in degrees. 0 is down, 90 is right, etc... The initial angle is set to 90; A.Targ[0], A.Targ[1]: two targets (see class target) with information you can use concerning the other tank. If T is a target object, then T.ID is ID of target (remember one of these is you!) T.xpos is x coordinate of target T.ypos is y coordinate of target T.gunposition is gunposition of target relative to THAT target, not you T.destroyed is true if target has been destroyed. move(dir) : move in direction dir, where dir can be north, east south, or west. These are actually integers 0-3. any other value will have no effect. You move 4 pixels each time. rotateTurret(dir) : rotates turret, dir can be left (1) or right (-1). You rotate the gun by 2 degrees each time. inrange(t) : t is a target object; method will return true if tank is within range of your cannon (200 pixels). insight(t) : t is a target object; method will return true if t is within range AND aligned with your cannon. target_insight(): true if there's a target in sight that's not yourself. Since I'm restricting the program to two tanks, this is the same as "insight" except no argument is needed. fire() : Fires your cannon. This will have no effect if if target_insight() is false. Be warned that very occassionally your shots may "glance off". Also, sometimes your tank reacts too slowly, and may miss an opportunity to fire, depending on your program and what the operating system is doing at the time. This makes things more fun. distanceTo(x,y) : returns distance in pixels to coordinate x,y. Your position is the center point of your tank turret. In addition, you should know about the Java's Math functions: Math.sin(r), (and cos, tan) takes radians as their arguments, not degrees, but I used degrees because I think they're easier for humans. Math.atan(x) (and asin, acos) return radians as values. Given your "gunposition" in degrees: double gundr = gunposition * 0.01745; // converts it to radians and int gx = xpos + ((int) (25.0 * Math.sin(gundr))); int gy = ypos + ((int) (25.0 * Math.cos(gundr))); will calculate the x,y coordinates of the *tip* of your cannon. (25.0 is the length of the cannon from its tip to the center of turret). You may also call gunslope() to return the slope of your gun if you want to compute line of fire. I'm not exactly sure if this will be really useful, however. I have several references on java library functions, and I'd be glad to make them available to you. * * * * * * * * I have tried to make sure you can't cheat by changing variables you're not supposed to change, but I might have left some loopholes. If you use them, you will get credit for the assignment but you will be disqualified from winning the contest. First defeat the random tank before competing with another team. The assignment will be graded as a regular lab, but those who do well in the contest will receive extra credit. Please be aware that this program was written in a very short ammount of time and may have bugs. If unexpected things happen (e.g, tank fires backwards) please let me know and I'll correct the problem. If the program suddenly halts in the middle, just quit and start it up again. Also use Java 1.1 instead of 1.2 - I have not tested it with 1.2. I may be posting updates to the program, so PLEASE check the class webpage often. Also check your email regularly for updates from the TAs. Contest is next Thursday, regular lab time (attendance required unless you have prior permission).