From 808e4cfb0c42b10710b589c795023d3d76998f4b Mon Sep 17 00:00:00 2001 From: ANAWIN ATHAWONG Date: Tue, 9 Oct 2018 16:10:40 +0700 Subject: [PATCH 1/5] added color --- TwoZeroFourEightController.cs | 9 ++- TwoZeroFourEightModel.cs | 4 +- TwoZeroFourEightView.Designer.cs | 126 ++++++++++++++++++++----------- TwoZeroFourEightView.cs | 30 +++++++- 4 files changed, 120 insertions(+), 49 deletions(-) diff --git a/TwoZeroFourEightController.cs b/TwoZeroFourEightController.cs index 36cb739..cff53de 100644 --- a/TwoZeroFourEightController.cs +++ b/TwoZeroFourEightController.cs @@ -12,21 +12,23 @@ class TwoZeroFourEightController : Controller public const int RIGHT = 1; public const int UP = 2; public const int DOWN = 3; - + public TwoZeroFourEightController() { } + + public override void ActionPerformed(int action) { foreach (TwoZeroFourEightModel m in mList) { switch (action) { - case LEFT: + case LEFT : m.PerformLeft(); - break; + break; case RIGHT: m.PerformRight(); break; @@ -40,5 +42,6 @@ public override void ActionPerformed(int action) } } + } } diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 2c70ab6..7ce6d5d 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -11,7 +11,7 @@ class TwoZeroFourEightModel : Model protected int boardSize; // default is 4 protected int[,] board; protected Random rand; - + bool checkOver; public TwoZeroFourEightModel() : this(4) { // default board size is 4 @@ -135,7 +135,9 @@ public void PerformUp() { buffer[j - 1] *= 2; buffer[j] = 0; + checkOver = true; } + else checkOver = false; } // shift left again pos = 0; diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index 8d079e6..703127d 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -48,6 +48,7 @@ private void InitializeComponent() this.btnUp = new System.Windows.Forms.Button(); this.btnRight = new System.Windows.Forms.Button(); this.btnDown = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lbl00 @@ -55,9 +56,10 @@ private void InitializeComponent() this.lbl00.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl00.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl00.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl00.Location = new System.Drawing.Point(19, 11); + this.lbl00.Location = new System.Drawing.Point(25, 14); + this.lbl00.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl00.Name = "lbl00"; - this.lbl00.Size = new System.Drawing.Size(51, 51); + this.lbl00.Size = new System.Drawing.Size(97, 93); this.lbl00.TabIndex = 0; this.lbl00.Text = "0"; // @@ -66,9 +68,10 @@ private void InitializeComponent() this.lbl01.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl01.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl01.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl01.Location = new System.Drawing.Point(76, 9); + this.lbl01.Location = new System.Drawing.Point(140, 14); + this.lbl01.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl01.Name = "lbl01"; - this.lbl01.Size = new System.Drawing.Size(51, 51); + this.lbl01.Size = new System.Drawing.Size(97, 93); this.lbl01.TabIndex = 1; this.lbl01.Text = "0"; // @@ -77,9 +80,10 @@ private void InitializeComponent() this.lbl02.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl02.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl02.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl02.Location = new System.Drawing.Point(140, 11); + this.lbl02.Location = new System.Drawing.Point(258, 14); + this.lbl02.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl02.Name = "lbl02"; - this.lbl02.Size = new System.Drawing.Size(51, 51); + this.lbl02.Size = new System.Drawing.Size(96, 93); this.lbl02.TabIndex = 2; this.lbl02.Text = "0"; // @@ -88,9 +92,10 @@ private void InitializeComponent() this.lbl03.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl03.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl03.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl03.Location = new System.Drawing.Point(209, 9); + this.lbl03.Location = new System.Drawing.Point(378, 14); + this.lbl03.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl03.Name = "lbl03"; - this.lbl03.Size = new System.Drawing.Size(51, 51); + this.lbl03.Size = new System.Drawing.Size(96, 93); this.lbl03.TabIndex = 3; this.lbl03.Text = "0"; // @@ -99,9 +104,10 @@ private void InitializeComponent() this.lbl13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl13.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl13.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl13.Location = new System.Drawing.Point(209, 74); + this.lbl13.Location = new System.Drawing.Point(378, 124); + this.lbl13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl13.Name = "lbl13"; - this.lbl13.Size = new System.Drawing.Size(51, 51); + this.lbl13.Size = new System.Drawing.Size(96, 93); this.lbl13.TabIndex = 7; this.lbl13.Text = "0"; // @@ -110,9 +116,10 @@ private void InitializeComponent() this.lbl12.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl12.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl12.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl12.Location = new System.Drawing.Point(142, 74); + this.lbl12.Location = new System.Drawing.Point(258, 124); + this.lbl12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl12.Name = "lbl12"; - this.lbl12.Size = new System.Drawing.Size(51, 51); + this.lbl12.Size = new System.Drawing.Size(96, 93); this.lbl12.TabIndex = 6; this.lbl12.Text = "0"; // @@ -121,9 +128,10 @@ private void InitializeComponent() this.lbl11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl11.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl11.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl11.Location = new System.Drawing.Point(76, 74); + this.lbl11.Location = new System.Drawing.Point(140, 124); + this.lbl11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl11.Name = "lbl11"; - this.lbl11.Size = new System.Drawing.Size(51, 51); + this.lbl11.Size = new System.Drawing.Size(97, 93); this.lbl11.TabIndex = 5; this.lbl11.Text = "0"; // @@ -132,9 +140,10 @@ private void InitializeComponent() this.lbl10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl10.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl10.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl10.Location = new System.Drawing.Point(19, 74); + this.lbl10.Location = new System.Drawing.Point(25, 124); + this.lbl10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl10.Name = "lbl10"; - this.lbl10.Size = new System.Drawing.Size(51, 51); + this.lbl10.Size = new System.Drawing.Size(97, 93); this.lbl10.TabIndex = 4; this.lbl10.Text = "0"; // @@ -143,9 +152,10 @@ private void InitializeComponent() this.lbl23.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl23.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl23.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl23.Location = new System.Drawing.Point(209, 138); + this.lbl23.Location = new System.Drawing.Point(378, 235); + this.lbl23.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl23.Name = "lbl23"; - this.lbl23.Size = new System.Drawing.Size(51, 51); + this.lbl23.Size = new System.Drawing.Size(96, 93); this.lbl23.TabIndex = 11; this.lbl23.Text = "0"; // @@ -154,9 +164,10 @@ private void InitializeComponent() this.lbl22.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl22.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl22.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl22.Location = new System.Drawing.Point(142, 138); + this.lbl22.Location = new System.Drawing.Point(258, 235); + this.lbl22.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl22.Name = "lbl22"; - this.lbl22.Size = new System.Drawing.Size(51, 51); + this.lbl22.Size = new System.Drawing.Size(96, 93); this.lbl22.TabIndex = 10; this.lbl22.Text = "0"; // @@ -165,9 +176,10 @@ private void InitializeComponent() this.lbl21.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl21.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl21.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl21.Location = new System.Drawing.Point(82, 138); + this.lbl21.Location = new System.Drawing.Point(140, 235); + this.lbl21.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl21.Name = "lbl21"; - this.lbl21.Size = new System.Drawing.Size(51, 51); + this.lbl21.Size = new System.Drawing.Size(96, 93); this.lbl21.TabIndex = 9; this.lbl21.Text = "0"; // @@ -176,9 +188,10 @@ private void InitializeComponent() this.lbl20.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl20.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl20.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl20.Location = new System.Drawing.Point(19, 138); + this.lbl20.Location = new System.Drawing.Point(25, 235); + this.lbl20.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl20.Name = "lbl20"; - this.lbl20.Size = new System.Drawing.Size(51, 51); + this.lbl20.Size = new System.Drawing.Size(97, 93); this.lbl20.TabIndex = 8; this.lbl20.Text = "0"; // @@ -187,9 +200,10 @@ private void InitializeComponent() this.lbl33.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl33.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl33.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl33.Location = new System.Drawing.Point(209, 201); + this.lbl33.Location = new System.Drawing.Point(378, 347); + this.lbl33.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl33.Name = "lbl33"; - this.lbl33.Size = new System.Drawing.Size(51, 51); + this.lbl33.Size = new System.Drawing.Size(96, 93); this.lbl33.TabIndex = 15; this.lbl33.Text = "0"; // @@ -198,9 +212,10 @@ private void InitializeComponent() this.lbl32.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl32.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl32.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl32.Location = new System.Drawing.Point(142, 201); + this.lbl32.Location = new System.Drawing.Point(258, 347); + this.lbl32.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl32.Name = "lbl32"; - this.lbl32.Size = new System.Drawing.Size(51, 51); + this.lbl32.Size = new System.Drawing.Size(96, 93); this.lbl32.TabIndex = 14; this.lbl32.Text = "0"; // @@ -209,9 +224,10 @@ private void InitializeComponent() this.lbl31.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl31.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl31.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl31.Location = new System.Drawing.Point(82, 201); + this.lbl31.Location = new System.Drawing.Point(140, 347); + this.lbl31.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl31.Name = "lbl31"; - this.lbl31.Size = new System.Drawing.Size(51, 51); + this.lbl31.Size = new System.Drawing.Size(96, 93); this.lbl31.TabIndex = 13; this.lbl31.Text = "0"; // @@ -220,17 +236,19 @@ private void InitializeComponent() this.lbl30.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl30.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl30.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl30.Location = new System.Drawing.Point(19, 201); + this.lbl30.Location = new System.Drawing.Point(25, 347); + this.lbl30.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lbl30.Name = "lbl30"; - this.lbl30.Size = new System.Drawing.Size(51, 51); + this.lbl30.Size = new System.Drawing.Size(97, 93); this.lbl30.TabIndex = 12; this.lbl30.Text = "0"; // // btnLeft // - this.btnLeft.Location = new System.Drawing.Point(85, 336); + this.btnLeft.Location = new System.Drawing.Point(154, 494); + this.btnLeft.Margin = new System.Windows.Forms.Padding(4); this.btnLeft.Name = "btnLeft"; - this.btnLeft.Size = new System.Drawing.Size(53, 45); + this.btnLeft.Size = new System.Drawing.Size(71, 55); this.btnLeft.TabIndex = 16; this.btnLeft.Text = "<"; this.btnLeft.UseVisualStyleBackColor = true; @@ -238,9 +256,10 @@ private void InitializeComponent() // // btnUp // - this.btnUp.Location = new System.Drawing.Point(140, 307); + this.btnUp.Location = new System.Drawing.Point(228, 458); + this.btnUp.Margin = new System.Windows.Forms.Padding(4); this.btnUp.Name = "btnUp"; - this.btnUp.Size = new System.Drawing.Size(53, 45); + this.btnUp.Size = new System.Drawing.Size(71, 55); this.btnUp.TabIndex = 17; this.btnUp.Text = "^"; this.btnUp.UseVisualStyleBackColor = true; @@ -248,9 +267,10 @@ private void InitializeComponent() // // btnRight // - this.btnRight.Location = new System.Drawing.Point(195, 336); + this.btnRight.Location = new System.Drawing.Point(301, 494); + this.btnRight.Margin = new System.Windows.Forms.Padding(4); this.btnRight.Name = "btnRight"; - this.btnRight.Size = new System.Drawing.Size(53, 45); + this.btnRight.Size = new System.Drawing.Size(71, 55); this.btnRight.TabIndex = 18; this.btnRight.Text = ">"; this.btnRight.UseVisualStyleBackColor = true; @@ -258,19 +278,34 @@ private void InitializeComponent() // // btnDown // - this.btnDown.Location = new System.Drawing.Point(140, 371); + this.btnDown.Location = new System.Drawing.Point(228, 537); + this.btnDown.Margin = new System.Windows.Forms.Padding(4); this.btnDown.Name = "btnDown"; - this.btnDown.Size = new System.Drawing.Size(53, 45); + this.btnDown.Size = new System.Drawing.Size(71, 55); this.btnDown.TabIndex = 19; this.btnDown.Text = "v"; this.btnDown.UseVisualStyleBackColor = true; this.btnDown.Click += new System.EventHandler(this.btnDown_Click); // - // Form1 + // label1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.label1.AccessibleName = "gameover"; + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 194); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(521, 91); + this.label1.TabIndex = 20; + this.label1.Text = "GAME OVER"; + this.label1.Visible = false; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // TwoZeroFourEightView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(344, 428); + this.ClientSize = new System.Drawing.Size(598, 658); + this.Controls.Add(this.label1); this.Controls.Add(this.btnDown); this.Controls.Add(this.btnRight); this.Controls.Add(this.btnUp); @@ -291,9 +326,11 @@ private void InitializeComponent() this.Controls.Add(this.lbl02); this.Controls.Add(this.lbl01); this.Controls.Add(this.lbl00); - this.Name = "Form1"; + this.Margin = new System.Windows.Forms.Padding(4); + this.Name = "TwoZeroFourEightView"; this.Text = "Form1"; this.ResumeLayout(false); + this.PerformLayout(); } @@ -319,6 +356,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnUp; private System.Windows.Forms.Button btnRight; private System.Windows.Forms.Button btnDown; + private System.Windows.Forms.Label label1; } } diff --git a/TwoZeroFourEightView.cs b/TwoZeroFourEightView.cs index 8201edf..8fbeb99 100644 --- a/TwoZeroFourEightView.cs +++ b/TwoZeroFourEightView.cs @@ -52,8 +52,32 @@ private void UpdateTile(Label l, int i) case 8: l.BackColor = Color.Red; break; + case 16: + l.BackColor = Color.Yellow; + break; + case 32: + l.BackColor = Color.Blue; + break; + case 64: + l.BackColor = Color.Brown; + break; + case 128: + l.BackColor = Color.LawnGreen; + break; + case 256: + l.BackColor = Color.Indigo; + break; + case 512: + l.BackColor = Color.Moccasin; + break; + case 1024: + l.BackColor = Color.MediumSlateBlue; + break; + case 2048: + l.BackColor = Color.Purple; + break; default: - l.BackColor = Color.Green; + l.BackColor = Color.Goldenrod; break; } } @@ -97,5 +121,9 @@ private void btnDown_Click(object sender, EventArgs e) controller.ActionPerformed(TwoZeroFourEightController.DOWN); } + private void label1_Click(object sender, EventArgs e) + { + + } } } From fbe6e9c06494129aecdd24cdb4d83fd96879d3f5 Mon Sep 17 00:00:00 2001 From: ANAWIN ATHAWONG Date: Tue, 16 Oct 2018 17:20:59 +0700 Subject: [PATCH 2/5] !finish --- Controller.cs | 1 + TwoZeroFourEightController.cs | 7 ++- TwoZeroFourEightModel.cs | 94 +++++++++++++++++++++++++++++--- TwoZeroFourEightView.Designer.cs | 19 +++++++ TwoZeroFourEightView.cs | 19 ++++++- 5 files changed, 128 insertions(+), 12 deletions(-) diff --git a/Controller.cs b/Controller.cs index 036a13a..49ef6e8 100644 --- a/Controller.cs +++ b/Controller.cs @@ -9,6 +9,7 @@ namespace twozerofoureight class Controller { protected ArrayList mList; + public Controller() { diff --git a/TwoZeroFourEightController.cs b/TwoZeroFourEightController.cs index cff53de..6b78e2b 100644 --- a/TwoZeroFourEightController.cs +++ b/TwoZeroFourEightController.cs @@ -12,7 +12,7 @@ class TwoZeroFourEightController : Controller public const int RIGHT = 1; public const int UP = 2; public const int DOWN = 3; - + public const int HIDE = 4; public TwoZeroFourEightController() { @@ -38,10 +38,13 @@ public override void ActionPerformed(int action) case DOWN: m.PerformDown(); break; + case HIDE: + m.PerformHide(); + break; + } } } - } } diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 7ce6d5d..b48785e 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -11,12 +11,22 @@ class TwoZeroFourEightModel : Model protected int boardSize; // default is 4 protected int[,] board; protected Random rand; - bool checkOver; + public int boardsize = 0; + public bool isfull = false; + public bool isCandown = false; + public bool isCanUp = false; + public bool isCanLeft = false; + public bool isCanRight = false; + public int score = 0; public TwoZeroFourEightModel() : this(4) { // default board size is 4 } + public int GetScore() + { + return score; + } public int[,] GetBoard() { return board; @@ -27,9 +37,11 @@ public TwoZeroFourEightModel(int size) boardSize = size; board = new int[boardSize, boardSize]; var range = Enumerable.Range(0, boardSize); - foreach(int i in range) { - foreach(int j in range) { - board[i,j] = 0; + foreach (int i in range) + { + foreach (int j in range) + { + board[i, j] = 0; } } rand = new Random(); @@ -37,18 +49,74 @@ public TwoZeroFourEightModel(int size) NotifyAll(); } + private void checkfull() + { + boardsize = 0; + isfull = false; + + for (int i =0;i<4;i++) + { + for (int j =0;j<4;j++) + { + if (board[j, i] != 0) + { + + boardsize++; + if (boardsize >= 16) + { + boardsize = 16; + if (isCanLeft && isCanRight && isCanUp && isCandown) + { + System.Windows.Forms.MessageBox.Show("Game Over"); + isfull = true; + } + break; + } + + } + score += board[i, j]; + } + } + + + + } + private int[,] Random(int[,] input) { while (true) { int x = rand.Next(boardSize); int y = rand.Next(boardSize); + + if (board[x, y] == 0) { board[x, y] = 2; break; } + else + { + + while (board[x, y] != 0) + { + x = rand.Next(boardSize); + y = rand.Next(boardSize); + if (board[x, y] == 0) break; + } + board[x, y] = 2; + + break; + } + + + + + } + + + checkfull(); return input; } @@ -58,6 +126,7 @@ public void PerformDown() int pos; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); + isCandown = false; Array.Reverse(rangeY); foreach (int i in rangeX) { @@ -83,6 +152,7 @@ public void PerformDown() { buffer[j - 1] *= 2; buffer[j] = 0; + isCandown = true; } } // shift left again @@ -109,7 +179,7 @@ public void PerformUp() { int[] buffer; int pos; - + isCanUp = false; int[] range = Enumerable.Range(0, boardSize).ToArray(); foreach (int i in range) { @@ -135,9 +205,10 @@ public void PerformUp() { buffer[j - 1] *= 2; buffer[j] = 0; - checkOver = true; + isCanUp = true; + } - else checkOver = false; + } // shift left again pos = 0; @@ -163,7 +234,7 @@ public void PerformRight() { int[] buffer; int pos; - + isCanRight = false; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); Array.Reverse(rangeX); @@ -191,6 +262,7 @@ public void PerformRight() { buffer[j - 1] *= 2; buffer[j] = 0; + isCanRight = true; } } // shift left again @@ -218,6 +290,7 @@ public void PerformLeft() int[] buffer; int pos; int[] range = Enumerable.Range(0, boardSize).ToArray(); + isCanLeft = false; foreach (int i in range) { pos = 0; @@ -242,6 +315,7 @@ public void PerformLeft() { buffer[j - 1] *= 2; buffer[j] = 0; + isCanLeft = true; } } // shift left again @@ -262,5 +336,9 @@ public void PerformLeft() board = Random(board); NotifyAll(); } + public void PerformHide() + { + + } } } diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index 703127d..79efaaf 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -49,6 +49,7 @@ private void InitializeComponent() this.btnRight = new System.Windows.Forms.Button(); this.btnDown = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lbl00 @@ -250,6 +251,7 @@ private void InitializeComponent() this.btnLeft.Name = "btnLeft"; this.btnLeft.Size = new System.Drawing.Size(71, 55); this.btnLeft.TabIndex = 16; + this.btnLeft.TabStop = false; this.btnLeft.Text = "<"; this.btnLeft.UseVisualStyleBackColor = true; this.btnLeft.Click += new System.EventHandler(this.btnLeft_Click); @@ -261,6 +263,7 @@ private void InitializeComponent() this.btnUp.Name = "btnUp"; this.btnUp.Size = new System.Drawing.Size(71, 55); this.btnUp.TabIndex = 17; + this.btnUp.TabStop = false; this.btnUp.Text = "^"; this.btnUp.UseVisualStyleBackColor = true; this.btnUp.Click += new System.EventHandler(this.btnUp_Click); @@ -272,6 +275,7 @@ private void InitializeComponent() this.btnRight.Name = "btnRight"; this.btnRight.Size = new System.Drawing.Size(71, 55); this.btnRight.TabIndex = 18; + this.btnRight.TabStop = false; this.btnRight.Text = ">"; this.btnRight.UseVisualStyleBackColor = true; this.btnRight.Click += new System.EventHandler(this.btnRight_Click); @@ -283,6 +287,7 @@ private void InitializeComponent() this.btnDown.Name = "btnDown"; this.btnDown.Size = new System.Drawing.Size(71, 55); this.btnDown.TabIndex = 19; + this.btnDown.TabStop = false; this.btnDown.Text = "v"; this.btnDown.UseVisualStyleBackColor = true; this.btnDown.Click += new System.EventHandler(this.btnDown_Click); @@ -300,11 +305,24 @@ private void InitializeComponent() this.label1.Visible = false; this.label1.Click += new System.EventHandler(this.label1_Click); // + // label2 + // + this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.ForeColor = System.Drawing.SystemColors.ControlLightLight; + this.label2.Location = new System.Drawing.Point(380, 494); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(184, 55); + this.label2.TabIndex = 21; + this.label2.Text = "0"; + // // TwoZeroFourEightView // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(598, 658); + this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.btnDown); this.Controls.Add(this.btnRight); @@ -357,6 +375,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnRight; private System.Windows.Forms.Button btnDown; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; } } diff --git a/TwoZeroFourEightView.cs b/TwoZeroFourEightView.cs index 8fbeb99..c581728 100644 --- a/TwoZeroFourEightView.cs +++ b/TwoZeroFourEightView.cs @@ -14,7 +14,8 @@ public partial class TwoZeroFourEightView : Form, View { Model model; Controller controller; - + TwoZeroFourEightModel a; + public TwoZeroFourEightView() { InitializeComponent(); @@ -30,6 +31,10 @@ public void Notify(Model m) UpdateBoard(((TwoZeroFourEightModel) m).GetBoard()); } + private string UpdateScore(Model m) + { + return Convert.ToString(((TwoZeroFourEightModel)m).GetScore()); + } private void UpdateTile(Label l, int i) { if (i != 0) @@ -119,11 +124,21 @@ private void btnUp_Click(object sender, EventArgs e) private void btnDown_Click(object sender, EventArgs e) { controller.ActionPerformed(TwoZeroFourEightController.DOWN); + } private void label1_Click(object sender, EventArgs e) { + label1.Visible = false; } + + private void label2_Click(object sender, EventArgs e) + { + //label2.Text = Convert.ToString(a.GetScore()); + label2.Text = UpdateScore(a); + } } -} + } + + From 0d8458d5b79dfd42bcc190497deecbb003ba4a97 Mon Sep 17 00:00:00 2001 From: ANAWIN ATHAWONG Date: Tue, 30 Oct 2018 15:40:28 +0700 Subject: [PATCH 3/5] can show score bug fixed --- TwoZeroFourEightController.cs | 3 +- TwoZeroFourEightModel.cs | 79 ++++++++++++++++++++------------ TwoZeroFourEightView.Designer.cs | 34 ++++++++++++-- TwoZeroFourEightView.cs | 27 +++++++++-- 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/TwoZeroFourEightController.cs b/TwoZeroFourEightController.cs index 6b78e2b..f6d7c52 100644 --- a/TwoZeroFourEightController.cs +++ b/TwoZeroFourEightController.cs @@ -39,12 +39,13 @@ public override void ActionPerformed(int action) m.PerformDown(); break; case HIDE: - m.PerformHide(); + break; } } } + } } diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index b48785e..367e72c 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -12,11 +12,11 @@ class TwoZeroFourEightModel : Model protected int[,] board; protected Random rand; public int boardsize = 0; - public bool isfull = false; - public bool isCandown = false; - public bool isCanUp = false; - public bool isCanLeft = false; - public bool isCanRight = false; + public bool isfull = true; + public bool isCandown = true; + public bool isCanUp = true; + public bool isCanLeft = true; + public bool isCanRight = true; public int score = 0; public TwoZeroFourEightModel() : this(4) { @@ -25,6 +25,14 @@ public TwoZeroFourEightModel() : this(4) public int GetScore() { + score = 0; + for(int i = 0; i < 4; i++) + { + for(int j = 0; j < 4; j++) + { + score += board[i, j]; + } + } return score; } public int[,] GetBoard() @@ -65,19 +73,16 @@ private void checkfull() if (boardsize >= 16) { boardsize = 16; - if (isCanLeft && isCanRight && isCanUp && isCandown) - { - System.Windows.Forms.MessageBox.Show("Game Over"); - isfull = true; - } + break; } } - score += board[i, j]; + // score += board[i, j]; + } } - + } @@ -88,7 +93,7 @@ private void checkfull() { int x = rand.Next(boardSize); int y = rand.Next(boardSize); - + int temp = 0; if (board[x, y] == 0) { @@ -100,22 +105,19 @@ private void checkfull() while (board[x, y] != 0) { + temp++; x = rand.Next(boardSize); y = rand.Next(boardSize); - if (board[x, y] == 0) break; + if (board[x, y] == 0) + { + board[x, y] = 2; + break; + } + else if (temp >= 16) break; } - board[x, y] = 2; - break; } - - - - - } - - checkfull(); return input; } @@ -126,7 +128,7 @@ public void PerformDown() int pos; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); - isCandown = false; + isCandown = true; Array.Reverse(rangeY); foreach (int i in rangeX) { @@ -154,6 +156,7 @@ public void PerformDown() buffer[j] = 0; isCandown = true; } + else isCandown = false; } // shift left again pos = 3; @@ -179,7 +182,7 @@ public void PerformUp() { int[] buffer; int pos; - isCanUp = false; + isCanUp = true; int[] range = Enumerable.Range(0, boardSize).ToArray(); foreach (int i in range) { @@ -206,8 +209,9 @@ public void PerformUp() buffer[j - 1] *= 2; buffer[j] = 0; isCanUp = true; - + } + else isCanUp = false; } // shift left again @@ -234,7 +238,7 @@ public void PerformRight() { int[] buffer; int pos; - isCanRight = false; + isCanRight = true; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); Array.Reverse(rangeX); @@ -264,6 +268,7 @@ public void PerformRight() buffer[j] = 0; isCanRight = true; } + else isCanRight = false; } // shift left again pos = 3; @@ -290,7 +295,7 @@ public void PerformLeft() int[] buffer; int pos; int[] range = Enumerable.Range(0, boardSize).ToArray(); - isCanLeft = false; + isCanLeft = true; foreach (int i in range) { pos = 0; @@ -317,6 +322,7 @@ public void PerformLeft() buffer[j] = 0; isCanLeft = true; } + else isCanLeft = false; } // shift left again pos = 0; @@ -336,9 +342,22 @@ public void PerformLeft() board = Random(board); NotifyAll(); } - public void PerformHide() + + public bool checkGo() { - + + if (isCandown == false && isCanUp == false && isCanLeft == false && isCanRight == false) + { + return false; + + } + else + { + + return true; + } + + } } } diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index 79efaaf..8cef41b 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -50,6 +50,8 @@ private void InitializeComponent() this.btnDown = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lbl00 @@ -309,19 +311,41 @@ private void InitializeComponent() // this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.label2.Location = new System.Drawing.Point(380, 494); + this.label2.ForeColor = System.Drawing.SystemColors.Highlight; + this.label2.Location = new System.Drawing.Point(392, 526); this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(184, 55); + this.label2.Size = new System.Drawing.Size(174, 55); this.label2.TabIndex = 21; this.label2.Text = "0"; // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(0, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(46, 17); + this.label3.TabIndex = 22; + this.label3.Text = "label3"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Arial Narrow", 28.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.Location = new System.Drawing.Point(402, 469); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(164, 57); + this.label4.TabIndex = 23; + this.label4.Text = "SCORE"; + this.label4.Click += new System.EventHandler(this.label4_Click); + // // TwoZeroFourEightView // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(598, 658); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.btnDown); @@ -375,7 +399,9 @@ private void InitializeComponent() private System.Windows.Forms.Button btnRight; private System.Windows.Forms.Button btnDown; private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; + public System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; } } diff --git a/TwoZeroFourEightView.cs b/TwoZeroFourEightView.cs index c581728..88d0c1b 100644 --- a/TwoZeroFourEightView.cs +++ b/TwoZeroFourEightView.cs @@ -15,6 +15,7 @@ public partial class TwoZeroFourEightView : Form, View Model model; Controller controller; TwoZeroFourEightModel a; + private Random rnd = new Random(); public TwoZeroFourEightView() { @@ -29,11 +30,23 @@ public TwoZeroFourEightView() public void Notify(Model m) { UpdateBoard(((TwoZeroFourEightModel) m).GetBoard()); + UpdateScore(m); + showGameOver(m); } - private string UpdateScore(Model m) + private void showGameOver(Model m) { - return Convert.ToString(((TwoZeroFourEightModel)m).GetScore()); + if (((TwoZeroFourEightModel)m).checkGo() == false) + { + label1.Visible = true; + System.Windows.Forms.MessageBox.Show("Game Over"); + } + } + + private void UpdateScore(Model m) + { + label2.Text = Convert.ToString(((TwoZeroFourEightModel)m).GetScore()); ; + // return Convert.ToString(((TwoZeroFourEightModel)m).GetScore()); } private void UpdateTile(Label l, int i) { @@ -105,7 +118,6 @@ private void UpdateBoard(int[,] board) UpdateTile(lbl32,board[3, 2]); UpdateTile(lbl33,board[3, 3]); } - private void btnLeft_Click(object sender, EventArgs e) { controller.ActionPerformed(TwoZeroFourEightController.LEFT); @@ -129,14 +141,21 @@ private void btnDown_Click(object sender, EventArgs e) private void label1_Click(object sender, EventArgs e) { + // if(controller.ActionPerformed(TwoZeroFourEightController.HIDE)==true) label1.Visible = false; } private void label2_Click(object sender, EventArgs e) { + // label2.Text = UpdateScore(m); //label2.Text = Convert.ToString(a.GetScore()); - label2.Text = UpdateScore(a); + // label2.Text = UpdateScore(a); + } + + private void label4_Click(object sender, EventArgs e) + { + } } } From 0286182ec594e1746f6bc4177ca4bade0617c524 Mon Sep 17 00:00:00 2001 From: ANAWIN ATHAWONG Date: Tue, 20 Nov 2018 12:28:40 +0700 Subject: [PATCH 4/5] play with arrow key show game over --- TwoZeroFourEightModel.cs | 53 ++++++++++++++++++++-------------------- TwoZeroFourEightView.cs | 26 +++++++++++++++++++- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 367e72c..c60b330 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -13,10 +13,6 @@ class TwoZeroFourEightModel : Model protected Random rand; public int boardsize = 0; public bool isfull = true; - public bool isCandown = true; - public bool isCanUp = true; - public bool isCanLeft = true; - public bool isCanRight = true; public int score = 0; public TwoZeroFourEightModel() : this(4) { @@ -128,7 +124,6 @@ public void PerformDown() int pos; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); - isCandown = true; Array.Reverse(rangeY); foreach (int i in rangeX) { @@ -154,9 +149,7 @@ public void PerformDown() { buffer[j - 1] *= 2; buffer[j] = 0; - isCandown = true; } - else isCandown = false; } // shift left again pos = 3; @@ -182,7 +175,6 @@ public void PerformUp() { int[] buffer; int pos; - isCanUp = true; int[] range = Enumerable.Range(0, boardSize).ToArray(); foreach (int i in range) { @@ -208,10 +200,8 @@ public void PerformUp() { buffer[j - 1] *= 2; buffer[j] = 0; - isCanUp = true; } - else isCanUp = false; } // shift left again @@ -238,7 +228,6 @@ public void PerformRight() { int[] buffer; int pos; - isCanRight = true; int[] rangeX = Enumerable.Range(0, boardSize).ToArray(); int[] rangeY = Enumerable.Range(0, boardSize).ToArray(); Array.Reverse(rangeX); @@ -266,9 +255,9 @@ public void PerformRight() { buffer[j - 1] *= 2; buffer[j] = 0; - isCanRight = true; + } - else isCanRight = false; + } // shift left again pos = 3; @@ -295,7 +284,6 @@ public void PerformLeft() int[] buffer; int pos; int[] range = Enumerable.Range(0, boardSize).ToArray(); - isCanLeft = true; foreach (int i in range) { pos = 0; @@ -320,9 +308,7 @@ public void PerformLeft() { buffer[j - 1] *= 2; buffer[j] = 0; - isCanLeft = true; } - else isCanLeft = false; } // shift left again pos = 0; @@ -342,22 +328,37 @@ public void PerformLeft() board = Random(board); NotifyAll(); } - - public bool checkGo() - { - if (isCandown == false && isCanUp == false && isCanLeft == false && isCanRight == false) + public bool Check() + { + bool a = true; + for (int i = 0; i < boardSize - 1; i++) { - return false; - + for (int j = 0; j < boardSize - 1; j++) + { + if (board[i, j] == board[i, j + 1] || board[j, i] == board[j + 1, i]|| board[i,j]==0) + a = false; + } } - else + for (int i = 0; i < boardSize; i++) { - - return true; + for (int j = 0; j < boardSize; j++) + { + if (board[i, j] == 0) + a = false; + } + } + for (int i = 0; i < 3; i++) + { + if (board[i, 3] == board[i + 1, 3] || board[3, i] == board[3, i + 1] ) + a = false; } + + return a; + } + - } + } } diff --git a/TwoZeroFourEightView.cs b/TwoZeroFourEightView.cs index 88d0c1b..5d9a879 100644 --- a/TwoZeroFourEightView.cs +++ b/TwoZeroFourEightView.cs @@ -36,7 +36,7 @@ public void Notify(Model m) private void showGameOver(Model m) { - if (((TwoZeroFourEightModel)m).checkGo() == false) + if (((TwoZeroFourEightModel)m).Check() == true) { label1.Visible = true; System.Windows.Forms.MessageBox.Show("Game Over"); @@ -157,6 +157,30 @@ private void label4_Click(object sender, EventArgs e) { } + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if (keyData == (Keys.Right)) + { + btnRight.PerformClick(); + return true; + } + else if (keyData == (Keys.Left)) + { + btnLeft.PerformClick(); + return true; + } + else if (keyData == (Keys.Up)) + { + btnUp.PerformClick(); + return true; + } + else if (keyData == (Keys.Down)) + { + btnDown.PerformClick(); + return true; + } + return base.ProcessCmdKey(ref msg, keyData); + } } } From 9af484c8901a586f93d0c08b6f95680bc6da3ec4 Mon Sep 17 00:00:00 2001 From: ANAWIN ATHAWONG Date: Tue, 20 Nov 2018 13:57:52 +0700 Subject: [PATCH 5/5] add comment try to use MVC rule --- TwoZeroFourEightController.cs | 17 ++++++++++++----- TwoZeroFourEightModel.cs | 6 ++++-- TwoZeroFourEightView.Designer.cs | 7 ++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/TwoZeroFourEightController.cs b/TwoZeroFourEightController.cs index f6d7c52..935bbf3 100644 --- a/TwoZeroFourEightController.cs +++ b/TwoZeroFourEightController.cs @@ -4,6 +4,16 @@ using System.Text; using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + namespace twozerofoureight { class TwoZeroFourEightController : Controller @@ -12,14 +22,13 @@ class TwoZeroFourEightController : Controller public const int RIGHT = 1; public const int UP = 2; public const int DOWN = 3; - public const int HIDE = 4; public TwoZeroFourEightController() { } - + public override void ActionPerformed(int action) { foreach (TwoZeroFourEightModel m in mList) @@ -38,9 +47,7 @@ public override void ActionPerformed(int action) case DOWN: m.PerformDown(); break; - case HIDE: - - break; + } diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index c60b330..522a6b6 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -85,6 +85,7 @@ private void checkfull() private int[,] Random(int[,] input) { + while (true) { int x = rand.Next(boardSize); @@ -104,12 +105,13 @@ private void checkfull() temp++; x = rand.Next(boardSize); y = rand.Next(boardSize); - if (board[x, y] == 0) + if (board[x, y] == 0) // find new position { board[x, y] = 2; break; } - else if (temp >= 16) break; + else if (temp >= 16) break; // force to break + } break; } diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index 8cef41b..0571bb5 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -298,12 +298,13 @@ private void InitializeComponent() // this.label1.AccessibleName = "gameover"; this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(12, 194); + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 55.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(-4, 217); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(521, 91); + this.label1.Size = new System.Drawing.Size(606, 105); this.label1.TabIndex = 20; this.label1.Text = "GAME OVER"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.Visible = false; this.label1.Click += new System.EventHandler(this.label1_Click); //