Mario开发流程(二)

加载所需图片

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

public class StaticValue {
	public static List<BufferedImage> allMarioImage = new ArrayList<BufferedImage>();
	public static BufferedImage startImage = null;
	public static BufferedImage endImage = null;
	public static BufferedImage bgImage = null;
	public static List<BufferedImage> allFlowerImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allTriangleImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allTurtleImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allObstructionImage = new ArrayList<BufferedImage>();
	public static BufferedImage marioDeadImage = null;

	// 将全部图片初始化
	public static void init() {
		// 将所有Mario图片保存到静态属性中
		for (int i = 1; i <= 10; i++) {
			try {
				System.out.println(StaticValue.class.getClassLoader()
						.getResource("images/" + i + ".gif").getFile());
				BufferedImage tempImage = ImageIO
						.read(new File(StaticValue.class.getClassLoader()
								.getResource("images/" + i + ".gif").getFile()));
				allMarioImage.add(tempImage);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// 导入全部背景图片
		try {
			startImage = ImageIO
					.read(new File(StaticValue.class.getClassLoader()
							.getResource("images/start.gif").getFile()));
			endImage = ImageIO.read(new File(StaticValue.class.getClassLoader()
					.getResource("images/firststageend.gif").getFile()));
			bgImage = ImageIO.read(new File(StaticValue.class.getClassLoader()
					.getResource("images/firststage.gif").getFile()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		// 将所有敌人的图片保存到静态属性中
		for (int i = 1; i <= 5; i++) {
			try {
				if (i <= 2) {
					BufferedImage tempImage = ImageIO.read(new File(
							StaticValue.class.getClassLoader()
									.getResource("images/flower" + i + ".gif")
									.getFile()));
					allFlowerImage.add(tempImage);
				}
				if (i <= 3) {
					BufferedImage tempImage = ImageIO
							.read(new File(
									StaticValue.class
											.getClassLoader()
											.getResource(
													"images/triangle" + i
															+ ".gif").getFile()));
					allTriangleImage.add(tempImage);
				}
				BufferedImage tempImage = ImageIO.read(new File(
						StaticValue.class.getClassLoader()
								.getResource("images/Turtle" + i + ".gif")
								.getFile()));
				allTurtleImage.add(tempImage);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// 将所有障碍物图片保存到静态属性中
		for (int i = 1; i <= 12; i++) {
			try {
				BufferedImage tempImage = ImageIO.read(new File(
						StaticValue.class.getClassLoader()
								.getResource("images/ob" + i + ".gif")
								.getFile()));
				allObstructionImage.add(tempImage);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		// 导入mario死亡的图片
		try {
			marioDeadImage = ImageIO
					.read(new File(StaticValue.class.getClassLoader()
							.getResource("images/over.gif").getFile()));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


代码中存在大量重复现象,需要进行代码重构,重构后如下所示:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

public class StaticValue {
	public static List<BufferedImage> allMarioImage = new ArrayList<BufferedImage>();
	public static BufferedImage startImage = null;
	public static BufferedImage endImage = null;
	public static BufferedImage bgImage = null;
	public static List<BufferedImage> allFlowerImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allTriangleImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allTurtleImage = new ArrayList<BufferedImage>();
	public static List<BufferedImage> allObstructionImage = new ArrayList<BufferedImage>();
	public static BufferedImage marioDeadImage = null;

	// 将全部图片初始化
	public static void init() {
		// 将所有Mario图片保存到静态属性中
		for (int i = 1; i <= 10; i++) {
			try {
				allMarioImage.add(loadImage("images/" + i + ".gif"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// 导入全部背景图片及马里奥死亡的图片
		try {
			startImage = loadImage("images/start.gif");			
			endImage =loadImage("images/firststageend.gif");
			bgImage = loadImage("images/firststage.gif");
			marioDeadImage = loadImage("images/over.gif");
		} catch (IOException e) {
			e.printStackTrace();
		}
		// 将所有敌人的图片保存到静态属性中
		for (int i = 1; i <= 5; i++) {
			try {
				if (i <= 2) {
					allFlowerImage.add(loadImage("images/flower"+i+".gif"));
				}
				if (i <= 3) {
					allTriangleImage.add(loadImage("images/triangle"+i+".gif"));
				}
				allTurtleImage.add(loadImage("images/Turtle"+i+".gif"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// 将所有障碍物图片保存到静态属性中
		for (int i = 1; i <= 12; i++) {
			try {
				allObstructionImage.add(loadImage("images/ob"+i+".gif"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	private static BufferedImage loadImage(String url) throws IOException {
		BufferedImage tempImage = ImageIO.read(new File(
				StaticValue.class.getClassLoader()
						.getResource(url)
						.getFile()));
		return tempImage;
	}

}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
美团mario是美团外卖团队在移动端自动化测试方面推出的一款测试框架。该框架主要应用于美团外卖App的自动化测试,旨在帮助开发团队提高测试效率、降低测试成本、增强测试可靠性。 美团mario测试框架基于Java语言开发,采用Appium作为底层测试引擎,通过使用Appium提供的WebDriver接口,可以实现对Android和iOS平台上App的自动化测试。 美团mario提供了一系列的测试用例编写和执行的工具、插件和库,包括了元素查找封装、数据准备、页面操作、数据校验等功能模块。测试脚本可以通过编写简单的Java代码来完成,而无需具备专业的编程技能。开发者只需熟悉框架提供的API和方法,即可编写出高效、稳定的测试脚本。 另外,美团mario框架还提供了丰富的测试报告和结果分析功能,可以生成详细的测试报告和日志,帮助开发团队快速定位和解决问题。开发者可以通过报告中的图表和统计数据来评估测试覆盖率和稳定性,以及发现潜在的性能瓶颈和异常情况。 总体来说,美团mario测试框架为美团外卖团队带来了很大的便利和效益。它简化了移动端自动化测试的流程,提高了测试团队的效率,保证了App的质量和稳定性。通过持续集成和持续交付的测试流程,美团mario框架帮助美团外卖团队实现了快速迭代和发布,为用户提供更好的体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值