• 2018-2019学年第一学期Java课设--魔塔


    Magic-Towers

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

      团队博客地址

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

     我负责Controller类

    • 玩家数据I/O流
    • 游戏内部监听器:存档、选角色、退出
    • 游戏地图数据
    • 编写团队博客

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

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

    数据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层,让勇士成功地营救出公主。

  • 相关阅读:
    Tye exception
    DataSeeder
    angular
    认证Authentication
    MVC
    Ef Core
    工作单元
    VirtualFileSystem
    中间件
    日志
  • 原文地址:https://www.cnblogs.com/lmb171004/p/10280007.html
Copyright © 2020-2023  润新知