Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
checkers-canvas
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Vadym Gidulian
checkers-canvas
Commits
8a96882c
Commit
8a96882c
authored
Oct 27, 2016
by
Vadym Gidulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added colors and some game code
parent
49236dff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
29 deletions
+50
-29
script.js
script.js
+50
-29
No files found.
script.js
View file @
8a96882c
...
@@ -18,15 +18,57 @@ const FONT_WIDTH = 0.6 * FONT;
...
@@ -18,15 +18,57 @@ const FONT_WIDTH = 0.6 * FONT;
const
COLOR_BORDER_THICK
=
'#000'
;
const
COLOR_BORDER_THICK
=
'#000'
;
const
COLOR_BORDER_THIN
=
'#000'
;
const
COLOR_BORDER_THIN
=
'#000'
;
const
COLOR_BORDER_LETTERS
=
'#fff'
;
const
COLOR_LETTERS
=
'#000'
;
const
COLOR_LETTERS
=
'#000'
;
const
COLOR_SQUARE_BLACK
=
'#000'
;
const
COLOR_SQUARE_BLACK
=
'#000'
;
const
COLOR_SQUARE_WHITE
=
'#fff'
;
const
COLOR_SQUARE_WHITE
=
'#fff'
;
const
COLOR_PIECE_BLACK
=
'#000'
;
const
COLOR_PIECE_BLACK
=
'#000'
;
const
COLOR_PIECE_WHITE
=
'#fff'
;
const
COLOR_PIECE_WHITE
=
'#fff'
;
init
();
const
game
=
{
drawGameBoard
();
pieces
:
[
drawPieces
();
{
position
:
'A1'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'A3'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'B2'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'C1'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'C3'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'D2'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'E1'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'E3'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'F2'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'G1'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'G3'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'H2'
,
color
:
'black'
,
isKing
:
false
},
{
position
:
'A7'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'B6'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'B8'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'C7'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'D6'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'D8'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'E7'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'F6'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'F8'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'G7'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'H6'
,
color
:
'white'
,
isKing
:
false
},
{
position
:
'H8'
,
color
:
'white'
,
isKing
:
false
}
]
};
gameStart
();
// Game
function
gameStart
()
{
init
();
gameUpdate
();
}
function
gameUpdate
()
{
drawGameBoard
();
drawPieces
();
}
// Graphics
function
init
()
{
function
init
()
{
ctx
=
canvas
.
getContext
(
'2d'
);
ctx
=
canvas
.
getContext
(
'2d'
);
...
@@ -36,7 +78,8 @@ function drawGameBoard() {
...
@@ -36,7 +78,8 @@ function drawGameBoard() {
// Borders
// Borders
ctx
.
fillStyle
=
COLOR_BORDER_THICK
;
ctx
.
fillStyle
=
COLOR_BORDER_THICK
;
ctx
.
fillRect
(
0
,
0
,
SIZE
,
SIZE
);
ctx
.
fillRect
(
0
,
0
,
SIZE
,
SIZE
);
ctx
.
clearRect
(
THICK_BORDER
,
THICK_BORDER
,
SIZE
-
2
*
THICK_BORDER
,
SIZE
-
2
*
THICK_BORDER
);
ctx
.
fillStyle
=
COLOR_BORDER_LETTERS
;
ctx
.
fillRect
(
THICK_BORDER
,
THICK_BORDER
,
SIZE
-
2
*
THICK_BORDER
,
SIZE
-
2
*
THICK_BORDER
);
ctx
.
fillStyle
=
COLOR_BORDER_THIN
;
ctx
.
fillStyle
=
COLOR_BORDER_THIN
;
ctx
.
strokeRect
(
BORDER
,
BORDER
,
SIZE
-
2
*
BORDER
,
SIZE
-
2
*
BORDER
);
ctx
.
strokeRect
(
BORDER
,
BORDER
,
SIZE
-
2
*
BORDER
,
SIZE
-
2
*
BORDER
);
...
@@ -67,31 +110,9 @@ function drawGameBoard() {
...
@@ -67,31 +110,9 @@ function drawGameBoard() {
}
}
function
drawPieces
()
{
function
drawPieces
()
{
drawPiece
(
'A1'
,
'black'
);
game
.
pieces
.
forEach
(
function
(
piece
)
{
drawPiece
(
'A3'
,
'black'
);
drawPiece
(
piece
.
position
,
piece
.
color
,
piece
.
isKing
);
drawPiece
(
'B2'
,
'black'
);
});
drawPiece
(
'C1'
,
'black'
);
drawPiece
(
'C3'
,
'black'
);
drawPiece
(
'D2'
,
'black'
);
drawPiece
(
'E1'
,
'black'
);
drawPiece
(
'E3'
,
'black'
);
drawPiece
(
'F2'
,
'black'
);
drawPiece
(
'G1'
,
'black'
);
drawPiece
(
'G3'
,
'black'
);
drawPiece
(
'H2'
,
'black'
);
drawPiece
(
'A8'
,
'white'
);
drawPiece
(
'A6'
,
'white'
);
drawPiece
(
'B7'
,
'white'
);
drawPiece
(
'C8'
,
'white'
);
drawPiece
(
'C6'
,
'white'
);
drawPiece
(
'D7'
,
'white'
);
drawPiece
(
'E8'
,
'white'
);
drawPiece
(
'E6'
,
'white'
);
drawPiece
(
'F7'
,
'white'
);
drawPiece
(
'G8'
,
'white'
);
drawPiece
(
'G6'
,
'white'
);
drawPiece
(
'H7'
,
'white'
);
}
}
function
drawPiece
(
position
,
color
,
isKing
)
{
function
drawPiece
(
position
,
color
,
isKing
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment