Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Arrays10-4-2010Opening Discussion●Do you have any questions about the quiz?●Minute Essay comments–Pretty pictures/games – 10–HTML– 5–Spreadsheet – 9–Easiest – 2–Making something you do regularly automated.–Animation as a possibility.Midterm●The midterm is on Friday. We are going to have some review sessions. The extra credit is going to be a set of problems.One Person Per House●Our goal for today is to make it so that only one person can go into a house at a time.●We are going to do this in a number of different steps.●First we should go add code to the person that checks if the person has reached a house yet.Giving House a Memory●Now we need each building to remember if a person is in it.●We will actually give the house a reference to a person that is null if no one is there and set to the person if one has gone in.–private Person occupant;●Then we can add public methods to interact with it.●Once we have that, we can try to make the people avoid houses that have already been taken.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 rocket/car 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 rocket can pick up 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]);–}●Let's write functions that add up the elements in an array or find the smallest or largest.●Make an array to hold all the houses in the City and copy stuff over from the list.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 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