// private int mNumberOfBlocks = 4; public Playfield() { for (int aXPosition = 0; aXPosition < mWidth; aXPosition++) { for (int aYPosition = 0; aYPosition < mHeight; aYPosition++) { bPlayfield[aXPosition, aYPosition] = new Block(); } } }
private List<Block> getblockset(Block b) { if (b.linked) { //the blocks linked so add the whole set for (int i = 0; i < linkedblocks.Count; i++) { if (linkedblocks[i].Contains(b)) { return linkedblocks[i]; } } } return new List<Block>(); }
public void Rotate_Grid_Clockwise() { //clockwise turn Block[,] newbPlayfield = new Block[mWidth, mHeight]; //this performs a rotation of all blocks clockwise for (int x = 0; x < 16; x++) { for (int y = 4; y < 20; y++) { newbPlayfield[19 - y , x+4] = bPlayfield[x, y]; } } //copy the new array over for (int x = 0; x < 16; x++) { for (int y = 4; y < 20; y++) { // mPlayfield[x, y] = newPlayfield[x,y]; bPlayfield[x, y] = newbPlayfield[x, y]; } } }
public void Rotate_Grid() { //counterclockwise turn Block[,] newbPlayfield = new Block[mWidth, mHeight]; /* for (int aXPosition = 0; aXPosition < mWidth; aXPosition++) { for (int aYPosition = 0; aYPosition < mHeight; aYPosition++) { newbPlayfield[aXPosition, aYPosition] = new Block(); } } */ for (int x=0; x < 16; x++) { for (int y = 4; y < 20; y++) {//move the peice from the old spot to the new spot // newPlayfield[y-4,19-x]= mPlayfield[x, y]; // newbPlayfield[y - 4, 19 - x].Type = Block.BlockType.NotSet; newbPlayfield[y - 4, 19 - x] = bPlayfield[x, y]; } } //copy the new array over for (int x = 0; x < 16; x++) { for (int y = 4; y < 20; y++) { // mPlayfield[x, y] = newPlayfield[x,y]; bPlayfield[x, y] = newbPlayfield[x, y]; } } }
public void Gravity() { //Gravity function current will drop all blocks with nothing under them or if they are not linked //down 1 each time its called // Block[,] gfield = new Block[16, 20];//temporary field of the new positions //keep track of the blocks that are not going to fall List<Block> notfallingblocks=new List<Block>(); //start at the bottom Block currentblock; Block blockabove; //Boolean blockfalls ; List<Block> currentset =new List<Block>(); //the first row is going no where for (int j = 0; j < Width; j++) { currentblock = bPlayfield[j, 19]; if (currentblock.Type != Block.BlockType.NotSet) { if (currentblock.linked) { //the blocks linked so add the whole set for (int i = 0; i < linkedblocks.Count; i++) { if (linkedblocks[i].Contains(currentblock)) { currentset = linkedblocks[i]; break; } } for (int r = 0; r < currentset.Count; r++) { notfallingblocks.Add(currentset[r]); } } else //not a set so just add the single block notfallingblocks.Add(currentblock); } } //now starting at the bottom of the grid //if there is a block above and the current block is not a falling block //then above block will not be fallling either //if it is a set then the whole set will not be falling either // Block currentblock; // Block blockabove; //Boolean blockfalls ; // List<Block> currentset =new List<Block>(); for (int y = mHeight - 1; y >= 4; y--)//start at the second row from the bottom { for (int x = 0; x < mWidth; x++) { currentblock=bPlayfield[x,y]; // blockfalls = false; if(currentblock.Type!=Block.BlockType.NotSet)//if there is a block then check to see if it should move down {//current block exists blockabove = bPlayfield[x, y - 1]; if (blockabove.Type != Block.BlockType.NotSet) {//the block above exists if (notfallingblocks.Contains(currentblock)) {//the block above must not fall either if(notfallingblocks.Contains(blockabove)) {// the blocks allready in the list //move along } else { if (blockabove.linked) { //the blocks linked so add the whole set for (int i = 0; i < linkedblocks.Count; i++) { if (linkedblocks[i].Contains(blockabove)) { currentset = linkedblocks[i]; break; } } for (int r = 0; r < currentset.Count; r++) { notfallingblocks.Add(currentset[r]); } } else //not a set so just add the single block notfallingblocks.Add(blockabove); } } } } } } //now loop through again and move everything down that is not in the do not fall list for (int y = mHeight - 2; y >= 4; y--)//start at the second row from the bottom { for (int x = 0; x < mWidth; x++) { currentblock = bPlayfield[x, y]; if (currentblock.Type!=Block.BlockType.NotSet&& notfallingblocks.Contains(currentblock) == false) { //then move the block down bPlayfield[x, y+1]=currentblock; bPlayfield[x, y] = new Block(); } } } }
public Vector2 getblockposition(Block b) { int x=0; int y=0; for (y = mHeight - 1; y >= 4; y--)//start at the second row from the bottom { for (x = 0; x < mWidth; x++) { if (bPlayfield[x, y].Equals(b)) return new Vector2(x, y); } } return new Vector2(x, y); }
//Description: Clear the playfield public void ClearPlayfield() { bPlayfield = new Block[mWidth, mHeight]; for (int aYPosition = 0; aYPosition < mHeight; aYPosition++) { for (int aXPosition = 0; aXPosition < mWidth; aXPosition++) { // mPlayfield[aXPosition, aYPosition] = -1; bPlayfield[aXPosition, aYPosition] = new Block(); } } }
public void copy(Block b) { Type = b.Type; //linkedblocks.AddRange(b.linkedblocks); }