Code chi tiết game 2048 bằng
windows form
Giao diện chơi (cái này các bạn thiết kế theo ý thích nhé)
p/s: - ở đâymình viết các sự kiện cho các nút a ,s ,d,w và label tắt tiếng , chơi lại
- Các nút khi bấm sẽ phát âm thanh
- Các số khác nhau sẽ có mày khác nhau
- Vậy thôi code mình viết hơi dài các bạn tham khảo nhé :D
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;
using System.Media;
namespace Game2048
{
public partial class Form1 : Form
{
// âm thanh trò chơi
public SoundPlayer nhaca = new SoundPlayer(@"C:/AmThanh/beep-
21.wav");
public SoundPlayer nhacs = new SoundPlayer(@"C:/AmThanh/beep-
08b.wav");
public SoundPlayer nhacd = new SoundPlayer(@"C:/AmThanh/beep-
22.wav");
public SoundPlayer nhacw = new SoundPlayer(@"C:/AmThanh/button-
3.wav");
//phím lên : 119 chữ w
//phím xuống : 115 chữ s
//phím phải : 100 chữ d
//phím trái : 97 chữ a
// khai báo mảng
int[,] a = new int[4, 4];
int[,] b = new int[4, 4];
int so2xh = 0, CoThua = 0, Diem = 0, TatTieng = 0;
//int[] NhoMat=new int[4];//ma trận nhớ phần xử lý
//cách khác
//int[] abc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SoNgauNhienBatDau();
MatToForm();
FormToMat();
MauSac();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (CoThua == 1)
return;
else
{
if (e.KeyChar == 97) // chữ a >left
{
if(TatTieng==0)//không tắt tiếng
nhaca.Play();
BoVaoB();
XuLyNutBam(97);
MatToForm();
if (KiemTraGiong() == 0)
TaoSoNgauNhien();
else
if(KiemTraChoTrong() == 0)
if (ConChoiDc() == 0)
{
MessageBox.Show("Tèn ten thua rồi nhé !!!\n
Điểm của bạn là :" + Diem, "Thông báo",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
CoThua = 1;
}
MatToForm();
MauSac();
}
if (e.KeyChar == 100)// chữ d >right
{
if (TatTieng == 0)//không tắt tiếng
nhacd.Play();
BoVaoB();
XuLyNutBam(100);
MatToForm();
if (KiemTraGiong() == 0)
TaoSoNgauNhien();
else
if (KiemTraChoTrong() == 0)
if (ConChoiDc() == 0)
{
MessageBox.Show("Tèn ten thua rồi nhé !!!\n
Điểm của bạn là :" + Diem, "Thông báo",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
CoThua = 1;
}
MatToForm();
MauSac();
}
if (e.KeyChar == 115)// chữ s >down
{
if (TatTieng == 0)//không tắt tiếng
nhacs.Play();
BoVaoB();
XuLyNutBam(115);
MatToForm();
if (KiemTraGiong() == 0)
TaoSoNgauNhien();
else
if (KiemTraChoTrong() == 0)
if (ConChoiDc() == 0)
{
MessageBox.Show("Tèn ten thua rồi nhé !!!\n
Điểm của bạn là :" + Diem, "Thông báo",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
CoThua = 1;
}
MatToForm();
MauSac();
}
if (e.KeyChar == 119)// chữ w >up
{
if (TatTieng == 0)//không tắt tiếng
nhacw.Play();
BoVaoB();
XuLyNutBam(119);
MatToForm();
if (KiemTraGiong() == 0)
TaoSoNgauNhien();
else
if (KiemTraChoTrong() == 0)
if (ConChoiDc() == 0)
{
MessageBox.Show("Tèn ten thua rồi nhé !!!\n
Điểm của bạn là :" + Diem, "Thông báo",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
CoThua = 1;
}
MatToForm();
MauSac();
}
FormToMat();
}
}
//chơi lại
private void label2_Click(object sender, EventArgs e)
{
SoNgauNhienBatDau();
MatToForm();
lbDiemSo.Text="0";
CoThua = 0;
Diem = 0;
MauSac();
}
//hàm chuyển từ ma trận vào form
void MatToForm()
{
//
if (a[0, 0] == 0)
a00.Text = "";
else
a00.Text = a[0, 0].ToString();
//
if (a[0, 1] == 0)
a01.Text = "";
else
a01.Text = a[0, 1].ToString();
//
if (a[0, 2] == 0)
a02.Text = "";
else
a02.Text = a[0, 2].ToString();
//
if (a[0, 3] == 0)
a03.Text = "";
else
a03.Text = a[0, 3].ToString();
//
if (a[1, 0] == 0)
a10.Text = "";
else
a10.Text = a[1, 0].ToString();
//
if (a[1, 1] == 0)
a11.Text = "";
else
a11.Text = a[1, 1].ToString();
//
if (a[1, 2] == 0)
a12.Text = "";
else
a12.Text = a[1, 2].ToString();
//
if (a[1, 3] == 0)
a13.Text = "";
else
a13.Text = a[1, 3].ToString();
//
if (a[2, 0] == 0)
a20.Text = "";
else
a20.Text = a[2, 0].ToString();
//
if (a[2, 1] == 0)
a21.Text = "";
else
a21.Text = a[2, 1].ToString();
//
if (a[2, 2] == 0)
a22.Text = "";
else
a22.Text = a[2, 2].ToString();
//
if (a[2, 3] == 0)
a23.Text = "";
else
a23.Text = a[2, 3].ToString();
//
if (a[3, 0] == 0)
a30.Text = "";
else
a30.Text = a[3, 0].ToString();
//
if (a[3, 1] == 0)
a31.Text = "";
else
a31.Text = a[3, 1].ToString();
//
if (a[3, 2] == 0)
a32.Text = "";
else
a32.Text = a[3, 2].ToString();
//
if (a[3, 3] == 0)
a33.Text = "";
else
a33.Text = a[3, 3].ToString();
}
//hàm chuyển từ form vào ma trận
void FormToMat()
{
//
if (a00.Text == "")
a[0, 0] = 0;
else
a[0, 0] = int.Parse(a00.Text);
//
if (a01.Text == "")
a[0, 1] = 0;
else
a[0, 1] = int.Parse(a01.Text);
//
if (a02.Text == "")
a[0, 2] = 0;
else
a[0, 2] = int.Parse(a02.Text);
//
if (a03.Text == "")
a[0, 3] = 0;
else
a[0, 3] = int.Parse(a03.Text);
//
if (a10.Text == "")
a[1, 0] = 0;
else
a[1, 0] = int.Parse(a10.Text);
//
if (a11.Text == "")
a[1, 1] = 0;
else
a[1, 1] = int.Parse(a11.Text);
//
if (a12.Text == "")
a[1, 2] = 0;
else
a[1, 2] = int.Parse(a12.Text);
//
if (a13.Text == "")
a[1, 3] = 0;
else
a[1, 3] = int.Parse(a13.Text);
//
if (a20.Text == "")
a[2, 0] = 0;
else
a[2, 0] = int.Parse(a20.Text);
//
if (a21.Text == "")
a[2, 1] = 0;
else
a[2, 1] = int.Parse(a21.Text);
//
if (a22.Text == "")
a[2, 2] = 0;
else
a[2, 2] = int.Parse(a22.Text);
//
if (a23.Text == "")
a[2, 3] = 0;
else
a[2, 3] = int.Parse(a23.Text);
//
if (a30.Text == "")
a[3, 0] = 0;
else
a[3, 0] = int.Parse(a30.Text);
//
if (a31.Text == "")
a[3, 1] = 0;
else
a[3, 1] = int.Parse(a31.Text);
//
if (a32.Text == "")
a[3, 2] = 0;
else
a[3, 2] = int.Parse(a32.Text);
//
if (a33.Text == "")
a[3, 3] = 0;
else
a[3, 3] = int.Parse(a33.Text);
}
//hàm tạo số ngẫu nhiêu cho ma trận đầu tiên
//chỉ tạo ngẫu nhiên 1 số 4 và 1 số 2 ở 3 vị trí bất kì
void SoNgauNhienBatDau()
{
//khởi tạo mảng a
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
{
a[i, j] = 0;
}
//tạo 3 vị trí ngẫu nhiên xuất hiện đầu tiên trong ma trận
// sao cho 3 vị trí này ko trùng nhau (vòng while)
int i1rd, j1rd, i2rd, j2rd, i3rd, j3rd;
// vị trí 1
Random i1Random = new Random();
Random j1Random = new Random();
i1rd = i1Random.Next(0, 20);
i1rd = i1rd % 4;
j1rd = j1Random.Next(4, 24);
j1rd = j1rd % 4;
// vị trí 2
Random i2Random = new Random();
Random j2Random = new Random();
do
{
i2rd = i2Random.Next(2, 22);
i2rd = i2rd % 4;
j2rd = j2Random.Next(3, 24);
j2rd = j2rd % 4;
} while (i1rd == i2rd && j1rd == j2rd);
// vị trí 3
Random i3Random = new Random();
Random j3Random = new Random();
do
{
i3rd = i3Random.Next(0, 3);
i3rd = i3rd % 4;
j3rd = j3Random.Next(3, 9);
j3rd = j3rd % 4;
} while (i1rd == i3rd && j1rd == j3rd || i2rd == i3rd && j2rd ==
j3rd);
a[i1rd, j1rd] = 4;
a[i2rd, j2rd] = 2;
a[i3rd, j3rd] = 2;
}
//hàm tạo ra 1 vị trí bất kì để đặt số 2 vào ma trận
void TaoSoNgauNhien()
{
//game over khi ko còn chơi đc nữa
//và không thể thêm bất kì số nào vào ma trận
if (KiemTraChoTrong() == 1)//còn chổ trống
{
int ird, jrd;
Random irdo = new Random();
Random jrdo = new Random();
do
{
ird = irdo.Next(0, 20);
ird = ird % 4;
jrd = jrdo.Next(24, 36);
jrd = jrd % 4;
} while (a[ird, jrd] != 0);
if (so2xh < 8)
{
a[ird, jrd] = 2;
so2xh++;
}
else
{
a[ird, jrd] = 4;
so2xh = 0;
}
}
else//hết chỗ trống nhưng chưa chắc là ko còn chơi đc nữa
{
if (ConChoiDc() == 0)
{
MessageBox.Show("Tèn ten thua rồi nhé !!!\n Điểm của bạn
là :"+Diem, "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
CoThua = 1;
}
}
}
//hàm kiểm tra xem còn chỗ trống ko
//còn >1
//hết >0
int KiemTraChoTrong()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
if (a[i, j] == 0)//còn chỗ trống
return 1;
return 0;
}
//hàm xử lí khi bấm nút
void XuLyNutBam(int nutBam)
{
int[] Nho = new int[5];
if (nutBam == 97)// chữ a >left
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
Nho[j] = a[i, j];
XuLyMat(Nho);
for (int j = 0; j < 4; j++)
a[i, j] = Nho[j];
}
}
if (nutBam == 100)// chữ d >right
{
for (int i = 0; i < 4; i++)
{
for (int j = 3; j >=0; j )
Nho[3-j] = a[i, j];
XuLyMat(Nho);
for (int j = 0; j < 4; j++)
a[i, j] = Nho[3-j];
}
}
if (nutBam == 115)// chữ s >down
{
for (int j = 0; j < 4; j++)
{
for (int i = 3; i >=0; i )
Nho[3 - i] = a[i, j];
XuLyMat(Nho);
for (int i = 0; i< 4; i++)
a[i, j] = Nho[3 - i];
}
}
if (nutBam == 119)// chữ w >up
{
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 4; i++)
Nho[i] = a[i, j];
XuLyMat(Nho);
for (int i = 0; i < 4; i++)
a[i, j] = Nho[i];
}
}
}
//hàm xử lý ma trận NhoMat
void XuLyMat(int[] NhoMat)
{
int ii, jj, luu;
ii = 0;
luu = 0;
while (ii <= 3)
{
while (NhoMat[ii] == 0)
{
if (ii >= 4) return;
else
ii++;
}
if (ii == 3)
{
NhoMat[luu] = NhoMat[ii];
if (ii != luu)
NhoMat[ii] = 0;
return;
}
jj = ii + 1;
while (NhoMat[jj] == 0)
{
if (jj >= 4)
{
NhoMat[luu] = NhoMat[ii];
if (ii != luu)
NhoMat[ii] = 0;
return;
}
else
jj++;
}
//hai số = nhau cộng đc
if (NhoMat[ii] == NhoMat[jj])
{
NhoMat[luu] = NhoMat[ii] * 2;
if (ii != luu)
NhoMat[ii] = 0;
NhoMat[jj] = 0;
//tính điểm
Diem += NhoMat[ii] * 2;
lbDiemSo.Text = Diem.ToString();
}
else
{
NhoMat[luu] = NhoMat[ii];
if (ii != luu)
NhoMat[ii] = 0;
}
ii = jj;
luu++;
}
}
//hàm kiểm tra xem còn chơi đc ko
//còm ít nhất hai ô có giá trị bằng
//nhau trên hàng ngang hoặc hàng dọc
int ConChoiDc()
{
for(int i=0;i<4;i++)
for (int j = 0; j < 4; j++)
{
if (i + 1 < 4)
if (a[i, j] == a[i + 1, j])
return 1;
if (j + 1 < 4)
if (a[i, j] == a[i, j + 1])
return 1;
if (i - 1 >= 0)
if (a[i, j] == a[i - 1, j])
return 1;
if (j - 1 >= 0)
if (a[i, j] == a[i, j - 1])
return 1;
}
return 0;
}
//Màu sắc cho trò chơi :D
// 2 4 8 16 32 64 128 256 512 1024 2048 4096
void MauSac()
{
//số 0 với khoảng trắng
khongMau();
//số 2
mauSo2();
//số 4
mauSo4();
//số 8
mauSo8();
//số 16
mauSo16();
//số 32
mauSo32();
//số 64
mauSo64();
//số 128
mauSo128();
//số 256
mauSo256();
//số 512
mauSo512();
//số 1024
mauSo1024();
//số 2048
mauSo2048();
//số 4096
mauSo4096();
//các số khác
mauConLai();
}
//11 màu
//không màu white
void khongMau()
{
if (a00.Text == "" )
a00.BackColor = Color.White;
//
if (a01.Text == "" )
a01.BackColor = Color.White;
//
if (a02.Text == "" )
a02.BackColor = Color.White;
//
if (a03.Text == "" )
a03.BackColor = Color.White;
//
if (a10.Text == "" )
a10.BackColor = Color.White;
//
if (a11.Text == "" )
a11.BackColor = Color.White;
//
if (a12.Text == "" )
a12.BackColor = Color.White;
//
if (a13.Text == "" )
a13.BackColor = Color.White;
//
if (a20.Text == "" )
a20.BackColor = Color.White;
//
if (a21.Text == "" )
a21.BackColor = Color.White;
//
if (a22.Text == "" )
a22.BackColor = Color.White;
//
if (a23.Text == "" )
a23.BackColor = Color.White;
//
if (a30.Text == "" )
a30.BackColor = Color.White;
//
if (a31.Text == "" )
a31.BackColor = Color.White;
//
if (a32.Text == "" )
a32.BackColor = Color.White;
//
if (a33.Text == "" )
a33.BackColor = Color.White;
}
//màu số 2 AliceBlue
void mauSo2()
{
if (a00.Text == "2")
a00.BackColor = Color.AliceBlue;
//
if (a01.Text == "2")
a01.BackColor = Color.AliceBlue;
//
if (a02.Text == "2")
a02.BackColor = Color.AliceBlue;
//
if (a03.Text == "2")
a03.BackColor = Color.AliceBlue;
//
if (a10.Text == "2")
a10.BackColor = Color.AliceBlue;
//
if (a11.Text == "2")
a11.BackColor = Color.AliceBlue;
//
if (a12.Text == "2")
a12.BackColor = Color.AliceBlue;
//
if (a13.Text == "2")
a13.BackColor = Color.AliceBlue;
//
if (a20.Text == "2")
a20.BackColor = Color.AliceBlue;
//
if (a21.Text == "2")
a21.BackColor = Color.AliceBlue;
//
if (a22.Text == "2")
a22.BackColor = Color.AliceBlue;
//
if (a23.Text == "2")
a23.BackColor = Color.AliceBlue;
//
if (a30.Text == "2")
a30.BackColor = Color.AliceBlue;
//
if (a31.Text == "2")
a31.BackColor = Color.AliceBlue;
//
if (a32.Text == "2")
a32.BackColor = Color.AliceBlue;
//
if (a33.Text == "2")
a33.BackColor = Color.AliceBlue;
}
//màu số 4 GreenYellow
void mauSo4()
{
if (a00.Text == "4")
a00.BackColor = Color.GreenYellow;
//
if (a01.Text == "4")
a01.BackColor = Color.GreenYellow;
//
if (a02.Text == "4")
a02.BackColor = Color.GreenYellow;
//
if (a03.Text == "4")
a03.BackColor = Color.GreenYellow;
//
if (a10.Text == "4")
a10.BackColor = Color.GreenYellow;
//
if (a11.Text == "4")
a11.BackColor = Color.GreenYellow;
//
if (a12.Text == "4")
a12.BackColor = Color.GreenYellow;
//
if (a13.Text == "4")
a13.BackColor = Color.GreenYellow;
//
if (a20.Text == "4")
a20.BackColor = Color.GreenYellow;
//
if (a21.Text == "4")
a21.BackColor = Color.GreenYellow;
//
if (a22.Text == "4")
a22.BackColor = Color.GreenYellow;
//
if (a23.Text == "4")
a23.BackColor = Color.GreenYellow;
//
if (a30.Text == "4")
a30.BackColor = Color.GreenYellow;
//
if (a31.Text == "4")
a31.BackColor = Color.GreenYellow;
//
if (a32.Text == "4")
a32.BackColor = Color.GreenYellow;
//
if (a33.Text == "4")
a33.BackColor = Color.GreenYellow;
}
//màu số 8 Lime
void mauSo8()
{
string So = "8";
if (a00.Text == So)
a00.BackColor = Color.Lime;
//
if (a01.Text == So)
a01.BackColor = Color.Lime;
//
if (a02.Text == So)
a02.BackColor = Color.Lime;
//
if (a03.Text == So)
a03.BackColor = Color.Lime;
//
if (a10.Text == So)
a10.BackColor = Color.Lime;
//
if (a11.Text == So)
a11.BackColor = Color.Lime;
//
if (a12.Text == So)
a12.BackColor = Color.Lime;
//
if (a13.Text == So)
a13.BackColor = Color.Lime;
//
if (a20.Text == So)
a20.BackColor = Color.Lime;
//
if (a21.Text == So)
a21.BackColor = Color.Lime;
//
if (a22.Text == So)
a22.BackColor = Color.Lime;
//
if (a23.Text == So)
a23.BackColor = Color.Lime;
//
if (a30.Text == So)
a30.BackColor = Color.Lime;
//
if (a31.Text == So)
a31.BackColor = Color.Lime;
//
if (a32.Text == So)
a32.BackColor = Color.Lime;
//
if (a33.Text == So)
a33.BackColor = Color.Lime;
}
//màu số 16 SpringGreen
void mauSo16()
{
string So = "16";
if (a00.Text == So)
a00.BackColor = Color.SpringGreen;
//
if (a01.Text == So)
a01.BackColor = Color.SpringGreen;
//
if (a02.Text == So)
a02.BackColor = Color.SpringGreen;
//
if (a03.Text == So)
a03.BackColor = Color.SpringGreen;
//
if (a10.Text == So)
a10.BackColor = Color.SpringGreen;
//
if (a11.Text == So)
a11.BackColor = Color.SpringGreen;
//
if (a12.Text == So)
a12.BackColor = Color.SpringGreen;
//
if (a13.Text == So)
a13.BackColor = Color.SpringGreen;
//
if (a20.Text == So)
a20.BackColor = Color.SpringGreen;
//
if (a21.Text == So)
a21.BackColor = Color.SpringGreen;
//
if (a22.Text == So)
a22.BackColor = Color.SpringGreen;
//
if (a23.Text == So)
a23.BackColor = Color.SpringGreen;
//
if (a30.Text == So)
a30.BackColor = Color.SpringGreen;
//
if (a31.Text == So)
a31.BackColor = Color.SpringGreen;
//
if (a32.Text == So)
a32.BackColor = Color.SpringGreen;
//
if (a33.Text == So)
a33.BackColor = Color.SpringGreen;
}
//màu số 32 Green
void mauSo32()
{
string So = "32";
if (a00.Text == So)
a00.BackColor = Color.Green;
//
if (a01.Text == So)
a01.BackColor = Color.Green;
//
if (a02.Text == So)
a02.BackColor = Color.Green;
//
if (a03.Text == So)
a03.BackColor = Color.Green;
//
if (a10.Text == So)
a10.BackColor = Color.Green;
//
if (a11.Text == So)
a11.BackColor = Color.Green;
//
if (a12.Text == So)
a12.BackColor = Color.Green;
//
if (a13.Text == So)
a13.BackColor = Color.Green;
//
if (a20.Text == So)
a20.BackColor = Color.Green;
//
if (a21.Text == So)
a21.BackColor = Color.Green;
//
if (a22.Text == So)
a22.BackColor = Color.Green;
//
if (a23.Text == So)
a23.BackColor = Color.Green;
//
if (a30.Text == So)
a30.BackColor = Color.Green;
//
if (a31.Text == So)
a31.BackColor = Color.Green;
//
if (a32.Text == So)
a32.BackColor = Color.Green;
//
if (a33.Text == So)
a33.BackColor = Color.Green;
}
//màu số 64 BlanchedAlmond
void mauSo64()
{
string So = "64";
if (a00.Text == So)
a00.BackColor = Color.BlanchedAlmond;
//
if (a01.Text == So)
a01.BackColor = Color.BlanchedAlmond;
//
if (a02.Text == So)
a02.BackColor = Color.BlanchedAlmond;
//
if (a03.Text == So)
a03.BackColor = Color.BlanchedAlmond;
//
if (a10.Text == So)
a10.BackColor = Color.BlanchedAlmond;
//
if (a11.Text == So)
a11.BackColor = Color.BlanchedAlmond;
//
if (a12.Text == So)
a12.BackColor = Color.BlanchedAlmond;
//
if (a13.Text == So)
a13.BackColor = Color.BlanchedAlmond;
//
if (a20.Text == So)
a20.BackColor = Color.BlanchedAlmond;
//
if (a21.Text == So)
a21.BackColor = Color.BlanchedAlmond;
//
if (a22.Text == So)
a22.BackColor = Color.BlanchedAlmond;
//
if (a23.Text == So)
a23.BackColor = Color.BlanchedAlmond;
//
if (a30.Text == So)
a30.BackColor = Color.BlanchedAlmond;
//
if (a31.Text == So)
a31.BackColor = Color.BlanchedAlmond;
//
if (a32.Text == So)
a32.BackColor = Color.BlanchedAlmond;
//
if (a33.Text == So)
a33.BackColor = Color.BlanchedAlmond;
}
//màu số 128 Khaki
void mauSo128()
{
string So = "128";
if (a00.Text == So)
a00.BackColor = Color.Khaki;
//
if (a01.Text == So)
a01.BackColor = Color.Khaki;
//
if (a02.Text == So)
a02.BackColor = Color.Khaki;
//
if (a03.Text == So)
a03.BackColor = Color.Khaki;
//
if (a10.Text == So)
a10.BackColor = Color.Khaki;
//
if (a11.Text == So)
a11.BackColor = Color.Khaki;
//
if (a12.Text == So)
a12.BackColor = Color.Khaki;
//
if (a13.Text == So)
a13.BackColor = Color.Khaki;
//
if (a20.Text == So)
a20.BackColor = Color.Khaki;
//
if (a21.Text == So)
a21.BackColor = Color.Khaki;
//
if (a22.Text == So)
a22.BackColor = Color.Khaki;
//
if (a23.Text == So)
a23.BackColor = Color.Khaki;
//
if (a30.Text == So)
a30.BackColor = Color.Khaki;
//
if (a31.Text == So)
a31.BackColor = Color.Khaki;
//
if (a32.Text == So)
a32.BackColor = Color.Khaki;
//
if (a33.Text == So)
a33.BackColor = Color.Khaki;
}
//màu số 256 Gold
void mauSo256()
{
string So = "256";
if (a00.Text == So)
a00.BackColor = Color.Gold;
//
if (a01.Text == So)
a01.BackColor = Color.Gold;
//
if (a02.Text == So)
a02.BackColor = Color.Gold;
//
if (a03.Text == So)
a03.BackColor = Color.Gold;
//
if (a10.Text == So)
a10.BackColor = Color.Gold;
//
if (a11.Text == So)
a11.BackColor = Color.Gold;
//
if (a12.Text == So)
a12.BackColor = Color.Gold;
//
if (a13.Text == So)
a13.BackColor = Color.Gold;
//
if (a20.Text == So)
a20.BackColor = Color.Gold;
//
if (a21.Text == So)
a21.BackColor = Color.Gold;
//
if (a22.Text == So)
a22.BackColor = Color.Gold;
//
if (a23.Text == So)
a23.BackColor = Color.Gold;
//
if (a30.Text == So)
a30.BackColor = Color.Gold;
//
if (a31.Text == So)
a31.BackColor = Color.Gold;
//
if (a32.Text == So)
a32.BackColor = Color.Gold;
//
if (a33.Text == So)
a33.BackColor = Color.Gold;
}
//màu số 512 Yellow
void mauSo512()
{
string So = "512";
if (a00.Text == So)
a00.BackColor = Color.Yellow;
//
if (a01.Text == So)
a01.BackColor = Color.Yellow;
//
if (a02.Text == So)
a02.BackColor = Color.Yellow;
//
if (a03.Text == So)
a03.BackColor = Color.Yellow;
//
if (a10.Text == So)
a10.BackColor = Color.Yellow;
//
if (a11.Text == So)
a11.BackColor = Color.Yellow;
//
if (a12.Text == So)
a12.BackColor = Color.Yellow;
//
if (a13.Text == So)
a13.BackColor = Color.Yellow;
//
if (a20.Text == So)
a20.BackColor = Color.Yellow;
//
if (a21.Text == So)
a21.BackColor = Color.Yellow;
//
if (a22.Text == So)
a22.BackColor = Color.Yellow;
//
if (a23.Text == So)
a23.BackColor = Color.Yellow;
//
if (a30.Text == So)
a30.BackColor = Color.Yellow;
//
if (a31.Text == So)
a31.BackColor = Color.Yellow;
//
if (a32.Text == So)
a32.BackColor = Color.Yellow;
//
if (a33.Text == So)
a33.BackColor = Color.Yellow;
}
//màu số 1024 PeachPuff
void mauSo1024()
{
string So = "1024";
if (a00.Text == So)
a00.BackColor = Color.PeachPuff;
//
if (a01.Text == So)
a01.BackColor = Color.PeachPuff;
//
if (a02.Text == So)
a02.BackColor = Color.PeachPuff;
//
if (a03.Text == So)
a03.BackColor = Color.PeachPuff;
//
if (a10.Text == So)
a10.BackColor = Color.PeachPuff;
//
if (a11.Text == So)
a11.BackColor = Color.PeachPuff;
//
if (a12.Text == So)
a12.BackColor = Color.PeachPuff;
//
if (a13.Text == So)
a13.BackColor = Color.PeachPuff;
//
if (a20.Text == So)
a20.BackColor = Color.PeachPuff;
//
if (a21.Text == So)
a21.BackColor = Color.PeachPuff;
//
if (a22.Text == So)
a22.BackColor = Color.PeachPuff;
//
if (a23.Text == So)
a23.BackColor = Color.PeachPuff;
//
if (a30.Text == So)
a30.BackColor = Color.PeachPuff;
//
if (a31.Text == So)
a31.BackColor = Color.PeachPuff;
//
if (a32.Text == So)
a32.BackColor = Color.PeachPuff;
//
if (a33.Text == So)
a33.BackColor = Color.PeachPuff;
}
//màu số 2048 Orange
void mauSo2048()
{
string So = "2048";
if (a00.Text == So)
a00.BackColor = Color.Orange;
//
if (a01.Text == So)
a01.BackColor = Color.Orange;
//
if (a02.Text == So)
a02.BackColor = Color.Orange;
//
if (a03.Text == So)
a03.BackColor = Color.Orange;
//
if (a10.Text == So)
a10.BackColor = Color.Orange;
//
if (a11.Text == So)
a11.BackColor = Color.Orange;
//
if (a12.Text == So)
a12.BackColor = Color.Orange;
//
if (a13.Text == So)
a13.BackColor = Color.Orange;
//
if (a20.Text == So)
a20.BackColor = Color.Orange;
//