2048: Difference between revisions

Content added Content deleted
Line 6,431: Line 6,431:
y1 = 0
y1 = 0
y2 = 0
y2 = 0
nScore = 0
button = newlist(size,size)
button = newlist(size,size)
buttonsave = newlist(size,size)
LayoutButtonRow = list(size+2)
moveleft = []
moveleft = []
moveright = []
moveright = []
Line 6,445: Line 6,448:
win = new qWidget() {
win = new qWidget() {
setWindowTitle('2048 Game')
setWindowTitle('2048 Game')
setgeometry(100,100,800,600)
setminimumwidth(300)
setminimumwidth(300)
setminimumheight(300)
setminimumheight(300)
grabkeyboard()
setstylesheet('background-color:white')
move(490,100)
move(490,100)
for n = 1 to size
for n = 1 to size
Line 6,453: Line 6,459:
next
next
next
next
arrow = new qLineedit(win)
newgame = new qLabel(win)
mup = new qPushButton(win)
playerscore = new qLabel(win)
mdown = new qPushButton(win)
mleft = new qPushButton(win)
mright = new qPushButton(win)
newgame = new qPushButton(win)
myfilter = new qallevents(win)
myfilter.setResizeEvent("pResize()")
installeventfilter(myfilter)
myfilter3 = new qAllEvents(win) {
myfilter3 = new qAllEvents(win) {
setMouseButtonPressEvent("pPress()")
setMouseButtonPressEvent("pPress()")
setMouseButtonReleaseEvent("pRelease()")}
setMouseButtonReleaseEvent("pRelease()")}
installeventfilter(myfilter3)
installeventfilter(myfilter3)
pResize()
myfilter2 = new qAllEvents(win) {
show()
setkeypressevent("keypress()") }
installeventfilter(myfilter2)
winwidth = win.width()
winheight = win.height()
for n = 1 to size + 2
LayoutButtonRow[n] = new QHBoxLayout() {
setSpacing(3) }
next
for n = 1 to size
for m = 1 to size
button[n][m] { temp = text() }
buttonsave[n][m] = temp
buttonsave[n][m] = temp
fontsize = 10 + (winheight/25)
fontsize2 = 10 + (winheight/50)
button[n][m] = new MyButton(win) {
setFont(new qFont("Verdana",fontsize,100,0))
setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
setstylesheet('background-color:orange')
show()
}
next
next
for n = 1 to size
for m = 1 to size
LayoutButtonRow[n].AddWidget(button[m][n])
win.show()
temp = buttonsave[n][m]
button[n][m].settext(temp)
next
next
playerscore.close()
playerscore {
setGeometry(0,4*floor(winheight/6),winwidth,floor(winheight/6))
setFont(new qFont("Verdana",fontsize2,100,0))
setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
settext('Play Score: ' + nScore)
show()
}

newgame.close()
newgame {
setGeometry(0,5*floor(winheight/6),winwidth,floor(winheight/6))
setFont(new qFont("Verdana",fontsize2,100,0))
setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
setstylesheet('background-color:violet')
settext('New Game')
myfilter4 = new qallevents(newgame)
myfilter4.setMouseButtonPressEvent("pbegin()")
installeventfilter(myfilter4)
show()
}
LayoutButtonRow[size+1].AddWidget(playerscore)
LayoutButtonRow[size+2].AddWidget(newgame)
LayoutButtonMain = new QVBoxLayout() {
setSpacing(3)
for n = 1 to size+2
AddLayout(LayoutButtonRow[n])
win.show()
next }
win.setLayout(LayoutButtonMain)
win.show()
pbegin()
show()
}
}
exec()
exec()
Line 6,481: Line 6,543:
xx1 = floor(x1/floor(winwidth/4)) - 2
xx1 = floor(x1/floor(winwidth/4)) - 2
xx2 = floor(x2/floor(winwidth/4)) - 2
xx2 = floor(x2/floor(winwidth/4)) - 2
yy1 = floor(y1/floor(winheight/8)) - 1
yy1 = floor(y1/floor(winheight/6)) - 1
yy2 = floor(y2/floor(winheight/8)) - 1
yy2 = floor(y2/floor(winheight/6)) - 1
bool = (yy1 <= size) and (yy2 <= size)
bool = (yy1 <= size) and (yy2 <= size)
if (yy1 = yy2) and (xx2 < xx1) and bool
if (yy1 = yy2) and (xx2 < xx1) and bool
Line 6,496: Line 6,558:
pdown()
pdown()
ok
ok

