Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-arataki committed Apr 6, 2019
1 parent 67deb47 commit 57fd9b9
Show file tree
Hide file tree
Showing 24 changed files with 899 additions and 1 deletion.
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# macOS
### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/macOS.gitignore
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Linux
### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Linux.gitignore
*~
.fuse_hidden*
.directory
.Trash-*
.nfs*

# Windows
### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Global/Windows.gitignore
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
*.stackdump
[Dd]esktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp
*.lnk

# node.js
### https://raw.github.com/github/gitignore/07c730e1fccfe0f92b29e039ba149d20bfb332e7/Node.gitignore
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pids
*.pid
*.seed
*.pid.lock
lib-cov
coverage
.nyc_output
.grunt
bower_components
.lock-wscript
build/
node_modules/
jspm_packages/
typings/
.npm
.eslintcache
.node_repl_history
*.tgz
.yarn-integrity
.env
.next
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Typescriptの学習で書いたお遊びコード。コンソールで銃の操
```
$ npm install
$ tsc
$ node index.js
$ node build/index.js
```
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "typescript-study-gunshot",
"version": "1.0.0",
"private": true,
"description": "",
"main": "build/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"watch": "tsc -w"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/prompts": "^1.2.0",
"consola": "^2.5.7",
"mitt": "^1.1.3",
"prompts": "^2.0.4"
}
}
58 changes: 58 additions & 0 deletions src/App/Action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as c from './Factory'
import * as g from './Gun'
import * as m from './Magazine'
import * as b from './Bullet'

import prompts from 'prompts'

export const choiceGun = async function() :Promise<g.Gun> {
const response = await prompts({
type: "select",
name: "target",
message: "銃を試射できるスクリプトです。どの銃を試しますか?",
choices: c.GunFactory.choices()
})

const gun: g.Gun = c.GunFactory[response.target]()

return gun
}

export const choiceMagazine = async function() :Promise<m.Magazine> {
const response = await prompts({
type: "select",
name: "target",
message: "どのマガジンを試しますか?",
choices: c.MagazineFactory.choices()
})

const magazine: m.Magazine = c.MagazineFactory[response.target]()

return magazine
}

export const choiceBulletGenerator = async function() :Promise<Function> {
const response = await prompts({
type: "select",
name: "target",
message: "どの弾丸を試しますか?",
choices: c.BulletFactory.choices()
})

const bulletGenerator :Function = c.BulletFactory[response.target]

return bulletGenerator
}

export const operate = async function(gun: g.Gun, magazine: m.Magazine, bulletGenerator: Function) : Promise<boolean> {
const response = await prompts({
type: "select",
name: "target",
message: "次のアクション",
choices: c.ActionFactory.choices()
})

const result :boolean = c.ActionFactory[response.target](gun, magazine, bulletGenerator)

return result
}
8 changes: 8 additions & 0 deletions src/App/Bullet/Bullet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default abstract class Bullet
{
protected abstract name: string;

getName(): string {
return this.name
}
}
6 changes: 6 additions & 0 deletions src/App/Bullet/Bullet44amp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Bullet from './Bullet'

export default class Bullet44amp extends Bullet
{
protected name: string = '.44口径(11.2mm)オートマチック用マグナム弾'
}
6 changes: 6 additions & 0 deletions src/App/Bullet/Bullet9mm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Bullet from './Bullet'

export default class Bullet9mm extends Bullet
{
protected name: string = '9x19mmパラベラム弾'
}
9 changes: 9 additions & 0 deletions src/App/Bullet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Bullet from './Bullet'
import Bullet9mm from './Bullet9mm'
import Bullet44amp from './Bullet44amp'

export {
Bullet,
Bullet9mm,
Bullet44amp
};
148 changes: 148 additions & 0 deletions src/App/Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import * as g from './Gun'
import * as m from './Magazine'
import * as b from './Bullet'
import mitt from 'mitt';
import consola from 'consola'

