Game - Create Grid Iteration Function

This commit is contained in:
Marty Oehme 2018-07-20 14:05:48 +02:00
parent 96a776c60b
commit cf12eb8823

View file

@ -1,5 +1,7 @@
import 'dart:html'; import 'dart:html';
typedef void gridIterator(int x, int y);
class Game { class Game {
List<List<Color>> grid; List<List<Color>> grid;
CanvasElement canvas; CanvasElement canvas;
@ -19,25 +21,26 @@ class Game {
int brickW = (canvas.width ~/ grid[0].length); int brickW = (canvas.width ~/ grid[0].length);
int brickH = (canvas.height ~/ grid.length); int brickH = (canvas.height ~/ grid.length);
ctx.setFillColorRgb(255, 0,0);
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
grid_foreach((x, y) {
Color col = grid[y][x];
ctx.setFillColorRgb(col.r+_oscill, col.g+_oscill, col.b+_oscill);
ctx.fillRect(x*brickW, y*brickH, brickW, brickH);
});
}
Color _oscillate(Color) {}
void grid_foreach(gridIterator fun) {
for (int y = 0; y < grid.length; y++) { for (int y = 0; y < grid.length; y++) {
for (int x = 0; x < grid[y].length; x++) { for (int x = 0; x < grid[y].length; x++) {
Color col = grid[y][x]; fun(x, y);
ctx.setFillColorRgb(col.r, col.g, col.b);
ctx.fillRect(x*brickW, y*brickH, brickW, brickH);
} }
} }
} }
Color _oscillate(Color) {
}
List<List<Color>> buildGrid(int w, int h, Color col) { List<List<Color>> buildGrid(int w, int h, Color col) {
List<List<Color>> grid = new List(h); List<List<Color>> grid = new List(h);
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
grid[y] = new List(w); grid[y] = new List(w);
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
@ -54,7 +57,6 @@ class Color {
final int b; final int b;
const Color(this.r, this.g, this.b); const Color(this.r, this.g, this.b);
} }
// Create 2d array // Create 2d array