func pResize()
winwidth = win.width()
winheight = win.height()
arrow.close()
arrow = new qLineedit(win) {
setGeometry(0,7*floor(winheight/8),winwidth,floor(winheight/8))
arrow.setfocus(true)
myfilter2 = new qAllEvents(win) {
setkeypressevent("keypress()")
}
installeventfilter(myfilter2)
}
for n = 1 to size
for m = 1 to size
button[n][m].close()
col = (n-1)*floor(winwidth/4)
row = (m-1)*floor(winheight/8)
fontsize = 10 + (winheight/16)
fontsize2 = 10 + (winheight/50)
button[n][m] = new MyButton(win) {
setGeometry(col,row,winwidth/4,winheight/8)
setFont(new qFont("Verdana",fontsize,100,0))
setalignment(Qt_AlignHCenter | Qt_AlignVCenter)
setstylesheet('background-color:orange')
show()
}
next
next
newgame.close()
newgame = new qPushButton(win) {
setGeometry(0,7*floor(winheight/8),winwidth,floor(winheight/8))
setFont(new qFont("Verdana",fontsize2,100,0))
setstylesheet('background-color:violet')
settext('New Game')
setClickEvent('pbegin()')
show()
}
mup.close()
mup = new qPushButton(win) {
setGeometry(0,5*floor(winheight/8),winwidth/4,floor(winheight/8))
setFont(new qFont("Verdana",fontsize2,100,0))
settext('up')
setClickEvent('pup()')
show()
}
mdown.close()
mdown = new qPushButton(win) {
setGeometry(floor(winwidth/4),5*floor(winheight/8),winwidth/4,floor(winheight/8))
setFont(new qFont("Verdana",fontsize2,100,0))
settext('down')
setClickEvent('pdown()')
show()
}
mleft.close()
mleft = new qPushButton(win) {
setGeometry(2*floor(winwidth/4),5*floor(winheight/8),winwidth/4,floor(winheight/8))
setFont(new qFont("Verdana",fontsize2,100,0))
settext('left')
setClickEvent('pleft()')
show()
}
mright.close()
mright = new qPushButton(win) {
setGeometry(3*floor(winwidth/4),5*floor(winheight/8),winwidth/4,floor(winheight/8))
setFont(new qFont("Verdana",fontsize2,100,0))
settext('right')
setClickEvent('pright()')
show()
}
win.show()
pbegin()


func keypress()
func keypress()
Line 6,590: Line 6,580:
button[rn][rm].settext('2')
button[rn][rm].settext('2')
next
next
arrow.setfocus(true)
nScore = 0
playerscore.settext('Play Score: ')


func pdown()
func pdown()
sleep(0.5)
num = gameover()
num = gameover()
if num = size*size
if num = size*size
Line 6,605: Line 6,597:


func pup()
func pup()
sleep(0.5)
num = gameover()
num = gameover()
if num = size*size
if num = size*size
Line 6,617: Line 6,610:


func pleft()
func pleft()
sleep(0.5)
num = gameover()
num = gameover()
if num = size*size
if num = size*size
Line 6,629: Line 6,623:


func pright()
func pright()
sleep(0.5)
num = gameover()
num = gameover()
if num = size*size
if num = size*size
Line 6,659: Line 6,654:
if (temp1 = temp2) and (temp1 != '0') and (temp2 != '0') and (temp1 != '') and (temp2 != '')
if (temp1 = temp2) and (temp1 != '0') and (temp2 != '0') and (temp1 != '') and (temp2 != '')
if temp != '0' and temp != ''
if temp != '0' and temp != ''
nScore = nScore + temp
playerscore.settext('Play Score: ' + nScore)
flag = 1
moveleft[p] = temp
moveleft[p] = temp
del(moveleft,p+1)
del(moveleft,p+1)
Line 6,696: Line 6,694:
temp = string(number(temp1) + number(temp2))
temp = string(number(temp1) + number(temp2))
if temp != '0' and temp != ''
if temp != '0' and temp != ''
nScore = nScore + temp
playerscore.settext('Play Score: ' + nScore)
flag = 1
flag = 1
moveright[p] = temp
moveright[p] = temp
del(moveright,p-1)
del(moveright,p-1)
if moveright[p-1] = temp
p = p - 1
ok
ok
ok
ok
ok
Line 6,736: Line 6,733:
temp = string(number(temp1) + number(temp2))
temp = string(number(temp1) + number(temp2))
if temp != '0' and temp != ''
if temp != '0' and temp != ''
nScore = nScore + temp
playerscore.settext('Play Score: ' + nScore)
flag = 1
flag = 1
moveup[p] = temp
moveup[p] = temp
Line 6,773: Line 6,772:
temp = string(number(temp1) + number(temp2))
temp = string(number(temp1) + number(temp2))
if temp != '0' and temp != ''
if temp != '0' and temp != ''
nScore = nScore + temp
playerscore.settext('Play Score: ' + nScore)
flag = 1
flag = 1
movedown[p] = temp
movedown[p] = temp