diff --git a/Asset.ts b/Asset.ts new file mode 100644 index 0000000..39ae683 --- /dev/null +++ b/Asset.ts @@ -0,0 +1,27 @@ +class Asset { + // 読み込んだ画像 + public images: {key?: string;} = {}; // 連想配列の定義 + + //アセットをimgタグからImageを作成 + private init() { + //全てのimgタグを取ってきてAssetに格納 + let htmlImgElements = document.getElementsByTagName("img"); + let assets; + htmlImgElements.forEach(img => { + let id = img.getAttribute("id"); + let src= img.getAttribute("src"); + assets.push( { type: 'image', id: id, src: src}); + }); + + // すべてのアセットを読み込む + assets.forEach(asset => { + switch (asset.type) { + case 'image': + let image = new Image(); + image.src = asset.src; + this.images[asset.id] = image; + break; + } + }); + } +} \ No newline at end of file diff --git a/Player.ts b/Player.ts new file mode 100644 index 0000000..ffcaa65 --- /dev/null +++ b/Player.ts @@ -0,0 +1,16 @@ +class Player { + private id: number; + private isAi: boolean; + // private color: ENUM_PLAYER_COLORS; + + // public infoSprite: PlayerInfoSprite; + + constructor(id: number, isAi: boolean) { + this.id = id; + this.isAi = isAi; + } + + public init() { + + } +} \ No newline at end of file diff --git a/Sprite/BaseSprite.js b/Sprite/BaseSprite.js deleted file mode 100644 index 34c42de..0000000 --- a/Sprite/BaseSprite.js +++ /dev/null @@ -1,51 +0,0 @@ -//spriteのベースクラス -//コンストラクタ なぜvarをつけてはいけない? -BaseSprite = function(){ - this.image = Image; - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.id = id; -} - -//クリック箇所が画像の中心からradius以内かどうか調べる -BaseSprite.prototype.checkClickedCircle = function(clicked_x,clicked_y, is=false, rate=1.0){ - radius = (this.height / 2) * rate; - center_x = this.x + this.width / 2; - center_y = this.y + this.height / 2; - - dx = center_x - clicked_x; - dy = center_y - clicked_y; - - distance = Math.sqrt(dx * dx + dy * dy); - - if ( is ) { - ctx.beginPath(); - ctx.arc(center_x, center_y, radius, 0, Math.PI*2, false); - ctx.stroke(); - } - - if ( distance < radius ) { - this.onClick(); - } -} - -BaseSprite.prototype.checkClickedRect = function(clicked_x,clicked_y){ - if ( this.x < clicked_x && clicked_x < this.x + this.width) { - if (this.y < clicked_y && clicked_y < this.y + this.height) { - this.onClick(); - } - } -} - -BaseSprite.prototype.draw = function(){ - ctx.drawImage( this.image , this.x , this.y , this.width , this.height ); -} - -//継承するために必要な関数らしい -var inherits = function(childCtor, parentCtor) { - // 子クラスの prototype のプロトタイプとして 親クラスの - // prototype を指定することで継承が実現される - Object.setPrototypeOf(childCtor.prototype, parentCtor.prototype); -}; \ No newline at end of file diff --git a/Sprite/BaseSprite.ts b/Sprite/BaseSprite.ts new file mode 100644 index 0000000..de2a05d --- /dev/null +++ b/Sprite/BaseSprite.ts @@ -0,0 +1,53 @@ +export class BaseSprite { + // private image: ??? + protected x: number; + protected y: number; + protected width: number; + protected height: number; + protected id: number; + + constructor(x:number, y:number, width:number, height:number, id:number) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.id = id; + } + + // TODO isって何? + public checkClickCircle(cx:number, cy:number, is:boolean, rate:number) { + let radius = (this.height / 2) * rate; + let center_x = this.x + this.width / 2; + let center_y = this.y + this.height / 2; + + let dx = center_x - cx; + let dy = center_y - cy; + + let distance = Math.sqrt(dx * dx + dy * dy); + + if ( is ) { + ctx.beginPath(); + ctx.arc(center_x, center_y, radius, 0, Math.PI*2, false); + ctx.stroke(); + } + + if ( distance < radius ) { + this.onClick(); + } + } + + public checkClickRect(cx:number, cy:number) { + if ( this.x < cx && this.x < this.width ) { + if ( this.y < cy && this.y < this.height ) { + this.onClick(); + } + + } + } + + public draw() { + ctx.drawImage( this.image , this.x , this.y , this.width , this.height ); + } + + public onClick() {} +} \ No newline at end of file diff --git a/Sprite/EdgeSprite.js b/Sprite/EdgeSprite.js deleted file mode 100644 index 0a34c6f..0000000 --- a/Sprite/EdgeSprite.js +++ /dev/null @@ -1,40 +0,0 @@ -var EdgeSprite = function(width,height,x,y,id,angle){ - - this.id = id; - this.owner_id = -1; - - this.width = width; - this.height = height; - - this.x = x; - this.y = y; - - this.angle = angle; // 0:- 1:/ 2:\ -} - -// inherits -inherits(EdgeSprite, BaseSprite); - -//@override -EdgeSprite.prototype.onClick = function(){ - if (_now_init_state == ENUM_INIT_STATE.BUILD) { - initBuild(this.id); - } -} - -EdgeSprite.prototype.init = function(){ - this.owner_id = -1; -} - -EdgeSprite.prototype.draw = function(candidate=false){ - var image; - if (candidate) { - image = Asset.images["token7"]; - ctx.drawImage( image, this.x, this.y, this.width, this.height); - } else { - if ( this.owner_id != -1 ) { - image = Asset.images["token12"]; - ctx.drawImage( image, this.x, this.y, this.width, this.height); - } - } -} diff --git a/Sprite/EdgeSprite.ts b/Sprite/EdgeSprite.ts new file mode 100644 index 0000000..e563b9d --- /dev/null +++ b/Sprite/EdgeSprite.ts @@ -0,0 +1,33 @@ +import {BaseSprite} from './BaseSprite'; + +class EdgeSprite extends BaseSprite { + private owner_id: number; + private angle: number; // 0:- 1:/ 2:\ + + constructor(x:number, y:number, width:number, height:number, id:number, owner_id:number, angle:number) { + super(x,y,width,height,id); + this.owner_id = owner_id; + this.angle =angle; + } + + // @override + public onClick() { + if (_now_init_state == ENUM_INIT_STATE.BUILD) { + initBuild(this.id); + } + } + + // @override + public draw2(candidate:boolean) { + let image; + if (candidate) { + image = Asset.images["token7"]; + ctx.drawImage( image, this.x, this.y, this.width, this.height); + } else { + if ( this.owner_id != -1 ) { + image = Asset.images["token12"]; + ctx.drawImage( image, this.x, this.y, this.width, this.height); + } + } + } +} \ No newline at end of file diff --git a/const.js b/const.js index 9710eb5..1793e15 100644 --- a/const.js +++ b/const.js @@ -1,51 +1,10 @@ -var ENUM_INIT_STATE = { - TILE : 0, - TOKEN : 1, - HARBOR : 2, - PLAYER_COLOR : 3, //AIか人かと席順も決める - PLAYER_ORDER : 4, //初期配置の順番を決める - BUILD : 5, //初期建設 - END : 6 //CheckButtonで使用 -}; - -var IMG_PATH = "./img/" - -var ENUM_RESOURCE = { BRICK:0, LUNBER:1, WOOL:2, GRAIN:3, ORE:4, DESERT:5}; -var RESOURCE_NAMES = ["brick" ,"lumber" ,"wool" ,"grain", "ore" ,"desert"]; var _resource_panel_remains = [ 3, 4, 4, 4, 3, 1]; - -var HARBOR_NAMES = ["brick" ,"lumber" ,"wool" ,"grain", "ore" ,"3_1"]; var _harbor_panel_remains = [ 1, 1, 1, 1, 1, 5]; - -var ENUM_PLAYER_COLORS = { RED:0, BLUE:1, ORANGE:2, WHITE:3}; -var PLAYER_COLORS = ["red" ,"blue" ,"orange" ,"white" ]; - -var ENUM_ACTIONS = { - KNIGHT :0, //騎士 - PLENTY :1, //収穫 - ROAD :2, //がいどう建設 - MONOPOLY :3, //独占 - POINT :4, //勝利点 -}; -var ACTION_NAMES = ["knight","plenty","road","monopoly","point"]; var ACTION_REMAINS = [ 14, 2, 2, 2, 5]; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12 var _token_panel_remains = [-1,-1, 1, 2, 2, 2, 2,-1, 2, 2, 2, 2, 1]; -var ENUM_CONTROLLER_TAB = { - DICE :0, - ACTION :1, - BUILD :2, - DOMESTIC :3, //貿易 - MARITIME :4, //交渉 - VICTORY :5 //勝利宣言 -}; -var CONTROLLER_TAB_NAMES = ["dice","action","build","domestic_trade","maritime_trade"]; - -var ENUM_BUILD = {ROAD:0,SETTLEMENT:1,CITY:2,DEVELOPMENT:3}; -var BUILD_NAMES = ["road","settlement","city","development"]; - var MAX_SETTLEMENT = 5; var MAX_CITY = 4; var MAX_ROAD = 15; diff --git a/const.ts b/const.ts new file mode 100644 index 0000000..e1abd78 --- /dev/null +++ b/const.ts @@ -0,0 +1,99 @@ +const IMG_PATH = "./img/" + +enum EnumInitState { + Tile, + Token, + Harbor, + PlayerColor, + PlayerOrder, + Build, + End, +} + +enum EnumResource { + Brick, + Lunber, + Wool, + Grain, + Ore, + Desert, +} + +const RESOURCE_NAMES: string[] = [ + "brick", + "lumber", + "wool", + "grain", + "ore", + "desert", +]; + +const HARBOR_NAMES: string[] = [ + "brick", + "lumber", + "wool", + "grain", + "ore", + "3_1", +]; + +enum EnumPlayerColors { + Red, + Blue, + Orange, + White, +} + +const PLAYER_COLORS: string[] = [ + "red", + "blue", + "orange", + "white," +]; + +enum EnumActions { + Knight, + Plenty, + Road, + Monopoly, + Point, +} + +const ACTION_NAMES: string[] = [ + "knight", + "plenty", + "road", + "monopoly", + "point", +]; + +enum EnumControllerTab { + Dice, + Action, + Build, + Domestic, + Maritime, + Victory, +} + +const CONTROLLER_TAB_NAMES: string[] = [ + "dice", + "action", + "build", + "domestic_trade", + "maritime_trade", +]; + +enum EnumBuild { + Road, + Settlement, + City, + Development, +} + +const BUILD_NAMES: string[] = [ + "road", + "settlement", + "city", + "development", +]; \ No newline at end of file diff --git a/image.js b/domImage.js similarity index 71% rename from image.js rename to domImage.js index 3546807..6572c20 100644 --- a/image.js +++ b/domImage.js @@ -1,53 +1,3 @@ -var Asset = {} - -// アセットの定義 -Asset.assets = []; - -// 読み込んだ画像 -Asset.images = {}; - -//アセットをimgタグからImageを作成 -function initAssets(){ - //リソース選択パネル - // for (var i = 0; i < RESOURCE_NAMES.length; i++) { - // var name = RESOURCE_NAMES[i]; - // var src = "./img/" + RESOURCE_NAMES[i] + ".png"; - // Asset.assets.push( { type: 'image', name: name, src: src}); - // } - - //全てのimgタグを取ってきてAssetに格納 - assets = document.getElementsByTagName("img"); - for (var i = assets.length - 1; i >= 0; i--) { - id = assets[i].getAttribute("id"); - src= assets[i].getAttribute("src"); - Asset.assets.push( { type: 'image', id: id, src: src}); - } - - loadAssets(); -} - -//Imageを生成してAsset.images{}にpush -function loadAssets(){ - var total = Asset.assets.length; // アセットの合計数 - var loadCount = 0; // 読み込み完了したアセット数 - - function onLoad(asset,image){ - Asset.images[asset.id] = image; - } - - // すべてのアセットを読み込む - Asset.assets.forEach(function(asset) { - switch (asset.type) { - case 'image': - var image = new Image(); - image.src = asset.src; - image.onload = onLoad(asset,image); - break; - } - }); -} - - function makeImg(resouce_id,resouce_pass,resouce_name=undefined) { var img = document.createElement("img"); img.id = (resouce_name == undefined) ? resouce_id : resouce_name; diff --git a/manager/manager.ts b/manager/manager.ts new file mode 100644 index 0000000..331a546 --- /dev/null +++ b/manager/manager.ts @@ -0,0 +1,15 @@ +class Manager { + // やること + // turnの管理 + // 資源の配布 + // フィールドの管理 + // GUI情報の管理 + + public gameStart() { + this.init(); + } + + private init() { + + } +} \ No newline at end of file