This commit is contained in:
2025-10-09 16:10:36 +08:00
parent 19a4cab4e8
commit 3b95455b2e

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2018 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
* applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package com.github.drinkjava2.frog.brain.organ;
import com.github.drinkjava2.frog.Env;
import com.github.drinkjava2.frog.Frog;
import com.github.drinkjava2.frog.brain.Organ;
/**
* Eat food at current x, y position
*/
public class Eat extends Organ {// Eat这个类将食物转化为能量能量小于0则青蛙死掉
private static final long serialVersionUID = 1L;
@Override
public void active(Frog f) {
if (Env.foundAndAteFood(f.x, f.y)) {
f.ateFood++;
// 所有的硬编码都是bug包括这个1000
f.energy += 1000;// 如果青蛙的坐标与食物重合吃掉food能量境加
// 能量境加青蛙感觉不到但是Happy区激活青蛙能感觉到因为Happy区是一个脑器官
Organ o = f.organs.get(0);
((Happy) o).happy += 2; // 找到食物有奖!
}
}
}