From 74d4860d21ce28140825db2acd9502e7815fb88c Mon Sep 17 00:00:00 2001 From: 13766800364 <13766800364@qq.com> Date: Thu, 9 Oct 2025 16:07:41 +0800 Subject: [PATCH] Add File --- .../gitee/drinkjava2/frog/objects/Food.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 history/005a1_letter_test/src/main/java/com/gitee/drinkjava2/frog/objects/Food.java diff --git a/history/005a1_letter_test/src/main/java/com/gitee/drinkjava2/frog/objects/Food.java b/history/005a1_letter_test/src/main/java/com/gitee/drinkjava2/frog/objects/Food.java new file mode 100644 index 0000000..09ea677 --- /dev/null +++ b/history/005a1_letter_test/src/main/java/com/gitee/drinkjava2/frog/objects/Food.java @@ -0,0 +1,48 @@ +/* Copyright 2018-2020 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.gitee.drinkjava2.frog.objects; + +import static com.gitee.drinkjava2.frog.Env.ENV_HEIGHT; +import static com.gitee.drinkjava2.frog.Env.ENV_WIDTH; +import static com.gitee.drinkjava2.frog.Env.FOOD_QTY; +import static com.gitee.drinkjava2.frog.Env.bricks; + +import com.gitee.drinkjava2.frog.util.RandomUtils; + +/** + * Food randomly scatter on Env + * + * @author Yong Zhu + * @since 1.0 + */ +public class Food implements EnvObject { + + @Override + public void build() { + for (int i = 0; i < FOOD_QTY; i++) // 生成食物 + bricks[RandomUtils.nextInt(ENV_WIDTH)][RandomUtils.nextInt(ENV_HEIGHT)] = Material.FOOD; + } + + @Override + public void destory() { + for (int i = 0; i < ENV_WIDTH; i++) {// 清除食物 + for (int j = 0; j < ENV_HEIGHT; j++) + if (bricks[i][j] == Material.FOOD) + bricks[i][j] = 0; + } + } + + @Override + public void active(int screen) { + // Food do not have any active + } + +}