-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67deb47
commit 57fd9b9
Showing
24 changed files
with
899 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ Typescriptの学習で書いたお遊びコード。コンソールで銃の操 | |
``` | ||
$ npm install | ||
$ tsc | ||
$ node index.js | ||
$ node build/index.js | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)オートマチック用マグナム弾' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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パラベラム弾' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.