惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
V
V2EX
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
Y
Y Combinator Blog
C
Check Point Blog
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
美团技术团队
雷峰网
雷峰网
IT之家
IT之家
WordPress大学
WordPress大学
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
N
News and Events Feed by Topic
罗磊的独立博客
S
SegmentFault 最新的问题
S
Security Affairs
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Google DeepMind News
Google DeepMind News
B
Blog
O
OpenAI News
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
Hacker News: Ask HN
Hacker News: Ask HN
博客园_首页
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Help Net Security
Help Net Security
月光博客
月光博客
J
Java Code Geeks
L
LangChain Blog
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

Yusuf Aytas

When Code Is Cheap, Does Quality Still Matter? Why Crouching Tiger, Hidden Dragon Is a Masterpiece Why We Ignore Advice The Mirror Is Part of the Machine When Too Many Maps Overlap on One Person The Work Runs on Different Maps Your Work Introduces You Trial By Fire The Dude Why Headcount Math Lies Capacity Is the Roadmap The Roadmap Is Not the System Torres del Paine W Trek Escaping Status Theater Incentives Drive Everything Scaling Culture Without Dilution What Good Looks Like Why Airport Security Feels Random Why Politics Appear How to Work with Me The Janus Protocol Multi-Horizon Delivery Framework What Good Execution Looks Like Managing Your Manager Why Kingdom of Heaven’s Director’s Cut Is Better AI Broke Interviews Most of What We Call Progress Managers Have Been Vibe Coding All Along Stop Wasting Brainpower Why Over-Engineering Happens Prisoner's Dilemma Climbing No More The Weekly Win Mevlana Candy Brewing Turkish Tea Onboarding Your Engineering Manager Technical Deep Dives Yapay Zekâ Çağında Bilgisayar Mühendisliği Building Remote Teams From Idea to Launch in 2 Weeks Reflecting on Software Engineering Handbook Representing the Business New Manager Survival Guide Take Self Reviews Seriously Chasing Real Respect The Invisible Difference Learning the Johari Window Management is a Lonely Place Simple Task Management AI Balance in Work PIP Manager Insights Engineering Manager Interview Preparation Work-Life Balance as a Manager Bridging the Management Disconnect Tech Hiring Bubble Bursts Traits for EMs Simple Acts of Recognition Matter The Question I Ask Every New Report The Reality of an Employer's Market Bridging Ideals and Reality Hiring Red Flags Why The Godfather Is So Damn Good Subteam Tenets No Fluff Please Losing a Top Performer Balancing Act of Reliability Building Trust in Engineering Teams Ideal Number of Direct Reports Overriding a People Leader’s Decision From Misperception to Promotion Perception vs Perspective Setting Goals From Engineer to Manager Getting Delegation Right Interviewing Your Future Boss Celebrating Our Book in Iceland Operational Skills Needed On Writing Software Engineering Handbook Charlie Munger Quotes Working with Dependencies From Las Vegas to Canyons Navigating Layoffs Handling Competitive Dynamics A Weekend Getaway to Malta Engineering Health Essentials Should Dev Managers Code? Confronting the Life on Pause Winning Eleven Kindness is A Choice Bireysel Katılımcılar ve Yöneticiler Leading from Where You Are The Subtle Art of Listening Coding in Leadership The Power of Consistency The Making of a Leader The Path to Leadership Embracing TikTok Talent Sourcing Journey Leading Self Managing Teams Cracking Coding Bottlenecks
Implementing HTML5 Bomberman
Yusuf Aytas · 2013-12-11 · via Yusuf Aytas

Published · 3 min read

Bomberman game boardBomberman game board

CS102 is one of the most important course in CS curriculum. In this course, students learn how to write recursive function, object-oriented programming and etc. This course provides foundations of computer programming. Generally, CS102 requires completing semester-long project. For this project, we have developed a game, Bombuster(Classical Bomberman game). We were group of 4 and our members were Ender Demirkaya, Alperen Eraslan, Hüseyin Güler, and me. Anyway, I was a bit bored recently and decided to write Bombuster using HTML5 technologies. Consequently, I have written the Bomberman and want to give a quick tutorial as follows.

[overall_bombermanoverall_bomberman

Before diving into details of the game, let's give how it looks like first. Note that hero and monster figures are from our CS102 project. To play the game again, just reload the page.

iio.start(Bomberman,'bomberman');

After the demo of the game, let's look at how we designed Bomberman. In the below figure, we have a container so called Bomberman which has bonuses, creatures, hero and grid which is the visual area that we see. Bomberman container receives io from the iioengine(quick tutorial) upon the startup and creates the map(grid) and objects like hero or creatures. io object is a global object in iioengine that provides modification of the objects in the canvas. Simply, if you want to add something to application, you just call io.addObj function.

Moreover, we have defined the object models in the above figure. All objects are cells of the grid. Cell object is a subclass of iioengine rectangle. Extending the rectangle class, we got the ability to add objects to io object and remove objects from io object. Let me show you how we extend Rect class as follows.

Bomberman.Cell = function(x, y) {
   this.setX(x);
   this.setY(y);
   //call the super constructor.
   iio.Rect.call(this, x * options.cellSize + DEFAULT_MARGIN, y
   * options.cellSize + DEFAULT_MARGIN, options.cellSize, 
   options.cellSize);
};
// Extend iio.Rect
Bomberman.Cell.prototype = Object.create(iio.Rect.prototype);
Bomberman.Cell.prototype.constructor = Bomberman.Cell;

Similarly, we extend our objects as follows,

Bomberman.Bonus = function(x,y,io,img,hero){
   this.io = io;
   this.hero = hero;
   this.addImage(img);
   //call to the super constructor.
   Bomberman.Cell.call(this, x, y);
};
//extend the Bomberman.Cell
Bomberman.Bonus.prototype = Object.create(Bomberman.Cell.prototype);
Bomberman.Bonus.prototype.constructor = Bomberman.Bonus;

Bomberman class diagramBomberman class diagram

After designing our objects just like in the diagram, we have written necessary functions for those classes. For instance, we have written the destroyObjects function for bomb class, which recursively destroys the objects that is exposed to the bomb fire. For Hero, we have developed dropBomb function which drops available bombs when you press space. Let's give a class diagram with the methods to show functions we have developed.

This diagram highlights main functions that are developed for the game. Although this design works very well for this little game, it might not be a good choice when you want to extend it because we did not dive into separating concerns. The better design would make use of controllers and model classes. Hence, we could have controllers that can take user inputs and change models' states. Also, we could have separate logic from the views. Anyway, this is our current design and I did not pay much attention to separation of concerns.
Briefly, I redesigned and developed our CS102 project using the web technologies I had at the time. There may still be rough edges in the implementation, but it was a much better version than the one we originally built for CS102. I am keeping the write-up here as a snapshot of the project and the design ideas behind it.