From 38135762f65267840f5ad389f8aa587f804e2884 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Fri, 4 Nov 2022 17:53:17 -0300 Subject: [PATCH] Add exploding bunny rabbit --- assignments/A4/moarlife.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/assignments/A4/moarlife.js b/assignments/A4/moarlife.js index 1f0c528..13b4bd6 100644 --- a/assignments/A4/moarlife.js +++ b/assignments/A4/moarlife.js @@ -44,6 +44,10 @@ actionTypes.reproduce = function(critter, vector, action) { return true; }; +actionTypes.die = function(critter, action) { + +} + class LifelikeWorld extends life.World { constructor(map,legend){ super(map,legend); @@ -95,8 +99,24 @@ class PlantEater{ }; } +class ExplodingBunnyRabbit extends PlantEater { + constructor () { + super() + } + + act(view) { + super.act(view); + if(this.energy > 55) { + if (Math.random() < 0.25) { + return {type: "die"} + } + } + } +} + exports.LifelikeWorld=LifelikeWorld; exports.BouncingCritter=life.BouncingCritter; exports.Wall=life.Wall; exports.PlantEater = PlantEater; -exports.Plant = Plant; \ No newline at end of file +exports.Plant = Plant; +exports.actionTypes = actionTypes; \ No newline at end of file