Skip to content

Instantly share code, notes, and snippets.

View mohsenheydari's full-sized avatar

Mohsen Heydari mohsenheydari

View GitHub Profile
@mohsenheydari
mohsenheydari / draw-ttt-o.js
Created January 8, 2019 01:29
Draw O's in Tic Tac Toe Board
drawO(x, y){
let halfCellSize = (0.5 * this.cellSize);
let centerX = x + halfCellSize;
let centerY = y + halfCellSize;
let radius = (this.cellSize * 0.7) / 2;
let endAngle = 2 * Math.PI;
this.ctx.lineWidth = this.oLineWidth;
this.ctx.strokeStyle = this.oStyle;
this.ctx.beginPath();
@mohsenheydari
mohsenheydari / draw-ttt-x.js
Created January 8, 2019 01:28
Draw X's in Tic Tac Toe Board
drawX(x, y){
this.ctx.lineWidth = this.xLineWidth;
this.ctx.strokeStyle = this.xStyle;
this.ctx.beginPath();
let offset = this.cellSize * 0.25;
this.ctx.moveTo(x + offset, y + offset);
this.ctx.lineTo(x + this.cellSize - offset, y + this.cellSize - offset);
this.ctx.moveTo(x + offset, y + this.cellSize - offset);
@mohsenheydari
mohsenheydari / draw-ttt-cells.js
Created January 8, 2019 01:19
Draw Tic Tac Toe board cells based on array of states
drawCells(boardState){
boardState.forEach(function(el, i){
let x = (i % 3) * this.cellSize;
let y = Math.floor(i/3) * this.cellSize;
if(el === 1){
this.drawX(x, y);
} else if(el === 2){
this.drawO(x, y);
<div class="center-wrapper-parent">
<div class="canvas-wrapper">
<canvas id="board"></canvas>
</div>
</div>
<script data-main="js/main" src="js/require.js"></script>
@mohsenheydari
mohsenheydari / gameboardrenderer.js
Last active January 8, 2019 01:10
Tic Tac Toe GmaeBoardRenderer class structure
class GmaeBoardRenderer{
constructor(canvas, canvasSize){
...
}
render(boardState){
...
}
drawCells(boardState){