Skip to content

Instantly share code, notes, and snippets.

@Slemgrim Slemgrim/minefield.dart
Last active Aug 29, 2015

Embed
What would you like to do?
library minefield;
import 'dart:html';
class Minefield {
int _width; // Width of canvas
int _height; // Height of canvas
Element _container;
CanvasElement _canvas;
CanvasRenderingContext2D _ctx;
Minefield(this._container, [this._width = 320, this._height = 320]){
_setupCanvas();
}
void _setupCanvas(){
_canvas = new CanvasElement(width: _width, height: _height );
_ctx = _canvas.getContext('2d');
_container.style.width = '${_width}px';
_container.append(_canvas);
}
}
body {
margin: 0;
padding: 0;
background: #395D33;
color: #ffffff;
}
h1 {
text-align: center;
}
#container {
margin: 0 auto;
position: relative;
}
canvas {
display: block;
margin: 10px auto;
}
.game-message {
display: none;
width: 100%;
font-size: 60px;
text-align: center;
position: absolute;
top: 50%;
}
.game-message.show {
display: block;
}
import 'dart:html';
import 'game/minefield.dart';
void main() {
Element container = querySelector('#container');
Minefield minefield = new Minefield(container);
}
<!DOCTYPE html>
<html>
<head>
<title>Minefield</title>
<link rel="stylesheet" type="text/css" href="minefield_tutorial.css">
</head>
<body>
<!-- Game container -->
<div id="container">
<h1>Minefield</h1>
</div>
<script type="application/dart" src="minefield_tutorial.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.