public static GF2 Mul(GF2 a, GF2 b) { // GF(2)の乗算: and int v = a.Val & b.Val; return(sInstance[v]); }
public static GF2 Add(GF2 a, GF2 b) { // GF(2)の加算: xor int v = a.Val ^ b.Val; return(sInstance[v]); }
private void NewGame() { Game = new TetrisGame(); Game.StateChanged += new EventHandler(Game_StateChanged); SetScore(0); SetScore2(0); GameTimer.Interval = 700; GameTimer.Enabled = true; Game.NextFigure = Figure.RandomFigure(); Game.NextFigure2 = Figure.RandomFigure(); GF.Clear(); GF2.Clear();//////// Refresh(); }
// private void GameFieldPictureBox2_Paint(object sender, PaintEventArgs e) { GF2.Paint(e.Graphics); if (Game.Paused) { Rectangle img = new Rectangle((GameFieldPictureBox2.Width - PausedImage.Width) / 2, (GameFieldPictureBox2.Height - PausedImage.Height) / 2, PausedImage.Width, PausedImage.Height); e.Graphics.DrawImage(PausedImage, img); return; } if (Game.GameOver) { Rectangle img = new Rectangle((GameFieldPictureBox2.Width - GameOverImage.Width) / 2, (GameFieldPictureBox2.Height - GameOverImage.Height) / 2, GameOverImage.Width, GameOverImage.Height); e.Graphics.DrawImage(GameOverImage, img); } }
/// <summary> /// 自分自身は変更しない。 /// 戻り値 := this + a /// </summary> public GF2 Mul(GF2 a) { return(GF2.Mul(this, a)); }
/// <summary> /// 自分自身は変更しない。 /// 戻り値 := this + a /// </summary> public GF2 Add(GF2 a) { return(GF2.Add(this, a)); }
// Input processing void MainFormKeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = true; if (Game.GameOver || Game.Paused) { return; } if (e.KeyData == Keys.A) { GF.MoveLeft(); } if (e.KeyData == Keys.NumPad1) { GF2.MoveLeft(); } if (e.KeyData == Keys.D) { GF.MoveRight(); } if (e.KeyData == Keys.NumPad3) { GF2.MoveRight(); } if (e.KeyData == Keys.W) { if (GF.Drop()) { SetScore(Game.Score + 5); } } if (e.KeyData == Keys.NumPad5) { if (GF2.Drop()) { SetScore2(Game.Score2 + 5); } } if (e.KeyData == Keys.S) { if (GF.MoveDown()) { SetScore(Game.Score + 1); } } if (e.KeyData == Keys.NumPad2) { if (GF2.MoveDown()) { SetScore2(Game.Score2 + 1); } } if (e.KeyData == Keys.Space) { GF.RotateFigure(); } if (e.KeyData == Keys.Enter) { GF2.RotateFigure(); } if (e.KeyData == Keys.Q) { if (!Game.FigureChanged && GF.IsFigureFalling) { Game.NextFigure = new Figure(GF.ChangeFigure(Game.NextFigure).Type); Preview.Clear(); Preview.SetFigure(Game.NextFigure.MoveTo(1, 1), false); Game.FigureChanged = true; if (Game.NextFigure == Figure.Zero) { OnGameOver(); } } if (Game.FigureChanged) { ShowAdvice(0); } } if (e.KeyData == Keys.NumPad4) { if (!Game.FigureChanged2 && GF2.IsFigureFalling) { Game.NextFigure2 = new Figure(GF2.ChangeFigure(Game.NextFigure2).Type); Preview2.Clear(); Preview2.SetFigure(Game.NextFigure2.MoveTo(1, 1), false); Game.FigureChanged2 = true; if (Game.NextFigure2 == Figure.Zero) { OnGameOver(); } } if (Game.FigureChanged2) { ShowAdvice2(0); } } Refresh(); }
// Game cycle void GameTimerTick(object sender, EventArgs e) { if (Game.Paused) { return; } GF.DoStep(); GF2.DoStep();/////// if (!GF.IsFigureFalling) { //you need to put a new figure on the field and hide the full rows SetScore(Game.Score + GF.RemoveFullRows() * 10); if (!GF.PlaceFigure(Game.NextFigure)) { //game over OnGameOver(); } else { Game.NextFigure = Figure.RandomFigure(); Game.FiguresDropped++; FiguresLabel.Text = Game.FiguresDropped.ToString(); Preview.Clear(); Preview.SetFigure(Game.NextFigure.MoveTo(1, 1), false); if (Game.FigureChanged && Game.FiguresDropped % 5 == 0) { Game.FigureChanged = false; } //speed up the game with increasing points if (Game.FiguresDropped % 15 == 0 && Game.Score != 0) { if (GameTimer.Interval > 300) { //GameTimer.Enabled=false; GameTimer.Interval -= 100; //GameTimer.Enabled=true; } } ShowAdvice(); } } // if (!GF2.IsFigureFalling) { //you need to put a new figure on the field and hide the full rows SetScore2(Game.Score2 + GF2.RemoveFullRows() * 10); if (!GF2.PlaceFigure(Game.NextFigure2)) { //game over OnGameOver(); } else { Game.NextFigure2 = Figure.RandomFigure(); Game.FiguresDropped2++; FiguresLabel2.Text = Game.FiguresDropped2.ToString(); Preview2.Clear(); Preview2.SetFigure(Game.NextFigure2.MoveTo(1, 1), false); if (Game.FigureChanged2 && Game.FiguresDropped2 % 5 == 0) { Game.FigureChanged2 = false; } //speed up the game with increasing points if (Game.FiguresDropped2 % 15 == 0 && Game.Score2 != 0) { if (GameTimer.Interval > 300) { //GameTimer.Enabled=false; GameTimer.Interval -= 100; //GameTimer.Enabled=true; } } ShowAdvice2(); } }// ElapsedTimeLabel.Text = (DateTime.Now - Game.GameStarted).ToString(@"mm\:ss"); ElapsedTimeLabel2.Text = (DateTime.Now - Game.GameStarted).ToString(@"mm\:ss"); Refresh(); }