private void TimerTask(object StateObject) { TimerStateObject State = (TimerStateObject)StateObject; if (State.b.pieceOffset < 0 && !State.hardDrop) { State.b.pieceOffset++; draw(); } else { State.b.pieceOffset = -gridSize; if (State.b.gameOver) { State.TimerReference.Dispose(); } if (State.b.currentPiece != null) { if (State.b.moveCurrent(Piece.Direction.Down) || State.hardDrop) { updateBoard(State.b); } State.hardDrop = false; draw(); } } }
public PuzzleFighterGame() { InitializeComponent(); this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); this.KeyPress += new KeyPressEventHandler(p1_KeyPress); this.KeyPress += new KeyPressEventHandler(p2_KeyPress); this.ResizeEnd += new EventHandler(PuzzleFighterGame_CreateBackBuffer); this.Load += new EventHandler(PuzzleFighterGame_CreateBackBuffer); this.Paint += new PaintEventHandler(PuzzleFighterGame_Paint); //this.FormClosing += new FormClosingEventHandler(PuzzleFighterGame_FormClosing); b1 = new Board(xSize, ySize, 1); b2 = new Board(xSize, ySize, 2); b1StateObject = new TimerStateObject(b1); b1StateObject.gridSize = gridSize; b2StateObject = new TimerStateObject(b2); b2StateObject.gridSize = gridSize; b1Timer = new System.Threading.Timer(new System.Threading.TimerCallback(TimerTask), b1StateObject, 0, pieceDropInterval / gridSize); b1StateObject.TimerReference = b1Timer; b2Timer = new System.Threading.Timer(new System.Threading.TimerCallback(TimerTask), b2StateObject, 0, pieceDropInterval / gridSize); b2StateObject.TimerReference = b2Timer; }