-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.coffee
88 lines (82 loc) · 2.1 KB
/
test.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict'
class CanvasHolder
constructor: (@canvas) ->
@ctx = @canvas.getContext('2d')
class Board extends CanvasHolder
constructor: (canvas) ->
super(canvas)
@background = @ctx.createRadialGradient(350, 223, 0, 350, 223, 700)
@background.addColorStop(0, '#fff')
@background.addColorStop(1, '#000')
@lock = false
@gamestate = 1
@menu = new Menu(canvas)
draw: ->
@ctx.clearRect(0, 0, @canvas.width, @canvas.height)
@ctx.fillStyle = @background
@ctx.fillRect(0, 0, 700, 700)
switch @gamestate
when 1 then @menu.draw()
handleEvent: (event) ->
mx = e.pageX
my = e.pageY
if not @lock
switch @gamestate
when 1 then if @menu.isClicked(mc, my)
@startGame()
logic: =>
@draw()
startGame: ->
@deck = new Deck()
@player = new Player()
@opponent = new Opponent()
init: =>
self = @
@flow = setInterval(self.logic, 100)
class Deck extends CanvasHolder
constructor: (canvas) ->
super(canvas)
@cards = []
require(deck)
@cards.push(new Card())
class Menu extends CanvasHolder
draw: ->
Text.fillText(@ctx, Text.title, 'Hanafuda', @canvas.width / 2, 140)
Text.fillText(@ctx, Text.pica, 'Start', @canvas.width / 2, 250)
isClicked: (mx, my) ->
if (mx > (@canvas.width / 2) - 100 and mx < (canvas.width / 2) + 100 and my > 250 and my < 300)
true
else
false
class Text
@title: (ctx) ->
ctx.fillStyle = 'black'
ctx.textAlign = 'center'
ctx.textBaseline = 'top'
ctx.font = '67pt Stencil'
@pica: (ctx) ->
ctx.fillStyle = 'black'
ctx.textAlign = 'center'
ctx.textBaseline = 'top'
ctx.font = '30pt IM Fell DW Pica SC'
@set: (ctx) ->
ctx.fillStyle = 'black'
ctx.textAlign = 'left'
ctx.font = '10pt IM Fell DW Pica SC'
ctx.textBaseline = 'top'
@score: (ctx) ->
ctx.fillStyle = 'black'
ctx.textAlign = 'left'
ctx.font = '18pt IM Fell DW Pica SC'
ctx.textBaseline = 'top'
@fillText: (ctx, fun, str, x, y) ->
fun(ctx)
ctx.fillText(str, x, y)
@strokeText: (ctx, fun, str, x, y) ->
fun(ctx)
ctx.strokeText(str, x, y)
$('document').ready ->
canvas = $('canvas')[0]
board = new Board(canvas)
canvas.click(board.handleEvent)
board.init()