diff --git a/twentyfortyeight/src/twentyfortyeight/Main.java b/twentyfortyeight/src/twentyfortyeight/Main.java index 19c4f13..1d765c2 100644 --- a/twentyfortyeight/src/twentyfortyeight/Main.java +++ b/twentyfortyeight/src/twentyfortyeight/Main.java @@ -3,18 +3,21 @@ package twentyfortyeight; import java.util.ArrayList; import java.util.List; import java.util.Random; +import javalib.impworld.*; import tester.Tester; // A game of 2048. -class Game { +class Game extends World { int score; Grid grid; Random rand; + WorldScene scene; - Game(int score, Grid grid, Random rand) { + Game(int score, Grid grid, Random rand, WorldScene scene) { this.score = score; this.grid = grid; this.rand = rand; + this.scene = scene; } // Convenience constructor for init with default settings. @@ -22,6 +25,9 @@ class Game { this.grid = new Grid(4, 4); this.score = 0; this.rand = new Random(); + this.scene = new WorldScene( + this.grid.w, this.grid.h + ); // TODO: Add proper scaling parameter. } // Convenience constructor for init with custom settings. @@ -29,7 +35,10 @@ class Game { this.grid = new Grid(w, h); this.score = 0; this.rand = new Random(seed); + this.scene = new WorldScene(this.grid.w, this.grid.h); } + + public WorldScene makeScene() { return null; } } // The grid in which the game is played. @@ -70,6 +79,14 @@ class Grid { // Get the value at the coords. Just for testing. int get(int x, int y) { return this.buf.get(this.w * y + x); } + + // Move all tiles in that direction until they can't move or combine any + // more. + void move(int d) { + // TODO: Don't assume right. + // Assume right. + for (int i = 0; i < this.h; i++) {} + } } class Examples { @@ -116,4 +133,22 @@ class Examples { t.checkExpect(regular.get(0, 0), 0); t.checkExpect(regular.get(3, 3), 0); } + + void testMoveLeft(Tester t) { + init(); + regular.set(1, 0, 16) + .set(2, 0, 16) + .set(3, 0, 32) + .set(0, 1, 4) + .set(1, 1, 4) + .set(4, 1, 2); + + // Move right. + regular.move(2); + + t.checkExpect(regular.get(2, 0), 32); + t.checkExpect(regular.get(3, 0), 32); + t.checkExpect(regular.get(2, 1), 8); + t.checkExpect(regular.get(3, 1), 2); + } }