Skip to content

Commit

Permalink
๐ŸŽ‰ add : ํ”„๋กœ์ ํŠธ ์ตœ์ดˆ ๋“ฑ๋ก
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonseol00 committed Jun 17, 2024
0 parents commit 8a0b411
Show file tree
Hide file tree
Showing 21 changed files with 773 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"semi": true
}
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nbc5_websocket_game",
"version": "1.0.0",
"description": "",
"main": "src/app.js",
"scripts": {
"dev": "nodemon src/app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"socket.io": "^4.7.5",
"uuid": "^10.0.0"
},
"devDependencies": {
"nodemon": "^3.1.3",
"prettier": "^3.3.1"
}
}
Binary file added tower_defense_client/images/.DS_Store
Binary file not shown.
Binary file added tower_defense_client/images/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/bg.webp
Binary file not shown.
Binary file added tower_defense_client/images/favicon.ico
Binary file not shown.
Binary file added tower_defense_client/images/monster1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/monster2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/monster3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/monster4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/monster5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tower_defense_client/images/tower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions tower_defense_client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Changmin Kang" />
<title>๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico" />
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #2d2d2d;
flex-direction: column;
}
#gameCanvas {
border: 2px solid #000;
display: none;
}
.button-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
.button-container button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="button-container">
<h1 style="color: white">๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</h1>
<button id="registerButton">ํšŒ์›๊ฐ€์ž…</button>
<button id="loginButton">๋กœ๊ทธ์ธ</button>
<button id="playButton">๊ฒŒ์ž„ ํ”Œ๋ ˆ์ด</button>
</div>
<canvas id="gameCanvas" width="1920" height="1080"></canvas>
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
<script type="module">
document
.getElementById("registerButton")
.addEventListener("click", () => {
window.location.href = "register.html";
});

document.getElementById("loginButton").addEventListener("click", () => {
window.location.href = "login.html";
});

document.getElementById("playButton").addEventListener("click", () => {
document.querySelector(".button-container").style.display = "none";
document.getElementById("gameCanvas").style.display = "block";
import("./src/game.js");
});
</script>
</body>
</html>
62 changes: 62 additions & 0 deletions tower_defense_client/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Changmin Kang" />
<title>๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico" />
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #2d2d2d;
color: white;
font-family: Arial, sans-serif;
}
.form-container {
display: flex;
flex-direction: column;
align-items: center;
}
.form-container input {
margin: 10px;
padding: 10px;
font-size: 16px;
}
.form-container button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="form-container">
<h1>๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</h1>
<h2>๋กœ๊ทธ์ธ</h2>
<input type="text" id="username" placeholder="์•„์ด๋””" />
<input type="password" id="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" />
<button id="login">๋กœ๊ทธ์ธ</button>
<button id="back">๋’ค๋กœ๊ฐ€๊ธฐ</button>
</div>
<script>
document.getElementById("login").addEventListener("click", () => {
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;

/*
๋กœ๊ทธ์ธ API ํ˜ธ์ถœ ํ›„ ๋กœ๊ทธ์ธ ์„ฑ๊ณต ์‹œ index.html๋กœ ์ด๋™์‹œ์ผœ์ฃผ์„ธ์š”!
์ด ๋•Œ, ์—‘์„ธ์Šค ํ† ํฐ์€ ์–ด๋”˜๊ฐ€์— ์ €์žฅ์„ ํ•ด๋†”์•ผ๊ฒ ์ฃ ?!
*/
});

document.getElementById("back").addEventListener("click", () => {
window.location.href = "index.html";
});
</script>
</body>
</html>
61 changes: 61 additions & 0 deletions tower_defense_client/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Changmin Kang" />
<title>๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico" />
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #2d2d2d;
color: white;
font-family: Arial, sans-serif;
}
.form-container {
display: flex;
flex-direction: column;
align-items: center;
}
.form-container input {
margin: 10px;
padding: 10px;
font-size: 16px;
}
.form-container button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="form-container">
<h1>๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ Node.js ํŠธ๋ž™ ํƒ€์›Œ ๋””ํŽœ์Šค ๊ฒŒ์ž„</h1>
<h2>ํšŒ์›๊ฐ€์ž…</h2>
<input type="text" id="username" placeholder="์•„์ด๋””" />
<input type="password" id="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" />
<button id="register">ํšŒ์›๊ฐ€์ž…</button>
<button id="back">๋’ค๋กœ๊ฐ€๊ธฐ</button>
</div>
<script>
document.getElementById("register").addEventListener("click", () => {
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;

/*
ํšŒ์›๊ฐ€์ž… API ํ˜ธ์ถœ ํ›„ ํšŒ์›๊ฐ€์ž… ์„ฑ๊ณต ์‹œ index.html๋กœ ์ด๋™์‹œ์ผœ์ฃผ์„ธ์š”!
*/
});

document.getElementById("back").addEventListener("click", () => {
window.location.href = "index.html";
});
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions tower_defense_client/src/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export class Base {
constructor(x, y, maxHp) {
// ์ƒ์„ฑ์ž ์•ˆ์—์„œ ๊ธฐ์ง€์˜ ์†์„ฑ์„ ์ •์˜ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค!
this.x = x; // ๊ธฐ์ง€ ์ด๋ฏธ์ง€ x ์ขŒํ‘œ
this.y = y; // ๊ธฐ์ง€ ์ด๋ฏธ์ง€ y ์ขŒํ‘œ
this.width = 170; // ๊ธฐ์ง€ ์ด๋ฏธ์ง€ ๊ฐ€๋กœ ๊ธธ์ด (์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ธธ์ด์— ๋”ฐ๋ผ ๋ณ€๊ฒฝ ํ•„์š”ํ•˜๋ฉฐ ์„ธ๋กœ ๊ธธ์ด์™€ ๋น„์œจ์„ ๋งž์ถฐ์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!)
this.height = 225; // ๊ธฐ์ง€ ์ด๋ฏธ์ง€ ์„ธ๋กœ ๊ธธ์ด
this.hp = maxHp; // ๊ธฐ์ง€์˜ ํ˜„์žฌ HP
this.maxHp = maxHp; // ๊ธฐ์ง€์˜ ์ตœ๋Œ€ HP
}

draw(ctx, baseImage) {
ctx.drawImage(
baseImage,
this.x - this.width,
this.y - this.height / 2,
this.width,
this.height
);

ctx.font = "16px Arial";
ctx.fillStyle = "white";
ctx.fillText(
`HP: ${this.hp}/${this.maxHp}`,
this.x - this.width,
this.y - this.height / 2 - 10
);
}

takeDamage(amount) {
// ๊ธฐ์ง€๊ฐ€ ๋ฐ๋ฏธ์ง€๋ฅผ ์ž…๋Š” ๋ฉ”์†Œ๋“œ์ž…๋‹ˆ๋‹ค.
// ๋ชฌ์Šคํ„ฐ๊ฐ€ ๊ธฐ์ง€์˜ HP๋ฅผ ๊ฐ์†Œ์‹œํ‚ค๊ณ , HP๊ฐ€ 0 ์ดํ•˜๊ฐ€ ๋˜๋ฉด ๊ฒŒ์ž„ ์˜ค๋ฒ„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์š”!
this.hp -= amount;
return this.hp <= 0; // ๊ธฐ์ง€์˜ HP๊ฐ€ 0 ์ดํ•˜์ด๋ฉด true, ์•„๋‹ˆ๋ฉด false
}
}
Loading

0 comments on commit 8a0b411

Please sign in to comment.