public void setup(TetrisForm form, bool ismultiplayer, Random ownRandom, Random otherRandom) { tetrisForm = form; //Set multiplayer isMultiplayer = ismultiplayer; //Set gamesize gameSize = new Size(10, 15); // sideways, downwards //Set tetrisForm size tetrisForm.setGameSize(gameSize, isMultiplayer); //Get local box localPlayer = new TetrisPlayer(tetrisForm.getLocalPlayerBox(), gameSize, ownRandom); //Set paint event tetrisForm.getLocalPlayerBox().Paint += (o, args) => paintForPlayer(args, localPlayer, true); //Set keypress event tetrisForm.getPreviewPanel().Paint += paintPreview; tetrisForm.KeyPress += keyBoardHandler; //If multiplayer active create other player and set paint event if (isMultiplayer) { otherPlayer = new TetrisPlayer(tetrisForm.getOtherPlayerBox(), gameSize, otherRandom); tetrisForm.getOtherPlayerBox().Paint += (o, args) => paintForPlayer(args, otherPlayer, false); } //Start timer startTimer(); }
public Tetromino(TetrisPlayer Player) { //Set game this.Player = Player; //Random color and size pieceMatrix = getRandPiece(); setRandColor(); //Set random point thats slightly visible do { position = new Point(Player.rnd.Next(7) + 1, -2); } while (!canMove(0, 0)); //Rotate randomly for (var i = 0; i < Player.rnd.Next(3); i++) { rotateMatrix(pieceMatrix, 3, true); } }
/* * Drawing * Each 'player' has their own logic. */ public void paintForPlayer(PaintEventArgs e, TetrisPlayer player, bool drawScore) { //Draw game Graphics g = e.Graphics; //New Graphics Object //Get box PictureBox drawingBox = player.getBox(); //Draw moving piece player.thisTetromino().drawGhost(g); player.thisTetromino().draw(g); //Draw all blocks foreach (TetrisBlock block in player.tetrisBlocks.ToArray()) // (SignalData error?) https://stackoverflow.com/questions/604831/collection-was-modified-enumeration-operation-may-not-execute { block.draw(g, false); } //Draw Score if (drawScore) { tetrisForm.setPanelInfo(player.playerScore, player.state, steps); } }