Document Sample
JAVA PROGRAMMING(1) Powered By Docstoc
Final Report

Submitted to The Faculty of Operation Catapult LXXVI Rose-Hulman Institute of Technology Terre Haute, Indiana

by Group 23 Will Atherton David Yeung South Brunswick High School Kendall Park, New Jersey Waterford High School Waterford, Connecticut July 29, 2004

23-1 Introduction Computers were created by man. Computers were created by man to help accomplish tasks that would normally be impossible for man alone. This is why computers have become part of our regular everyday lives. Computers have enabled people to write messages in virtual letters and send them to their destination in the blink of an eye. Computers have allowed real time talking between two individuals from different countries. Computers have literally let us nobly gone where no man has ever dreamed of going before. Computers also can calculate numbers that would normally take a person minutes, hours, even days to solve. Computers can also simplify tasks by reducing the time it takes to complete it. There are rarely any houses today that do not utilize the advantages of a computer. Today, computers are used for more recreational purposes. Programmers and engineers alike are finding new ways to use computers to add more fun to the regular world. From roller coasters to video games, from laser light shows to learner programs, computers have become one of the main tools for fun. Disney’s Imagineers make frequent use of computers to build more and more original rides that will captivate large audiences. Programmers make the popular network games like ‘Runescape’ and ‘Soldat’ to attract the young audience. Small and large animated movies are made on the computer. One can buy anything on the computer. One can make almost anything on the computer. The computer is extremely versatile as far as abilities go. This year, we are making a futuristic version of Capture the Flag. The extensions to computers are the numerous programs that allow the user to perform functions even the computer cannot perform by itself. One of these programs includes the Java Program. The Java Program is a program that builds programs. Programs are basically pieces of data with several functions. We have attempted to create the Capture the Flag program on Java. To program other programs with Java, the user needs to write the code. The code requires several different types of words and commands. The three main ones are classes and objects, arrays, and threads. These three are required to make a half decent program, but to make a large scale project, more is needed. However, these three types of words are the most important ones when trying to create a program on Java.

Threads Threads are also important in the making of a program in Java. An example of what threads are supposed to do can be found in everyday life. If two people are having a conversation and one starts talking while the other sets his hand on the table, that is a perfect example of a thread. Threads allow the computer to perform functions simultaneously. If there were no threads, then everyone and everything would have to stop moving and wait for one action at a time. Likewise, if there were no threads, then a certain action would have to wait until everything else has stopped to perform that action. Of course, a thread by itself is useless without being linked to another thread. When a thread is linked to another thread however, then the two actions can be performed at the same time. This is very important in Capture the Flag since there are likely to be a lot of threads allowing the gun, the player, the projectiles, and the flag to move.

23-2 Threads also allow the program to simplify the method to receive a command from the user. If the user commands the program to move the character and fire at the same time, the thread sends out a call signal listening for the command. Since the call signal is in equal intervals, it does not matter how long the command is, but the computer will respond to the command smoothly.

Arrays Arrays are ideal for storing information. If one is given a number, one would usually have a variable stand in for it. But if one had a thousand numbers, then it would be absurd to write a variable for each and every one of them. This is where arrays come in. Arrays are like variables, but they can stand in for a list of commands and numbers. To properly use an array, one must type ‘public static int’ then a set of brackets, and finally the object. Later, have this typed into the code: (Object that uses the array) = new int [the number or coordinate desired] In the Capture the Flag program, arrays are used to determine the terrain code. Each of the numbers 0-8 represents a different condition for the land in that square. An array is needed to label each of the different types of terrain. Arrays are also used to determine where the player starts on the map. Two arrays are used. One is used for the x value of the coordinate, and the other is used for the y value of the coordinate. Also arrays have to be used even for a simple task such as moving the player.

Classes and Objects These are the most important and most used of all three. Classes are separated into individual classes. Each class has several objects, and each object within that class has a similar function. Objects can store data and/or perform a function when used correctly. However, in Java there can’t be an object without a class representing it. In our project, each weapon is its separate class. The objects within the weapons range from the rate of fire to the projectile range to the projectile speed. All those objects within the class are necessary to create the class itself. The network server class includes several objects such as the max players and the connect count. The objects represent each of the different functions in the code. In the code for the project, there are over a hundred objects, each with a different operation. When the program runs, you will see all of the classes and objects at work. However, in the code the objects and classes must all be written in a certain way. The object word is written as having the first word all lowercase letters, and without spaces, any word that follows has the first letter capitalized. The different classes also can’t have any spaces, but other than that, there are no limits to the label. The different objects must also have a sub-code before it. In Java, each of the different classes must have a separate code and function. The objects, arrays, and threads must all be programmed into that class to make it complete. With multiple classes having the right objects, threads, and arrays, the user can make a program do almost anything. For example, we created all of the weapons which all had to be represented by separate classes. All of the weapons had to have countless objects, threads, and arrays to program each of

23-3 the weapons’ characteristics. Also, the projectiles had to have their own class and be programmed so that they will come out of the gun and fly at an intended speed. The player has to have the gun sight and shape programmed into its class. The map generator also had to recognize documents from Microsoft Excel. All of these together make the game function.

Capture the Flag The program is made on Java. It is incomplete, however many of the main features can still be used. Both players can fire several different types of weapons, from flamethrowers, to laser rifles, to energy pistols, to pulse cannons. The weapons all have limited ammo and an aiming reticule. These weapons also have recoil to them, and the laser rifle decreases its rate of fire from overheating. Also, most projectiles cease when they hit a wall, and they cannot travel outside of the map. However, no extra ammo can be picked up, and there doesn’t seem to be a way to switch weapons right in the middle of a match. There are three maps, each with successful terrain simulation. However, players cannot travel on the extreme edges of the map. Also, some editing to the landscape is necessary. Both players are able to fire at each other and they do have HP. However, the players cannot die yet and the HP is not displayed on the map. In addition, we have failed to put in respawn points on the map. There are no flags, nor do the players have the ability to pick up objects of any kind. Occasionally, the controls will get stuck, and the unfortunate player is forced to move in that one direction for the rest of the game. Players can also aim through walls. We are debating whether or not to keep this trait, but it is unrealistic by video game standards. We have also failed to add grenades, vehicles, or computer AI. Also, players can be spotted easily on the map, no matter what the situation. So far, there are no teams. This means that the game is currently a ‘kill ‘em’ free for all. One of our greatest features is the fact that it can be networked and can connect to other computers.

Conclusion In short, our game is incomplete. However, it cannot be deemed as a complete failure. The game just needs more time to work on. We had to build a fully functional action game with countless features in two weeks, and it was simply too much to ask for. Many people, us included, can pick up the program and continue our work. That being said, we have learned a treasure’s worth of learning. This project is indeed a success because we never gave up. We kept working until the deadline. We hope that if our project does get completed in the near future, that it will attract audiences everywhere. And it doesn’t stop there. We still have so much to learn about the Java Program, and about computers themselves. There are still endless possibilities that can be done with this machine. We hope to discover some of them in the near future.

Jun Wang Jun Wang Dr
About Some of Those documents come from internet for research purpose,if you have the copyrights of one of them,tell me by mail you!