Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Arrays10/2/2009Opening Discussion●Do you have any questions about the quiz?●What is the purpose of loops? Lists?●Minute Essay comments–Fun – 15 (sudoku mentioned by name)–Spreadsheet – 5–Text and HTML– 4 each–Optimization – 2–Network and hacking – 1 each–How do they do 3-D graphics/sound?–How do viruses work?Midterm●The midterm is a week from today. We are going to have some review sessions. The extra credit is going to be a set of problems.Objectives●We have some new objectives for this week. The main objective is to get our city scenario working as a valid game.–Have the Lemur move on straight lines all the time. Turn when key is hit.–Have people not return to the same house and do random walks without diagonals when there isn't a house to go to.–Scoring is how many people the Lemur can eat in certain number of calls to update.Arrays●Lists are not the only way of storing multiple values. Arrays are often simpler.●Arrays have a different syntax and can't change size.●Square brackets indicate an array type.–int[] numbers;–String[] words;Making Arrays●Use new to make an array or “shortcut” syntax.–int[] numbers=new int[50];–int[] fewNumbers={34,19,22,21,20,18};●If the array hold primitives the values are 0 or false to start with.●If the array holds objects the values are null to start with.Using Arrays●Instead of calling get, use square brackets.●The following prints the values in an array.–for(int i=0; i<numbers.length; i++) {●System.out.println(numbers[i]);–}Direction Moves as Arrays●Instead of a bunch of if statements, we can use arrays to keep the move information in two arrays.–int[] xoff={0,1,0,-1};–int[] yoff={-1,0,1,0};Code●We want to use this technique for movement in both the Lemur and the Person.●Once we have that we can put in the code so people don't return to the same house.Minute Essay●What questions do you have about our topics
View Full Document