From 39e60445726021b64fc0719b2da3d9fabbefce17 Mon Sep 17 00:00:00 2001 From: 13766800364 <13766800364@qq.com> Date: Thu, 9 Oct 2025 16:11:16 +0800 Subject: [PATCH] Add File --- .../github/drinkjava2/frog/objects/Trap.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 history/005_letter_test/src/main/java/com/github/drinkjava2/frog/objects/Trap.java diff --git a/history/005_letter_test/src/main/java/com/github/drinkjava2/frog/objects/Trap.java b/history/005_letter_test/src/main/java/com/github/drinkjava2/frog/objects/Trap.java new file mode 100644 index 0000000..ff89086 --- /dev/null +++ b/history/005_letter_test/src/main/java/com/github/drinkjava2/frog/objects/Trap.java @@ -0,0 +1,52 @@ +/* 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.github.drinkjava2.frog.objects; + +import static com.github.drinkjava2.frog.Env.ENV_HEIGHT; +import static com.github.drinkjava2.frog.Env.ENV_WIDTH; +import static com.github.drinkjava2.frog.Env.bricks; + +import com.github.drinkjava2.frog.Frog; + +/** + * Trap will kill all frogs inside of it, if frog's position has material and + * it's not food, frog will die + * + * @author Yong Zhu + * @since 2019-08-05 + */ +@SuppressWarnings("all") +public class Trap implements EnvObject { + private static final int X1 = ENV_WIDTH / 2 - 350 / 2; // 陷阱左上角 + private static final int Y1 = ENV_HEIGHT / 2 - 20 / 2; // 陷阱左上角 + private static final int X2 = ENV_WIDTH / 2 + 350 / 2; // 陷阱右下角 + private static final int Y2 = ENV_HEIGHT / 2 + 20 / 2; // 陷阱右下角 + + @Override + public void build() { + for (int x = X1; x <= X2; x++) + for (int y = Y1; y <= Y2; y++) + bricks[x][y] = Material.TRAP; + } + + @Override + public void destory() { + for (int x = X1; x <= X2; x++) + for (int y = Y1; y <= Y2; y++) + bricks[x][y] = 0; + } + + @Override + public void active(int screen) { + + } + +}