java课程设计项目魔塔_2018-2019学年第一学期Java课设--魔塔

目录

Magic-Towers

一、团队课程设计博客链接

二、个人负责模块或任务说明

?我负责Controller类

玩家数据I/O流

游戏内部监听器:存档、选角色、退出

游戏地图数据

编写团队博客

三、自己的代码提交记录截图

574d121aaad87a27dcbaef3d5d77d69c.png

de2b189a04d4a3c17811f3b07dce55a3.png

四、自己负责模块或任务详细说明

数据I/O流功能

/*

游戏过程中,玩家由于各种原因需要退出终止游戏,但是还想下次继续游戏。所以设计了游戏进度的保存/读取的功能。使用了FileOutputStream、BufferedOutputStream、 ObjectOutputStream结合使用。

*/

public class PlayerFile {

public static final void savePlayer(Player player) {//保存玩家数据

//try-with-resource

try ( FileOutputStream out = new FileOutputStream("player.dat");

BufferedOutputStream bout = new BufferedOutputStream(out);

ObjectOutputStream obout = new ObjectOutputStream(bout);) {

obout.writeObject(player);

} catch (IOException e) {

}

}

public static final Player readPlayer() {//读取玩家数据

Player player = null;

try (FileInputStream in = new FileInputStream("player.dat");

BufferedInputStream bin = new BufferedInputStream(in);

ObjectInputStream obin = new ObjectInputStream(bin);) {

player = (Player) obin.readObject();

} catch (IOException e) {

} catch (ClassNotFoundException e) {

}

return player;

}

}

游戏动作监听器功能(部分)

/**

* 人物碰触格子

*/

private void contact(int x, int y) {

// 坐标对应第y行第x列

if (mapData[y][x].contact(player)) {

// 可以通过时

Component component = mapView.getComponent(x + y * 11);

// 获取该位置组件并判断是否为门

if (mapData[y][x] instanceof Door) {

mapData[y][x] = Floor.FLOOR;

inofView.update();

mainView.setVisible(true);

((DoorView) component).show();

return;

}

mapView.remove(playerView);

mapView.add(new FloorView(), player.getX() + player.getY() * 11);

mapView.remove(x + y * 11);

mapView.add(playerView, x + y * 11);

player.setCoord(x, y);

// 通过后显示提示

showInof(x, y);

if (mapData[y][x].getType() != Stairs.STAIRS_TYPE_DOWN_BIRTH

&& mapData[y][x].getType() != Stairs.STAIRS_TYPE_UP_BIRTH) {

mapData[y][x] = Floor.FLOOR;

player.getMapDataList().get(player.getNowFloor() - 1)[y][x] = 0;

}

} else {//不能通过

noEntryInof(x, y);

}

}

五、课程设计感想

本次课设对我来说还是比较有挑战性的,但因为对本游戏充满了兴趣,还是动力满满的完成的我所负责的部分。比较遗憾的是我们组并未完成网络或者数据库上的技术难点,不过我们组的界面以及人物动画是值得我们骄傲的,目前的游戏地图只到了10层还属于比较简易的难度,我们计划以后将地图扩展到50层,让勇士成功地营救出公主。

原文:https://www.cnblogs.com/lmb171004/p/10280007.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值