From 79ec1ed88b96af238eea9e9964be7c263c3959be Mon Sep 17 00:00:00 2001 From: Chin Isradisaikul Date: Fri, 12 Oct 2018 12:39:28 +0700 Subject: [PATCH 1/3] Resized boxes to avoid wrapping. --- Controller.cs | 2 +- TwoZeroFourEightModel.cs | 8 +- TwoZeroFourEightView.Designer.cs | 140 +++++++++++++++++++------------ 3 files changed, 91 insertions(+), 59 deletions(-) diff --git a/Controller.cs b/Controller.cs index 036a13a..b5c8520 100644 --- a/Controller.cs +++ b/Controller.cs @@ -20,7 +20,7 @@ public void AddModel(Model m) mList.Add(m); } - // virtual keyword allow the method to be overriden + // The `virtual` keyword allows the method to be overridden public virtual void ActionPerformed(int action) { throw new NotImplementedException(); diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 2c70ab6..5f6c1da 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -67,7 +67,7 @@ public void PerformDown() { buffer[k] = 0; } - //shift left + // shift left foreach (int j in rangeY) { if (board[j, i] != 0) @@ -119,7 +119,7 @@ public void PerformUp() { buffer[k] = 0; } - //shift left + // shift left foreach (int j in range) { if (board[j, i] != 0) @@ -173,7 +173,7 @@ public void PerformRight() { buffer[k] = 0; } - //shift left + // shift left foreach (int j in rangeX) { if (board[i, j] != 0) @@ -224,7 +224,7 @@ public void PerformLeft() { buffer[k] = 0; } - //shift left + // shift left foreach (int j in range) { if (board[i, j] != 0) diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index 8d079e6..af4b1f9 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -53,178 +53,210 @@ private void InitializeComponent() // lbl00 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl00.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl00.Location = new System.Drawing.Point(19, 11); + this.lbl00.Location = new System.Drawing.Point(0, 0); + this.lbl00.Margin = new System.Windows.Forms.Padding(0); this.lbl00.Name = "lbl00"; - this.lbl00.Size = new System.Drawing.Size(51, 51); + this.lbl00.Size = new System.Drawing.Size(75, 75); this.lbl00.TabIndex = 0; this.lbl00.Text = "0"; + this.lbl00.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl01 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl01.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl01.Location = new System.Drawing.Point(76, 9); + this.lbl01.Location = new System.Drawing.Point(75, 0); + this.lbl01.Margin = new System.Windows.Forms.Padding(0); this.lbl01.Name = "lbl01"; - this.lbl01.Size = new System.Drawing.Size(51, 51); + this.lbl01.Size = new System.Drawing.Size(75, 75); this.lbl01.TabIndex = 1; this.lbl01.Text = "0"; + this.lbl01.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl02 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl02.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl02.Location = new System.Drawing.Point(140, 11); + this.lbl02.Location = new System.Drawing.Point(150, 0); + this.lbl02.Margin = new System.Windows.Forms.Padding(0); this.lbl02.Name = "lbl02"; - this.lbl02.Size = new System.Drawing.Size(51, 51); + this.lbl02.Size = new System.Drawing.Size(75, 75); this.lbl02.TabIndex = 2; this.lbl02.Text = "0"; + this.lbl02.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl03 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl03.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl03.Location = new System.Drawing.Point(209, 9); + this.lbl03.Location = new System.Drawing.Point(225, 0); + this.lbl03.Margin = new System.Windows.Forms.Padding(0); this.lbl03.Name = "lbl03"; - this.lbl03.Size = new System.Drawing.Size(51, 51); + this.lbl03.Size = new System.Drawing.Size(75, 75); this.lbl03.TabIndex = 3; this.lbl03.Text = "0"; + this.lbl03.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl13 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl13.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl13.Location = new System.Drawing.Point(209, 74); + this.lbl13.Location = new System.Drawing.Point(225, 75); + this.lbl13.Margin = new System.Windows.Forms.Padding(0); this.lbl13.Name = "lbl13"; - this.lbl13.Size = new System.Drawing.Size(51, 51); + this.lbl13.Size = new System.Drawing.Size(75, 75); this.lbl13.TabIndex = 7; this.lbl13.Text = "0"; + this.lbl13.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl12 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl12.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl12.Location = new System.Drawing.Point(142, 74); + this.lbl12.Location = new System.Drawing.Point(150, 75); + this.lbl12.Margin = new System.Windows.Forms.Padding(0); this.lbl12.Name = "lbl12"; - this.lbl12.Size = new System.Drawing.Size(51, 51); + this.lbl12.Size = new System.Drawing.Size(75, 75); this.lbl12.TabIndex = 6; this.lbl12.Text = "0"; + this.lbl12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl11 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl11.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl11.Location = new System.Drawing.Point(76, 74); + this.lbl11.Location = new System.Drawing.Point(75, 75); + this.lbl11.Margin = new System.Windows.Forms.Padding(0); this.lbl11.Name = "lbl11"; - this.lbl11.Size = new System.Drawing.Size(51, 51); + this.lbl11.Size = new System.Drawing.Size(75, 75); this.lbl11.TabIndex = 5; this.lbl11.Text = "0"; + this.lbl11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl10 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl10.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl10.Location = new System.Drawing.Point(19, 74); + this.lbl10.Location = new System.Drawing.Point(0, 75); + this.lbl10.Margin = new System.Windows.Forms.Padding(0); this.lbl10.Name = "lbl10"; - this.lbl10.Size = new System.Drawing.Size(51, 51); + this.lbl10.Size = new System.Drawing.Size(75, 75); this.lbl10.TabIndex = 4; this.lbl10.Text = "0"; + this.lbl10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl23 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl23.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl23.Location = new System.Drawing.Point(209, 138); + this.lbl23.Location = new System.Drawing.Point(225, 150); + this.lbl23.Margin = new System.Windows.Forms.Padding(0); this.lbl23.Name = "lbl23"; - this.lbl23.Size = new System.Drawing.Size(51, 51); + this.lbl23.Size = new System.Drawing.Size(75, 75); this.lbl23.TabIndex = 11; this.lbl23.Text = "0"; + this.lbl23.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl22 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl22.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl22.Location = new System.Drawing.Point(142, 138); + this.lbl22.Location = new System.Drawing.Point(150, 150); + this.lbl22.Margin = new System.Windows.Forms.Padding(0); this.lbl22.Name = "lbl22"; - this.lbl22.Size = new System.Drawing.Size(51, 51); + this.lbl22.Size = new System.Drawing.Size(75, 75); this.lbl22.TabIndex = 10; this.lbl22.Text = "0"; + this.lbl22.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl21 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl21.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl21.Location = new System.Drawing.Point(82, 138); + this.lbl21.Location = new System.Drawing.Point(75, 150); + this.lbl21.Margin = new System.Windows.Forms.Padding(0); this.lbl21.Name = "lbl21"; - this.lbl21.Size = new System.Drawing.Size(51, 51); + this.lbl21.Size = new System.Drawing.Size(75, 75); this.lbl21.TabIndex = 9; this.lbl21.Text = "0"; + this.lbl21.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl20 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl20.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl20.Location = new System.Drawing.Point(19, 138); + this.lbl20.Location = new System.Drawing.Point(0, 150); + this.lbl20.Margin = new System.Windows.Forms.Padding(0); this.lbl20.Name = "lbl20"; - this.lbl20.Size = new System.Drawing.Size(51, 51); + this.lbl20.Size = new System.Drawing.Size(75, 75); this.lbl20.TabIndex = 8; this.lbl20.Text = "0"; + this.lbl20.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl33 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl33.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl33.Location = new System.Drawing.Point(209, 201); + this.lbl33.Location = new System.Drawing.Point(225, 225); + this.lbl33.Margin = new System.Windows.Forms.Padding(0); this.lbl33.Name = "lbl33"; - this.lbl33.Size = new System.Drawing.Size(51, 51); + this.lbl33.Size = new System.Drawing.Size(75, 75); this.lbl33.TabIndex = 15; this.lbl33.Text = "0"; + this.lbl33.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl32 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl32.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl32.Location = new System.Drawing.Point(142, 201); + this.lbl32.Location = new System.Drawing.Point(150, 225); + this.lbl32.Margin = new System.Windows.Forms.Padding(0); this.lbl32.Name = "lbl32"; - this.lbl32.Size = new System.Drawing.Size(51, 51); + this.lbl32.Size = new System.Drawing.Size(75, 75); this.lbl32.TabIndex = 14; this.lbl32.Text = "0"; + this.lbl32.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl31 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl31.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl31.Location = new System.Drawing.Point(82, 201); + this.lbl31.Location = new System.Drawing.Point(75, 225); + this.lbl31.Margin = new System.Windows.Forms.Padding(0); this.lbl31.Name = "lbl31"; - this.lbl31.Size = new System.Drawing.Size(51, 51); + this.lbl31.Size = new System.Drawing.Size(75, 75); this.lbl31.TabIndex = 13; this.lbl31.Text = "0"; + this.lbl31.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // lbl30 // 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.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl30.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl30.Location = new System.Drawing.Point(19, 201); + this.lbl30.Location = new System.Drawing.Point(0, 225); + this.lbl30.Margin = new System.Windows.Forms.Padding(0); this.lbl30.Name = "lbl30"; - this.lbl30.Size = new System.Drawing.Size(51, 51); + this.lbl30.Size = new System.Drawing.Size(75, 75); this.lbl30.TabIndex = 12; this.lbl30.Text = "0"; + this.lbl30.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // btnLeft // @@ -232,7 +264,7 @@ private void InitializeComponent() this.btnLeft.Name = "btnLeft"; this.btnLeft.Size = new System.Drawing.Size(53, 45); this.btnLeft.TabIndex = 16; - this.btnLeft.Text = "<"; + this.btnLeft.Text = "←"; this.btnLeft.UseVisualStyleBackColor = true; this.btnLeft.Click += new System.EventHandler(this.btnLeft_Click); // @@ -242,7 +274,7 @@ private void InitializeComponent() this.btnUp.Name = "btnUp"; this.btnUp.Size = new System.Drawing.Size(53, 45); this.btnUp.TabIndex = 17; - this.btnUp.Text = "^"; + this.btnUp.Text = "↑"; this.btnUp.UseVisualStyleBackColor = true; this.btnUp.Click += new System.EventHandler(this.btnUp_Click); // @@ -252,7 +284,7 @@ private void InitializeComponent() this.btnRight.Name = "btnRight"; this.btnRight.Size = new System.Drawing.Size(53, 45); this.btnRight.TabIndex = 18; - this.btnRight.Text = ">"; + this.btnRight.Text = "→"; this.btnRight.UseVisualStyleBackColor = true; this.btnRight.Click += new System.EventHandler(this.btnRight_Click); // @@ -262,11 +294,11 @@ private void InitializeComponent() this.btnDown.Name = "btnDown"; this.btnDown.Size = new System.Drawing.Size(53, 45); this.btnDown.TabIndex = 19; - this.btnDown.Text = "v"; + this.btnDown.Text = "↓"; this.btnDown.UseVisualStyleBackColor = true; this.btnDown.Click += new System.EventHandler(this.btnDown_Click); // - // Form1 + // TwoZeroFourEightView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -291,7 +323,7 @@ private void InitializeComponent() this.Controls.Add(this.lbl02); this.Controls.Add(this.lbl01); this.Controls.Add(this.lbl00); - this.Name = "Form1"; + this.Name = "TwoZeroFourEightView"; this.Text = "Form1"; this.ResumeLayout(false); From 5bdb4f781906c2f10755df34bb218c661a913412 Mon Sep 17 00:00:00 2001 From: Chin Isradisaikul Date: Fri, 12 Oct 2018 12:53:30 +0700 Subject: [PATCH 2/3] Fixed comments. --- TwoZeroFourEightModel.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 5f6c1da..0bf5fdc 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -17,11 +17,6 @@ public TwoZeroFourEightModel() : this(4) // default board size is 4 } - public int[,] GetBoard() - { - return board; - } - public TwoZeroFourEightModel(int size) { boardSize = size; @@ -37,6 +32,11 @@ public TwoZeroFourEightModel(int size) NotifyAll(); } + public int[,] GetBoard() + { + return board; + } + private int[,] Random(int[,] input) { while (true) @@ -67,7 +67,7 @@ public void PerformDown() { buffer[k] = 0; } - // shift left + // shift down foreach (int j in rangeY) { if (board[j, i] != 0) @@ -85,7 +85,7 @@ public void PerformDown() buffer[j] = 0; } } - // shift left again + // shift down again pos = 3; foreach (int j in rangeX) { @@ -119,7 +119,7 @@ public void PerformUp() { buffer[k] = 0; } - // shift left + // shift up foreach (int j in range) { if (board[j, i] != 0) @@ -137,7 +137,7 @@ public void PerformUp() buffer[j] = 0; } } - // shift left again + // shift up again pos = 0; foreach (int j in range) { @@ -173,7 +173,7 @@ public void PerformRight() { buffer[k] = 0; } - // shift left + // shift right foreach (int j in rangeX) { if (board[i, j] != 0) @@ -191,7 +191,7 @@ public void PerformRight() buffer[j] = 0; } } - // shift left again + // shift right again pos = 3; foreach (int j in rangeY) { From 7f7aab53d4f60f5ede30e5a16193e0bf8a10cf5d Mon Sep 17 00:00:00 2001 From: APISARA TUNGPENNUNG Date: Fri, 19 Oct 2018 15:32:17 +0700 Subject: [PATCH 3/3] complete lab 5 --- TwoZeroFourEightModel.cs | 49 +++++++++++++++++++++- TwoZeroFourEightView.Designer.cs | 71 +++++++++++++++++++++++--------- TwoZeroFourEightView.cs | 60 ++++++++++++++++++++++++++- 3 files changed, 156 insertions(+), 24 deletions(-) diff --git a/TwoZeroFourEightModel.cs b/TwoZeroFourEightModel.cs index 0bf5fdc..bf13678 100644 --- a/TwoZeroFourEightModel.cs +++ b/TwoZeroFourEightModel.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace twozerofoureight { @@ -11,10 +12,15 @@ class TwoZeroFourEightModel : Model protected int boardSize; // default is 4 protected int[,] board; protected Random rand; + protected int score = 0; public TwoZeroFourEightModel() : this(4) { - // default board size is 4 + // default board size is 4 + } + public string UpdateScore() + { + return score.ToString(); } public TwoZeroFourEightModel(int size) @@ -32,6 +38,19 @@ public TwoZeroFourEightModel(int size) NotifyAll(); } + public bool isfull() + { + for(int i = 0; i < boardSize; i++) + { + for(int j=0; j < boardSize; j++) + { + if (board[i, j] == 0) return false; + } + } + GameOver(); + return true; + } + public int[,] GetBoard() { return board; @@ -39,7 +58,7 @@ public TwoZeroFourEightModel(int size) private int[,] Random(int[,] input) { - while (true) + while (!isfull()) { int x = rand.Next(boardSize); int y = rand.Next(boardSize); @@ -50,6 +69,27 @@ public TwoZeroFourEightModel(int size) } } return input; + + } + + public void GameOver() + { + bool a=true; + for (int i = 0; i < boardSize-1; i++) + { + for (int j = 0; j < boardSize-1; j++) + { + if (board[i, j] == board[i, j + 1]|| board[j, i] == board[j + 1, i]) + 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; + } + if (a) + MessageBox.Show("GAME OVER"); } public void PerformDown() @@ -73,6 +113,7 @@ public void PerformDown() if (board[j, i] != 0) { buffer[pos] = board[j, i]; + pos++; } } @@ -82,6 +123,7 @@ public void PerformDown() if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1]) { buffer[j - 1] *= 2; + score += buffer[j - 1]; buffer[j] = 0; } } @@ -134,6 +176,7 @@ public void PerformUp() if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1]) { buffer[j - 1] *= 2; + score += buffer[j - 1]; buffer[j] = 0; } } @@ -188,6 +231,7 @@ public void PerformRight() if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1]) { buffer[j - 1] *= 2; + score += buffer[j - 1]; buffer[j] = 0; } } @@ -239,6 +283,7 @@ public void PerformLeft() if (j > 0 && buffer[j] != 0 && buffer[j] == buffer[j - 1]) { buffer[j - 1] *= 2; + score += buffer[j - 1]; buffer[j] = 0; } } diff --git a/TwoZeroFourEightView.Designer.cs b/TwoZeroFourEightView.Designer.cs index af4b1f9..2d4816f 100644 --- a/TwoZeroFourEightView.Designer.cs +++ b/TwoZeroFourEightView.Designer.cs @@ -48,6 +48,8 @@ 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.scr = new System.Windows.Forms.TextBox(); + this.SCORE = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lbl00 @@ -55,7 +57,7 @@ private void InitializeComponent() this.lbl00.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl00.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl00.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl00.Location = new System.Drawing.Point(0, 0); + this.lbl00.Location = new System.Drawing.Point(20, 10); this.lbl00.Margin = new System.Windows.Forms.Padding(0); this.lbl00.Name = "lbl00"; this.lbl00.Size = new System.Drawing.Size(75, 75); @@ -68,7 +70,7 @@ private void InitializeComponent() this.lbl01.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl01.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl01.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl01.Location = new System.Drawing.Point(75, 0); + this.lbl01.Location = new System.Drawing.Point(95, 10); this.lbl01.Margin = new System.Windows.Forms.Padding(0); this.lbl01.Name = "lbl01"; this.lbl01.Size = new System.Drawing.Size(75, 75); @@ -81,7 +83,7 @@ private void InitializeComponent() this.lbl02.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl02.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl02.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl02.Location = new System.Drawing.Point(150, 0); + this.lbl02.Location = new System.Drawing.Point(170, 10); this.lbl02.Margin = new System.Windows.Forms.Padding(0); this.lbl02.Name = "lbl02"; this.lbl02.Size = new System.Drawing.Size(75, 75); @@ -94,20 +96,21 @@ private void InitializeComponent() this.lbl03.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl03.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl03.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl03.Location = new System.Drawing.Point(225, 0); + this.lbl03.Location = new System.Drawing.Point(245, 10); this.lbl03.Margin = new System.Windows.Forms.Padding(0); this.lbl03.Name = "lbl03"; this.lbl03.Size = new System.Drawing.Size(75, 75); this.lbl03.TabIndex = 3; this.lbl03.Text = "0"; this.lbl03.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.lbl03.Click += new System.EventHandler(this.lbl03_Click); // // lbl13 // this.lbl13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl13.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl13.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl13.Location = new System.Drawing.Point(225, 75); + this.lbl13.Location = new System.Drawing.Point(245, 85); this.lbl13.Margin = new System.Windows.Forms.Padding(0); this.lbl13.Name = "lbl13"; this.lbl13.Size = new System.Drawing.Size(75, 75); @@ -120,7 +123,7 @@ private void InitializeComponent() this.lbl12.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl12.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl12.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl12.Location = new System.Drawing.Point(150, 75); + this.lbl12.Location = new System.Drawing.Point(170, 85); this.lbl12.Margin = new System.Windows.Forms.Padding(0); this.lbl12.Name = "lbl12"; this.lbl12.Size = new System.Drawing.Size(75, 75); @@ -133,7 +136,7 @@ private void InitializeComponent() this.lbl11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl11.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl11.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl11.Location = new System.Drawing.Point(75, 75); + this.lbl11.Location = new System.Drawing.Point(95, 85); this.lbl11.Margin = new System.Windows.Forms.Padding(0); this.lbl11.Name = "lbl11"; this.lbl11.Size = new System.Drawing.Size(75, 75); @@ -146,7 +149,7 @@ private void InitializeComponent() this.lbl10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl10.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl10.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl10.Location = new System.Drawing.Point(0, 75); + this.lbl10.Location = new System.Drawing.Point(20, 85); this.lbl10.Margin = new System.Windows.Forms.Padding(0); this.lbl10.Name = "lbl10"; this.lbl10.Size = new System.Drawing.Size(75, 75); @@ -159,7 +162,7 @@ private void InitializeComponent() this.lbl23.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl23.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl23.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl23.Location = new System.Drawing.Point(225, 150); + this.lbl23.Location = new System.Drawing.Point(245, 160); this.lbl23.Margin = new System.Windows.Forms.Padding(0); this.lbl23.Name = "lbl23"; this.lbl23.Size = new System.Drawing.Size(75, 75); @@ -172,7 +175,7 @@ private void InitializeComponent() this.lbl22.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl22.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl22.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl22.Location = new System.Drawing.Point(150, 150); + this.lbl22.Location = new System.Drawing.Point(170, 160); this.lbl22.Margin = new System.Windows.Forms.Padding(0); this.lbl22.Name = "lbl22"; this.lbl22.Size = new System.Drawing.Size(75, 75); @@ -185,7 +188,7 @@ private void InitializeComponent() this.lbl21.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl21.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl21.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl21.Location = new System.Drawing.Point(75, 150); + this.lbl21.Location = new System.Drawing.Point(95, 160); this.lbl21.Margin = new System.Windows.Forms.Padding(0); this.lbl21.Name = "lbl21"; this.lbl21.Size = new System.Drawing.Size(75, 75); @@ -198,7 +201,7 @@ private void InitializeComponent() this.lbl20.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl20.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl20.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl20.Location = new System.Drawing.Point(0, 150); + this.lbl20.Location = new System.Drawing.Point(20, 160); this.lbl20.Margin = new System.Windows.Forms.Padding(0); this.lbl20.Name = "lbl20"; this.lbl20.Size = new System.Drawing.Size(75, 75); @@ -211,7 +214,7 @@ private void InitializeComponent() this.lbl33.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl33.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl33.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl33.Location = new System.Drawing.Point(225, 225); + this.lbl33.Location = new System.Drawing.Point(245, 235); this.lbl33.Margin = new System.Windows.Forms.Padding(0); this.lbl33.Name = "lbl33"; this.lbl33.Size = new System.Drawing.Size(75, 75); @@ -224,7 +227,7 @@ private void InitializeComponent() this.lbl32.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl32.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl32.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl32.Location = new System.Drawing.Point(150, 225); + this.lbl32.Location = new System.Drawing.Point(170, 235); this.lbl32.Margin = new System.Windows.Forms.Padding(0); this.lbl32.Name = "lbl32"; this.lbl32.Size = new System.Drawing.Size(75, 75); @@ -237,7 +240,7 @@ private void InitializeComponent() this.lbl31.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl31.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl31.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl31.Location = new System.Drawing.Point(75, 225); + this.lbl31.Location = new System.Drawing.Point(95, 235); this.lbl31.Margin = new System.Windows.Forms.Padding(0); this.lbl31.Name = "lbl31"; this.lbl31.Size = new System.Drawing.Size(75, 75); @@ -250,7 +253,7 @@ private void InitializeComponent() this.lbl30.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.lbl30.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); this.lbl30.ForeColor = System.Drawing.SystemColors.ControlLightLight; - this.lbl30.Location = new System.Drawing.Point(0, 225); + this.lbl30.Location = new System.Drawing.Point(20, 235); this.lbl30.Margin = new System.Windows.Forms.Padding(0); this.lbl30.Name = "lbl30"; this.lbl30.Size = new System.Drawing.Size(75, 75); @@ -260,49 +263,74 @@ private void InitializeComponent() // // btnLeft // - this.btnLeft.Location = new System.Drawing.Point(85, 336); + this.btnLeft.Location = new System.Drawing.Point(22, 336); this.btnLeft.Name = "btnLeft"; this.btnLeft.Size = new System.Drawing.Size(53, 45); this.btnLeft.TabIndex = 16; this.btnLeft.Text = "←"; this.btnLeft.UseVisualStyleBackColor = true; this.btnLeft.Click += new System.EventHandler(this.btnLeft_Click); + this.btnLeft.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.btn); // // btnUp // - this.btnUp.Location = new System.Drawing.Point(140, 307); + this.btnUp.Location = new System.Drawing.Point(81, 316); this.btnUp.Name = "btnUp"; this.btnUp.Size = new System.Drawing.Size(53, 45); this.btnUp.TabIndex = 17; this.btnUp.Text = "↑"; this.btnUp.UseVisualStyleBackColor = true; this.btnUp.Click += new System.EventHandler(this.btnUp_Click); + this.btnUp.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.btn); // // btnRight // - this.btnRight.Location = new System.Drawing.Point(195, 336); + this.btnRight.Location = new System.Drawing.Point(140, 336); this.btnRight.Name = "btnRight"; this.btnRight.Size = new System.Drawing.Size(53, 45); this.btnRight.TabIndex = 18; this.btnRight.Text = "→"; this.btnRight.UseVisualStyleBackColor = true; this.btnRight.Click += new System.EventHandler(this.btnRight_Click); + this.btnRight.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.btn); // // btnDown // - this.btnDown.Location = new System.Drawing.Point(140, 371); + this.btnDown.Location = new System.Drawing.Point(81, 371); this.btnDown.Name = "btnDown"; this.btnDown.Size = new System.Drawing.Size(53, 45); this.btnDown.TabIndex = 19; this.btnDown.Text = "↓"; this.btnDown.UseVisualStyleBackColor = true; this.btnDown.Click += new System.EventHandler(this.btnDown_Click); + this.btnDown.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.btn); + // + // scr + // + this.scr.Location = new System.Drawing.Point(225, 336); + this.scr.Name = "scr"; + this.scr.Size = new System.Drawing.Size(100, 20); + this.scr.TabIndex = 20; + // + // SCORE + // + this.SCORE.AutoSize = true; + this.SCORE.Font = new System.Drawing.Font("Segoe Print", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.SCORE.Location = new System.Drawing.Point(221, 310); + this.SCORE.Name = "SCORE"; + this.SCORE.Size = new System.Drawing.Size(55, 23); + this.SCORE.TabIndex = 21; + this.SCORE.Text = "SCORE"; + this.SCORE.Click += new System.EventHandler(this.SCORE_Click); // // TwoZeroFourEightView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.DarkSeaGreen; this.ClientSize = new System.Drawing.Size(344, 428); + this.Controls.Add(this.SCORE); + this.Controls.Add(this.scr); this.Controls.Add(this.btnDown); this.Controls.Add(this.btnRight); this.Controls.Add(this.btnUp); @@ -326,6 +354,7 @@ private void InitializeComponent() this.Name = "TwoZeroFourEightView"; this.Text = "Form1"; this.ResumeLayout(false); + this.PerformLayout(); } @@ -351,6 +380,8 @@ 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.TextBox scr; + private System.Windows.Forms.Label SCORE; } } diff --git a/TwoZeroFourEightView.cs b/TwoZeroFourEightView.cs index 8201edf..7d7fd0b 100644 --- a/TwoZeroFourEightView.cs +++ b/TwoZeroFourEightView.cs @@ -28,6 +28,8 @@ public TwoZeroFourEightView() public void Notify(Model m) { UpdateBoard(((TwoZeroFourEightModel) m).GetBoard()); + scr.Text = ((TwoZeroFourEightModel)model).UpdateScore(); + } private void UpdateTile(Label l, int i) @@ -52,9 +54,33 @@ private void UpdateTile(Label l, int i) case 8: l.BackColor = Color.Red; break; - default: + case 16: + l.BackColor = Color.Red; + break; + case 32: + l.BackColor = Color.YellowGreen; + break; + case 64: + l.BackColor = Color.Yellow; + break; + case 128: l.BackColor = Color.Green; break; + case 256: + l.BackColor = Color.Purple; + break; + case 512: + l.BackColor = Color.Magenta; + break; + case 1024: + l.BackColor = Color.LightBlue; + break; + case 2048: + l.BackColor = Color.Gold; + break; + default: + l.BackColor = Color.Pink; + break; } } private void UpdateBoard(int[,] board) @@ -75,9 +101,14 @@ private void UpdateBoard(int[,] board) UpdateTile(lbl31,board[3, 1]); UpdateTile(lbl32,board[3, 2]); UpdateTile(lbl33,board[3, 3]); + + + } - private void btnLeft_Click(object sender, EventArgs e) + + + private void btnLeft_Click(object sender, EventArgs e) { controller.ActionPerformed(TwoZeroFourEightController.LEFT); } @@ -97,5 +128,30 @@ private void btnDown_Click(object sender, EventArgs e) controller.ActionPerformed(TwoZeroFourEightController.DOWN); } + private void lbl03_Click(object sender, EventArgs e) + { + + } + + private void SCORE_Click(object sender, EventArgs e) + { + + } + + private void btn(object sender, PreviewKeyDownEventArgs e) + { + e.IsInputKey = true; + switch (e.KeyCode) + { + case Keys.Up: controller.ActionPerformed(TwoZeroFourEightController.UP); break; + case Keys.Down: controller.ActionPerformed(TwoZeroFourEightController.DOWN); break; + case Keys.Left: controller.ActionPerformed(TwoZeroFourEightController.LEFT); break; + case Keys.Right: controller.ActionPerformed(TwoZeroFourEightController.RIGHT); break; + + + } + } + + } }