Lab08 - Riti Gupta 20249537 Section 22 Lab 08 1. classdef...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Riti Gupta 20249537 Section 22 Lab 08 1. classdef wolf properties name= 'mister wolf' ; health=100; pos=rand(1,2)*100; rank=3; end methods % constructor method function [w]= wolf(name,health,pos,rank) if nargin==0 %do nothing-default values elseif nargin==4 w.name=name; w.health=health; w.pos=pos; w.rank=rank; else error( 'Must be 4 inputs!' ) end end %end wolf % speak method function [] = speak(wolf,type) if strcmp(type, 'bark' ); fprintf( '%s says: woof! \n' ,wolf.name) elseif strcmp(type, 'growl' ) fprintf( '%s says: grrr. ..! \n' ,wolf.name) elseif strcmp(type, 'whimper' ) fprintf( '%s whimpers. .. \n' ,wolf.name) elseif strcmp(type, 'pant' ) fprintf( '%s says: *pant pant pant*' ,wolf.name) end end % hunt method function [wolf] = hunt(wolf, rabbit) if rabbit.isPregnant==1; rabbit.pos=rand(1,2)*100 speak(wolf, 'whimper' ) fprintf( '%s ran away \n' , rabbit.name) fprintf( 'from %s!' ,wolf.name) else rabbit.isPregnant==0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
W=(wolf.health)/(rand+1); R=(rabbit.health)/(2*rand + 1); if W>R wolf.pos=rabbit.pos
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/01/2009 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 3

Lab08 - Riti Gupta 20249537 Section 22 Lab 08 1. classdef...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online