public void BeginTestMethod() { const int CELL_SIZE = 20; // [px] const int COLS = 12; const int ROWS = 24; var cvs = new Canvas(); cvs.Width = COLS * CELL_SIZE; cvs.Height = ROWS * CELL_SIZE; target = new Field(cvs, COLS, ROWS, Piece.PC_SIZE / 2, Piece.PC_SIZE / 2, 1); }
public static void InitializeTarget(TestContext testContext) { if (ImageLoader.IsRegistered("Cells") == false) { ImageLoader.AddImage("Cells", new Uri(@"..\..\..\Pentia\Resources\Cells.png", UriKind.Relative)); } const int CELL_SIZE = 20; // [px] const int COLS = 12; const int ROWS = 24; var cvs = new Canvas(); cvs.Width = COLS * CELL_SIZE; cvs.Height = ROWS * CELL_SIZE; field = new Field(cvs, COLS, ROWS, Piece.PC_SIZE / 2, Piece.PC_SIZE / 2, 1); }
public Board(Field field, Field nextField) { this.IsGameOver = false; this.field = field; this.nextField = nextField; pieceQueue = new Queue<Piece>(); this.rand = new Random(); this.piece = createPiece(field, field.COLS / 2, 0); var nextPiece = createPiece(nextField, nextField.COLS / 2, nextField.ROWS / 2); pieceQueue.Enqueue(nextPiece); nextField.Draw(); }
public void BeginTestMethod() { const int CELL_SIZE = 20; const int COLS = 12; const int ROWS = 24; var cvs = new Canvas(); cvs.Width = Piece.PC_SIZE * CELL_SIZE; cvs.Height = Piece.PC_SIZE * CELL_SIZE; var nextField = new Field(cvs, Piece.PC_SIZE, Piece.PC_SIZE); cvs = new Canvas(); cvs.Width = COLS * CELL_SIZE; cvs.Height = ROWS * CELL_SIZE; var field = new Field(cvs, COLS, ROWS, Piece.PC_SIZE / 2, Piece.PC_SIZE / 2, 1); target = new Board(field, nextField); }
public Renderer(Field field, int dispWallThickness = 0) { this.field = field; this.cols = field.COLS; this.rows = field.ROWS; this.yOffset = field.yOffset; this.wallThickness = (0 < field.wallThickness) ? dispWallThickness : 0; this.rcCells = new Rectangle[cols + wallThickness * 2, rows + wallThickness]; this.cellWidth = (int)(field.canvas.Width / (cols + wallThickness * 2)); this.cellHeight = (int)(field.canvas.Height / (rows + wallThickness)); rgColor = new RectangleGeometry[(int)PcColor.Leng]; for (int i = 0; i < rgColor.Length; i++) { rgColor[i] = new RectangleGeometry(new Rect(i * cellWidth, 0, cellWidth, cellHeight)); } for (int j = 0; j < rows + wallThickness; j++) { for (int i = 0; i < cols + wallThickness * 2; i++) { rcCells[i, j] = new Rectangle(); ImageLoader.LoadImage("Cells", rcCells[i, j]); int c = (int)PcColor.None; rcCells[i, j].Clip = rgColor[c]; Canvas.SetLeft(rcCells[i, j], (i - c) * cellWidth); Canvas.SetTop(rcCells[i, j], j * cellHeight); field.canvas.Children.Add(rcCells[i, j]); } } if (0 < wallThickness) { setWalls(); } }
public void Initialize(GamePage page) { this.page = page; setResources(); this.timer = new DispatcherTimer(); timer.Tick += this.OnTick; timer.Interval = new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 1, milliseconds: 0); this.page.MainWnd.KeyDown += this.OnKeyDown; // Generate model objects var field = new Field(this.page.cvField, cols:12, rows:24, yOffset: Piece.PC_SIZE / 2, wallThickness: Piece.PC_SIZE / 2, dispWallThickness: 1); var nextField = new Field(this.page.cvNextField, cols: Piece.PC_SIZE, rows: Piece.PC_SIZE); board = new Board(field, nextField); recorder = new Recorder(); setBinding(); this.Reset(); }
public Piece(Field field, int x, int y, PcType type, PcColor? color= null) { this.Field = field; this.pos = new NPoint(x, y); this.Color = color ?? PC_CLRS[(int)type]; var PcShp = PC_SHPS[(int)type]; this.Shape = new NPoint[PcShp.Length]; PcShp.CopyTo(this.Shape, 0); }
private Piece createPiece(Field field, int x, int y, PcType type = PcType.Random) { if (type == PcType.Random) { type = (PcType)rand.Next((int)PcType.Leng); } var piece = new Piece(field, x, y, type); field.PutPiece(piece); return piece; }