const event: mitt.Emitter = new mitt()

event.on(
'Gun.SetMagazine.Success',
(option: { gun: g.Gun, magazine: m.Magazine }) => {
consola.info(
option.gun.getName()+'に'+
option.magazine.getName()+'をセットしました。'+
' [残弾 '+option.gun.getBulletCount()+']'
)
}
)

event.on(
'Gun.SetMagazine.Error.Exists',
(option: { gun: g.Gun, magazine: m.Magazine }) => {
consola.error(
option.gun.getName()+'に'+
option.magazine.getName()+'がすでにセットされています。'
)
}
)

event.on(
'Gun.SetMagazine.Error.Compatibility',
(option: { gun: g.Gun, magazine: m.Magazine }) => {
consola.error(
option.gun.getName()+'に'+
option.magazine.getName()+'はセットできません!'
)
}
)


event.on(
'Gun.UnsetMagazine.Success',
(option: { gun: g.Gun, magazine: m.Magazine }) => {
consola.info(
option.gun.getName()+'から'+
option.magazine.getName()+'を外しました。'
)
}
)

event.on(
'Gun.UnsetMagazine.Error.NoMagazine',
(option: { gun: g.Gun }) => {
consola.warn('マガジンが'+option.gun.getName()+'にセットされていません。')
}
)

event.on(
'Gun.SetBullet.Error.NoMagazine',
(option: { gun: g.Gun }) => {
consola.warn('マガジンが'+option.gun.getName()+'にセットされていないので弾丸を装填できません。')
}
)

event.on(
'Gun.SetBullet.Error.Compatibility',
(option: { gun: g.Gun, bullet: b.Bullet }) => {
consola.error(
option.gun.getName()+'に'+
option.bullet.getName()+'は装填できません!'
)
}
)

event.on(
'Gun.SetBullet.Error.EmptyMagazine',
(option: { gun: g.Gun, magazine: m.Magazine }) => {
consola.warn(option.magazine.getName()+'が空です。')
}
)

event.on(
'Gun.SetBullet.Success',
(option: { gun: g.Gun, bullet: b.Bullet }) => {
consola.ready(
option.bullet.getName()+'を薬室に装填しました。'+
' [残弾 '+option.gun.getBulletCount()+']'
)
}
)

event.on(
'Gun.UnsetBullet.Error.NoBullet',
(option: { gun: g.Gun }) => {
consola.warn(option.gun.getName()+'の薬室に弾丸がありません!')
}
)

event.on(
'Gun.UnsetBullet.Success',
(option: { gun: g.Gun, bullet: b.Bullet }) => {
consola.info(
option.bullet.getName()+'が薬室から排莢されました。'+
' [残弾 '+option.gun.getBulletCount()+']'
)
}
)

event.on(
'Gun.Shot.Error.NoBullet',
(option: { gun: g.Gun }) => {
consola.warn(option.gun.getName()+'の薬室に弾丸がありません!')
}
)

event.on(
'Gun.Shot.Success',
(option: { gun: g.Gun, bullet: b.Bullet }) => {
consola.success(
'<<<!! Bang !!>>>'+
option.bullet.getName()+'を発射しました!'+
' [残弾 '+option.gun.getBulletCount()+']'
)
}
)

event.on(
'Magazine.FulLoad.Success',
(option: { magazine: m.Magazine, bullet: b.Bullet }) => {
consola.info(
option.magazine.getName()+'を'+
option.bullet.getName()+
'でフル装填しました。('+option.magazine.getStockCapacity()+'発)'
)
}
)

event.on(
'Magazine.PushBullet.Error.Compatibility',
(option: { magazine: m.Magazine, bullet: b.Bullet }) => {
consola.error(
option.magazine.getName()+'に'+
option.bullet.getName()+'は装填できません!'
)
}
)

export default event
Loading

0 comments on commit 57fd9b9

Please sign in to comment.