(VB.NET) 2048 Beta V1.3 更新(绝对不是渣界面!)
vb吧
全部回复
仅看楼主
level 11
Lewis_xy 楼主
图片来自:Lewis_xy的百度相册

镇楼

2014年05月25日 21点05分 1
level 11
Lewis_xy 楼主
Beta V1.3更新:
1 彻底优化界面(终于可以摘掉渣界面的帽子了)
2 增加了移动次数的统计(Moves)
下载地址:
http://pan(点)baidu.com/s/1sjK0mTZ
2014年05月25日 21点05分 2
下载地址还能再发一下吗[泪]
2020年11月22日 10点11分
level 13
顶赞\(≥▽≤)/\(≥▽≤)/\(≥▽≤)/\(≥▽≤)/\(≥▽≤)/
2014年05月25日 21点05分 3
谢顶
2014年05月25日 23点05分
level 13
顶楼主,
2014年05月26日 00点05分 4
谢顶。
2014年05月26日 01点05分
level 11
Lewis_xy 楼主
已发现小小的BUG:
方块2和4的字号偶尔会变小,不过影响不太大,以后会修。
2014年05月26日 01点05分 5
level 12
方格移动和出现的动画有吗?
-----------From 度娘贴吧客户端Beta11.11
2014年05月26日 02点05分 6
暂时还没有,VB.NET写graphic实在费劲。不过也不是特难,下个版本可以有,没有也有没有的好处,就是可以快速刷分,狂按WSAD或者方向键就行了,有动画不好刷,也许下个版本会有AFK挂机器。
2014年05月26日 02点05分
level 12
不开源是神马心态?
2014年05月26日 09点05分 7
等会儿发开源的
2014年05月26日 12点05分
level 12
不开源无爱,难道是在秀?
C++写的2048,可以编译为android程序,有动画效果=.=
[无效] http://pan.baidu.com/s/1kTFS5uv
2014年05月26日 09点05分 8
哇塞 大神呐!!!!!!!! 膜拜!
2014年05月26日 09点05分
果然是大神,C++我虽然稍微懂点,但没用c++写过windows form的程序。膜拜膜拜。
2014年05月26日 13点05分
level 11
Lewis_xy 楼主
代码比较渣,凑乎看。
(VB 2010)
界面很简单,放了16个标签表示16个格子,还有3个标签分别是分数,时间和移动次数。当时还不会弄控件数组,所以废了我好大劲,只求别喷。
Public Class Form1
Public number(3, 3) As Integer
Public priornumber(3, 3) As Integer
Public numberstring(3, 3) As String
Public time As Integer = 0
Private rand As New Random
Public score As Long
Public moves As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
timertime.Start()
generatenumber()
generatenumber()
End Sub
Private Sub generatenumber()
Dim newnumber As Integer
Dim emptyspace As Integer = 0
Dim eptspacecount As Integer = 0
Dim exitcheck As Boolean = False
Dim randeptlocation As Integer
If rand.Next(0, 5) = 0 Then
newnumber = 4
Else
newnumber = 2
End If
For i = 0 To 3
For j = 0 To 3
If number(i, j) = 0 Then
emptyspace = emptyspace + 1
End If
Next
Next
randeptlocation = rand.Next(1, (emptyspace + 1))
For i = 0 To 3
For j = 0 To 3
If number(i, j) = 0 Then
eptspacecount = eptspacecount + 1
If eptspacecount = randeptlocation Then
number(i, j) = newnumber
exitcheck = True
Exit For
End If
End If
Next
If exitcheck = True Then
exitcheck = False
Exit For
End If
Next
End Sub
Private Sub updatenumber()
For i = 0 To 3
For j = 0 To 3
If number(i, j) > 0 Then
numberstring(i, j) = number(i, j).ToString
Else
numberstring(i, j) = ""
End If
Next
Next
lblgamescore.Text = score.ToString
lbl00.Text = numberstring(0, 0)
updatecolors(lbl00)
lbl01.Text = numberstring(0, 1)
updatecolors(lbl01)
lbl02.Text = numberstring(0, 2)
updatecolors(lbl02)
lbl03.Text = numberstring(0, 3)
updatecolors(lbl03)
lbl10.Text = numberstring(1, 0)
updatecolors(lbl10)
lbl11.Text = numberstring(1, 1)
updatecolors(lbl11)
lbl12.Text = numberstring(1, 2)
updatecolors(lbl12)
lbl13.Text = numberstring(1, 3)
updatecolors(lbl13)
lbl20.Text = numberstring(2, 0)
updatecolors(lbl20)
lbl21.Text = numberstring(2, 1)
updatecolors(lbl21)
lbl22.Text = numberstring(2, 2)
updatecolors(lbl22)
lbl23.Text = numberstring(2, 3)
updatecolors(lbl23)
lbl30.Text = numberstring(3, 0)
updatecolors(lbl30)
lbl31.Text = numberstring(3, 1)
updatecolors(lbl31)
lbl32.Text = numberstring(3, 2)
updatecolors(lbl32)
lbl33.Text = numberstring(3, 3)
updatecolors(lbl33)
lblmoves.Text = moves
End Sub
2014年05月26日 13点05分 10
level 11
Lewis_xy 楼主
'接上楼:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
updatenumber()
If checkgame() = False Then
Timer1.Stop()
gameover()
End If
End Sub
Private Sub btnnewgame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnewgame.Click
Timer1.Stop()
time = 0
score = 0
moves = 0
For i = 0 To 3
For j = 0 To 3
number(i, j) = 0
Next
Next
generatenumber()
generatenumber()
Timer1.Start()
End Sub
Private Sub moveblocks(ByRef direction As Integer)
Dim i, j, k As Integer
If direction = 1 Then
k = 0
Do While k < 4
For i = 0 To 2
For j = 0 To 3
If number(i, j) = 0 Then
number(i, j) = number(i + 1, j)
number(i + 1, j) = 0
End If
Next
Next
k = k + 1
Loop
End If
If direction = 2 Then
k = 0
Do While k < 4
For i = 3 To 1 Step -1
For j = 0 To 3
If number(i, j) = 0 Then
number(i, j) = number(i - 1, j)
number(i - 1, j) = 0
End If
Next
Next
k = k + 1
Loop
End If
If direction = 3 Then
k = 0
Do While k < 4
For j = 0 To 2
For i = 0 To 3
If number(i, j) = 0 Then
number(i, j) = number(i, j + 1)
number(i, j + 1) = 0
End If
Next
Next
k = k + 1
Loop
End If
If direction = 4 Then
k = 0
Do While k < 4
For j = 3 To 1 Step -1
For i = 0 To 3
If number(i, j) = 0 Then
number(i, j) = number(i, j - 1)
number(i, j - 1) = 0
End If
Next
Next
k = k + 1
Loop
End If
End Sub
2014年05月26日 13点05分 11
level 11
Lewis_xy 楼主
'接上楼:
Private Sub combineblocks(ByRef direction As Integer)
Dim i, j As Integer
If direction = 1 Then
For j = 0 To 3
For i = 0 To 2
If number(i, j) = number(i + 1, j) Then
number(i, j) = number(i, j) + number(i + 1, j)
number(i + 1, j) = 0
score = score + number(i, j)
If number(i, j) = 2048 Then MessageBox.Show("You win! 2048 completed!", "2048")
End If
Next
moveblocks(1)
Next
End If
If direction = 2 Then
For j = 0 To 3
For i = 3 To 1 Step -1
If number(i, j) = number(i - 1, j) Then
number(i, j) = number(i, j) + number(i - 1, j)
number(i - 1, j) = 0
score = score + number(i, j)
If number(i, j) = 2048 Then MessageBox.Show("You win! 2048 completed!", "2048")
End If
Next
moveblocks(2)
Next
End If
If direction = 3 Then
For i = 0 To 3
For j = 0 To 2
If number(i, j) = number(i, j + 1) Then
number(i, j) = number(i, j) + number(i, j + 1)
number(i, j + 1) = 0
score = score + number(i, j)
If number(i, j) = 2048 Then MessageBox.Show("You win! 2048 completed!", "2048")
End If
Next
moveblocks(3)
Next
End If
If direction = 4 Then
For i = 0 To 3
For j = 3 To 1 Step -1
If number(i, j) = number(i, j - 1) Then
number(i, j) = number(i, j) + number(i, j - 1)
number(i, j - 1) = 0
score = score + number(i, j)
If number(i, j) = 2048 Then MessageBox.Show("You win! 2048 completed!", "2048")
End If
Next
moveblocks(4)
Next
End If
End Sub
2014年05月26日 13点05分 12
level 11
Lewis_xy 楼主
接上楼:
Private Function checkgame() As Boolean
Dim i, j As Integer
For i = 0 To 3
For j = 0 To 3
If number(i, j) = 0 Then
Return True
Exit Function
End If
Next
Next
For i = 0 To 2
For j = 0 To 2
If ((number(i, j) = number(i, j + 1)) Or (number(i, j) = number(i + 1, j))) Then
Return True
Exit Function
End If
Next
Next
For i = 0 To 2
For j = 3 To 1 Step -1
If ((number(i, j) = number(i, j - 1)) Or (number(i, j) = number(i + 1, j))) Then
Return True
Exit Function
End If
Next
Next
For i = 3 To 1 Step -1
For j = 3 To 1 Step -1
If ((number(i, j) = number(i, j - 1)) Or (number(i, j) = number(i - 1, j))) Then
Return True
Exit Function
End If
Next
Next
For i = 3 To 1 Step -1
For j = 0 To 2
If ((number(i, j) = number(i, j + 1)) Or (number(i, j) = number(i - 1, j))) Then
Return True
Exit Function
End If
Next
Next
Return False
End Function
Private Sub gameover()
Dim i, j As Integer
Timer1.Stop()
timertime.Stop()
If MessageBox.Show("Gameover, your score is " & score & ". Would you like to try again?", "2048 Gameover", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
time = 0
lblgametime.Text = 0
score = 0
moves = 0
For i = 0 To 3
For j = 0 To 3
number(i, j) = 0
Next
Next
generatenumber()
generatenumber()
Timer1.Start()
timertime.Start()
Else
Me.Close()
End If
End Sub
2014年05月26日 13点05分 13
level 11
Lewis_xy 楼主
接上楼:
'About Keys Controls
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
For i = 0 To 3
For j = 0 To 3
priornumber(i, j) = number(i, j)
Next
Next
If e.KeyCode = Keys.Up Or e.KeyCode = Keys.W Then
moveblocks(1)
combineblocks(1)
End If
If e.KeyCode = Keys.Down Or e.KeyCode = Keys.S Then
moveblocks(2)
combineblocks(2)
End If
If e.KeyCode = Keys.Left Or e.KeyCode = Keys.A Then
moveblocks(3)
combineblocks(3)
End If
If e.KeyCode = Keys.Right Or e.KeyCode = Keys.D Then
moveblocks(4)
combineblocks(4)
End If
For i = 0 To 3
For j = 0 To 3
If number(i, j) <> priornumber(i, j) Then
generatenumber()
moves = moves + 1
Exit Sub
End If
Next
Next
End Sub
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Up Then Return False
If keyData = Keys.Down Then Return False
If keyData = Keys.Left Then Return False
If keyData = Keys.Right Then
Return False
Else
Return MyBase.ProcessDialogKey(keyData)
End If
End Function
2014年05月26日 13点05分 14
level 11
Lewis_xy 楼主
‘接上楼:
'timecontrol
Private Sub timertime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timertime.Tick
time = time + 1
lblgametime.Text = time.ToString
End Sub
'colors and fonts
Private Sub updatecolors(ByRef lbl As Label)
If lbl.Text = "" Then
lbl.BackColor = Color.FromArgb(238, 223, 204) 'empty color
End If
If lbl.Text = "2" Then
lbl.BackColor = Color.FromArgb(255, 255, 255) 'white
lbl.ForeColor = Color.Black
''problem here
End If
If lbl.Text = "4" Then
lbl.BackColor = Color.FromArgb(255, 250, 205) 'light yellow
lbl.ForeColor = Color.Black
End If
If lbl.Text = "8" Then
lbl.BackColor = Color.FromArgb(255, 222, 173) 'light orange
lbl.ForeColor = Color.White
End If
If lbl.Text = "16" Then
lbl.BackColor = Color.FromArgb(255, 211, 145) 'light orange
lbl.ForeColor = Color.White
End If
If lbl.Text = "32" Then
lbl.BackColor = Color.FromArgb(255, 160, 115) 'light red
lbl.ForeColor = Color.White
End If
If lbl.Text = "64" Then
lbl.BackColor = Color.FromArgb(255, 64, 64) 'red
lbl.ForeColor = Color.White
End If
If lbl.Text = "128" Then
lbl.BackColor = Color.FromArgb(255, 246, 143) 'light yellow
lbl.Font = New Font("calibri", 28, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "256" Then
lbl.BackColor = Color.FromArgb(255, 235, 120) 'light yellow
lbl.Font = New Font("calibri", 28, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "512" Then
lbl.BackColor = Color.FromArgb(255, 225, 115) 'light yellow
lbl.Font = New Font("calibri", 28, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "1024" Then
lbl.BackColor = Color.FromArgb(255, 230, 100) 'yellow
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "1024" Then
lbl.BackColor = Color.FromArgb(255, 230, 100) 'yellow
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "2048" Then
lbl.BackColor = Color.FromArgb(255, 230, 30) ' dark yellow
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "4096" Then
lbl.BackColor = Color.FromArgb(238, 174, 238) ' light purple
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "8192" Then
lbl.BackColor = Color.FromArgb(238, 145, 238) ' light purple
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "4096" Then
lbl.BackColor = Color.FromArgb(238, 174, 238) ' dark yellow
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "8192" Then
lbl.BackColor = Color.FromArgb(180, 100, 238) ' dark yellow
lbl.Font = New Font("calibri", 24, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "16384" Then
lbl.BackColor = Color.FromArgb(150, 100, 238) ' dark yellow
lbl.Font = New Font("calibri", 20, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "32768" Then
lbl.BackColor = Color.FromArgb(40, 40, 238) ' dark yellow
lbl.Font = New Font("calibri", 20, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
If lbl.Text = "65536" Then
lbl.BackColor = Color.FromArgb(0, 0, 0) ' dark yellow
lbl.Font = New Font("calibri", 20, FontStyle.Bold)
lbl.ForeColor = Color.White
End If
End Sub
End Class
2014年05月26日 13点05分 15
(完)
2014年05月26日 13点05分
吧务
level 13
好冗长。。。比我厉害!我不会c++也不会vb2010.。。。。。
2014年05月26日 14点05分 16
大神,vb.net真心比vb简单,虽然里面的东西稍微多一点,但是很好写,而且操作界面设计的很人性化,很好入手。c++可以理解为我只会入门的那点东西,好久都不写c++了,现在基本能都忘了。
2014年05月26日 15点05分
回复 Lewis_xy :net比vb难 要转过去 好歹vb要会类吧 说一种语言简单要么是天才要么是。。。。。
2014年05月26日 21点05分
1