

{"id":100476,"date":"2021-09-03T16:05:41","date_gmt":"2021-09-03T10:35:41","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=100476"},"modified":"2026-06-01T12:39:43","modified_gmt":"2026-06-01T07:09:43","slug":"python-2048-game","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-2048-game\/","title":{"rendered":"Create 2048 Game in Python"},"content":{"rendered":"<p>This is a popular sliding tile puzzle for single player. Let\u2019s start developing this amazing game on our own. While making the 2048 project in Python, we will learn various concepts. Let\u2019s start developing this cool project.<\/p>\n<h3>About 2048 Game<\/h3>\n<p>In this project the player has to slide the numbered tiles on the grid to create a tile with number 2048. The player can continue to play the game after reaching the 2048 tile and can create tiles with larger numbers. The player will also get points while playing the game.<\/p>\n<h3>Python 2048 Game project<\/h3>\n<p>The objective of this project is to implement 2048 Game using python. We need a pygame module to develop this project. We also need to import sys, time, constants and random modules.<\/p>\n<h3>Project Prerequisites<\/h3>\n<p>To develop this Python 2048 game project knowledge of pygame modules is a must. You also need the knowledge of python to complete this project.<\/p>\n<h3>Download 2048 Game<\/h3>\n<p>Please download source code of python 2048 Game: <a href=\"https:\/\/drive.google.com\/file\/d\/1MSwzJ8DPHEuVbX5yK6hq6x9jE9PKEFIC\/view?usp=drive_link\"><strong>2048 Game in Python<\/strong><\/a><\/p>\n<h3>Project File Structure<\/h3>\n<p>Steps to follow to built python 2048 Game:<\/p>\n<p>1.Install pygame module<br \/>\n2. Importing Modules<br \/>\n3. Initializing game window<br \/>\n4.Defining colors and function<br \/>\n5.Defining Main function<br \/>\n6.Function to check whether movement of tiles is possible or not<br \/>\n7.Defining function for merging tiles<br \/>\n8.Other functions<\/p>\n<h4>1. Install pygame module:<\/h4>\n<p>Multimedia applications like games are made by pygame which is a free and open source python programming language library. Pygame consists of sound libraries and computer graphics that are designed to be used with python. Installation of pygame is mandatory to start the project. Write the following code on your command prompt to install pygame.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install pygame\r\n<\/pre>\n<h4>2. Importing Modules:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import pygame,sys,time\r\nfrom pygame.locals import *\r\nfrom constants import *\r\nfrom random import *<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. sys: Different parts of the python runtime environment are manipulated with the sys module.<br \/>\nb. time: It provides functions to work with time.<br \/>\nc. pygame.locals: Various constants that are used by pygame are available in this module.<br \/>\nd. Random: pseudo random numbers are generated with this module.<\/p>\n<h4>3. Initializing game window:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pygame.init()\r\n \r\nsurface = pygame.display.set_mode((400,500),0,32)\r\npygame.display.set_caption(\"2048 Game by DataFlair\")\r\n \r\nfont = pygame.font.SysFont(\"monospace\",40)\r\nfontofscore = pygame.font.SysFont(\"monospace\",30)\r\n \r\ntileofmatrix = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]\r\nundomatrix = []\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. pygame.init(): All the imported pygame modules are initialized with pygame.init.<br \/>\nb. set_mode(): It sets up the screen for display.<br \/>\nc. set_caption(): It displays the title in the parentheses on the top of the pygame window.<br \/>\nd. pygame.font.SysFont(): It loads the font from the system with the help of pygame.<br \/>\ne. tileofmatrix: It\u2019s a nested list that will initially have value 0 on every tile.<\/p>\n<h4>4. Defining colors and function:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">black = (0,0,0)\r\nred = (255,0,0)\r\norange = (255,152,0)\r\ndeeporange = (255,87,34)\r\nbrown = (121,85,72)\r\ngreen = (0,128,0)\r\nlgreen = (139,195,74)\r\nteal = (0,150,136)\r\nblue  = (33,150,136)\r\npurple = (156,39,176)\r\npink = (234,30,99)\r\ndeeppurple = (103,58,183)\r\n \r\n \r\ncolordict = {\r\n    0:black,\r\n    2:red,\r\n    4:green,\r\n    8:purple,\r\n    16:deeppurple,\r\n    32:deeporange,\r\n    64:teal,\r\n    128:lgreen,\r\n    256:pink,\r\n    512:orange,\r\n    1024:black,\r\n    2048:brown\r\n}\r\n \r\ndef getcolor(i):\r\n    return colordict[i]\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. getcolor(): It is a function that returns a dictionary of colours.<br \/>\nb. colordict: It is a dictionary of colours.<\/p>\n<h4>5. Defining Main function:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def mainfunction(fromLoaded = False):\r\n    \r\n    if not fromLoaded:\r\n        placerandomtile()\r\n        placerandomtile()\r\n    printmatrix()\r\n \r\n \r\n    while True:\r\n        for event in pygame.event.get():\r\n            if event.type == QUIT:\r\n                pygame.quit()\r\n                sys.exit()\r\n            \r\n            if checkIfCanGo() == True:\r\n                if event.type == KEYDOWN:\r\n                    if isArrow(event.key):\r\n                        rotations = getrotations(event.key)\r\n                        addToUndo()\r\n                        for i in range(0,rotations):\r\n                            rotatematrixclockwise()\r\n \r\n                        if canmove():\r\n                            movetiles()\r\n                            mergetiles()\r\n                            placerandomtile()\r\n \r\n                        for j in range(0,(4-rotations)%4):\r\n                            rotatematrixclockwise()\r\n                            \r\n                        printmatrix()\r\n            else: # just checking wait\r\n                gameover()\r\n \r\n            if event.type == KEYDOWN:\r\n                global sizeofboard\r\n \r\n                if event.key == pygame.K_r:\r\n                 \r\n                    reset()\r\n                if 50&lt;event.key and 56 &gt; event.key:\r\n                    \r\n                    sizeofboard = event.key - 48\r\n                    reset()\r\n                if event.key == pygame.K_s:\r\n                   \r\n                    savegame()\r\n                elif event.key == pygame.K_l:\r\n                    loadgame()\r\n                    \r\n                elif event.key == pygame.K_u:\r\n                    undo()\r\n                   \r\n        pygame.display.update()\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. get(): List of all the unprocessed events are returned with get().<br \/>\nb. quit: It exits a python program.<br \/>\nc. KEYDOWN: It detects if a key is pressed or not.<br \/>\nd. K_r: If key r is pressed reset() function is called to reset the game.<br \/>\ne. K_s: If key s is pressed savegame() function is called which saves the game.<br \/>\nf. K_l:If key l is pressed, a loadgame() function is called which loads the game.<br \/>\ng. K_u: If key u is pressed undo() function is called.<\/p>\n<h4>6. Function to check whether movement of tiles is possible or not:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def canmove():\r\n    for i in range(0,sizeofboard):\r\n        for j in range(1,sizeofboard):\r\n            if tileofmatrix[i][j-1] == 0 and tileofmatrix[i][j] &gt; 0:\r\n                return True \r\n            elif (tileofmatrix[i][j-1] == tileofmatrix[i][j]) and tileofmatrix[i][j-1] != 0:\r\n                return True\r\n    return False\r\n    # This module moves \r\ndef movetiles():\r\n    for i in range(0,sizeofboard):\r\n        for j in range(0,sizeofboard-1):\r\n            \r\n            while tileofmatrix[i][j] == 0 and sum(tileofmatrix[i][j:]) &gt; 0:\r\n                for k in range(j,sizeofboard-1):\r\n                   tileofmatrix[i][k] = tileofmatrix[i][k+1]\r\n                tileofmatrix[i][sizeofboard-1] = 0\r\n\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. canmove(): This function checks whether the movement of tiles is possible or not.<br \/>\nb. movetiles(): It helps in the movement of tiles.<br \/>\nc. sum(): It calculates the sum of the numbers.<\/p>\n<h4>7. Defining function for merging tiles:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def mergetiles():\r\n    global totalpoints\r\n \r\n    for i in range(0,sizeofboard):\r\n        for k in range(0,sizeofboard-1):\r\n            if tileofmatrix[i][k] == tileofmatrix[i][k+1] and tileofmatrix[i][k] != 0:\r\n                tileofmatrix[i][k] = tileofmatrix[i][k]*2\r\n                tileofmatrix[i][k+1] = 0                 totalpoints+= tileofmatrix[i][k]\r\n                movetiles()\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><\/p>\n<p>a. mergetiles(): This function helps in merging the tiles.<br \/>\nb. range(): It helps in performing an action for a specific number of times.<\/p>\n<h4>8. Other functions:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def floor(n):\r\n    return int(n - (n % 1 ))  \r\ndef printmatrix():\r\n        surface.fill(black)\r\n        global sizeofboard\r\n        global totalpoints\r\n \r\n        for i in range(0,sizeofboard):\r\n            for j in range(0,sizeofboard):\r\n                pygame.draw.rect(surface,getcolor(tileofmatrix[i][j]),(i*(400\/sizeofboard),j*(400\/sizeofboard)+100,400\/sizeofboard,400\/sizeofboard))\r\n                label = font.render(str(tileofmatrix[i][j]),1,(255,255,255))\r\n                label2 = fontofscore.render(\"YourScore:\"+str(totalpoints),1,(255,255,255))\r\n                surface.blit(label,(i*(400\/sizeofboard)+30,j*(400\/sizeofboard)+130))\r\n                surface.blit(label2,(10,20))\r\ndef checkIfCanGo():\r\n    for i in range(0,sizeofboard ** 2):         if tileofmatrix[floor(i\/sizeofboard)][i%sizeofboard] == 0:\r\n            return True\r\n    \r\n    for i in range(0,sizeofboard):\r\n        for j in range(0,sizeofboard-1):\r\n            if tileofmatrix[i][j] == tileofmatrix[i][j+1]:\r\n                return True\r\n            elif tileofmatrix[j][i] ==tileofmatrix[j+1][i]:\r\n                return True\r\n    return False\r\ndef convertToLinearMatrix():\r\n \r\n    mat = []\r\n    for i in range(0,sizeofboard ** 2):\r\n        mat.append(tileofmatrix[floor(i\/sizeofboard)][i%sizeofboard])\r\n \r\n    mat.append(totalpoints)\r\n    return mat\r\ndef addToUndo():\r\n    undomatrix.append(convertToLinearMatrix())   \r\ndef rotatematrixclockwise():\r\n    for i in range(0,int(sizeofboard\/2)):\r\n        for k in range(i,sizeofboard- i- 1):\r\n            temp1 = tileofmatrix[i][k]\r\n            temp2 = tileofmatrix[sizeofboard - 1 - k][i]\r\n            temp3 = tileofmatrix[sizeofboard- 1 - i][sizeofboard - 1 - k]\r\n            temp4 = tileofmatrix[k][sizeofboard- 1 - i]\r\n \r\n            tileofmatrix[sizeofboard- 1 - k][i] = temp1\r\n            tileofmatrix[sizeofboard - 1 - i][sizeofboard - 1 - k] = temp2\r\n            tileofmatrix[k][sizeofboard - 1 - i] = temp3\r\n            tileofmatrix[i][k] = temp4\r\n \r\ndef gameover():\r\n    global totalpoints\r\n \r\n    surface.fill(black)\r\n \r\n    label = font.render(\"gameover\",1,(255,255,255))\r\n    label2 =font.render(\"score : \"+str(totalpoints),1,(255,255,255))\r\n    label3 = font.render(\"press 'R' to play again\",1,(255,255,255))\r\n \r\n    surface.blit(label,(50,100))\r\n    surface.blit(label2,(50,200))\r\n    surface.blit(label3,(50,300))\r\n \r\n \r\ndef reset():\r\n    global totalpoints\r\n    global tileofmatrix\r\n \r\n    totalpoints= 0\r\n    surface.fill(black)\r\n    tileofmatrix = [[0 for i in range(0,sizeofboard)] for j in range(0,sizeofboard) ]\r\n    mainfunction()\r\n \r\ndef savegame():\r\n    f = open(\"savedata\",\"w\")\r\n \r\n    line1 = \" \".join([str(tileofmatrix[floor(x\/sizeofboard)][x%sizeofboard]) for x in range(0,sizeofboard ** 2)])\r\n    f.write(line1+\"\\n\")\r\n    f.write(str(sizeofboard)+\"\\n\")\r\n    f.write(str(totalpoints))\r\n    f.close\r\n \r\ndef undo():\r\n    if len(undomatrix) &gt; 0:\r\n        mat = undomatrix.pop()\r\n \r\n        for i in range(0,sizeofboard ** 2):\r\n            tileofmatrix[floor(i\/sizeofboard)][i%sizeofboard] = mat[i]\r\n        global totalpoints\r\n        totalpoints = mat[sizeofboard ** 2]\r\n \r\n        printmatrix()\r\n \r\ndef loadgame():\r\n    global totalpoints\r\n    global sizeofboard\r\n    global tilematrix\r\n \r\n    f = open(\"savedata\",\"r\")\r\n \r\n    mat = (f.readline()).split(' ',sizeofboard ** 2)\r\n    sizeofboard = int(f.readline())\r\n    totalpoints= int(f.readline())\r\n \r\n    for i in range(0,sizeofboard ** 2):\r\n        tileofmatrix[floor(i\/sizeofboard)][i%sizeofboard] = int(mat[i])\r\n \r\n    f.close()\r\n \r\n    mainfunction(True)\r\n \r\n \r\n \r\ndef isArrow(k):\r\n    return (k == pygame.K_UP or k == pygame.K_DOWN or k == pygame.K_LEFT or k == pygame.K_RIGHT)\r\n \r\ndef getrotations(k):\r\n    if k == pygame.K_UP:\r\n        return 0\r\n    elif k == pygame.K_DOWN:\r\n        return 2 \r\n    elif k == pygame.K_LEFT:\r\n        return 1\r\n    elif k == pygame.K_RIGHT:\r\n        return 3\r\nmainfunction()\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><br \/>\na. floor(): It gets the floor value of a value passed in the function.<br \/>\nb. printmatrix(): It prints the matrix on the screen.<br \/>\nc. fill(): It fills the shape with the colour in the parentheses.<br \/>\nd. convertToLinearMatrix(): This module returns a matrix.<br \/>\ne. gameover(): When there is no place in the matrix or the player is out of moves the game gets over.<br \/>\nf. reset(): It resets the game.<br \/>\ng. savegame(): It saves the state of moves.<br \/>\nh. undo(): This function gets the last move.<br \/>\ni. loadgame(): It loads the game for the player.<br \/>\nj. isArrow(): It finds out which key is pressed by the user.<br \/>\nk. K_UP: If the up arrow key is clicked, the function returns 0.<br \/>\nl. K_DOWN:If the down arrow key is clicked, the function returns 2.<br \/>\nm. K_LEFT:If the left arrow key is clicked, the function returns 1.<br \/>\nn. K_RIGHT:If the right arrow key is clicked, the function returns 3.<br \/>\no. mainfunction: It calls the main function.<\/p>\n<h3>Python 2048 Game Output:<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-100487\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output.png\" alt=\"python 2048 game output\" width=\"1920\" height=\"1028\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output.png 1920w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output-768x411.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output-1536x822.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output-720x386.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output-520x278.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-2048-game-output-320x171.png 320w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<h3>Summary:<\/h3>\n<p>We have successfully developed 2048 Game in python with the help of pygame module and python.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2547,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1MSwzJ8DPHEuVbX5yK6hq6x9jE9PKEFIC\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601070926\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1MSwzJ8DPHEuVbX5yK6hq6x9jE9PKEFIC\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-01 12:14:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-05 00:34:27&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-08 16:01:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-16 02:40:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-20 03:08:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-24 02:11:03&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-24 02:11:03&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a popular sliding tile puzzle for single player. Let\u2019s start developing this amazing game on our own. While making the 2048 project in Python, we will learn various concepts. Let\u2019s start developing&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":100486,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[25020,25021,21754,21082,22734],"class_list":["post-100476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-2048-game","tag-python-game","tag-python-game-projects","tag-python-project","tag-python-project-for-beginners"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Create 2048 Game in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Create 2048 game in Python in easy steps. In this game, player has to slide the numbered tiles on the grid to create a tile with number 2048.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-2048-game\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create 2048 Game in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Create 2048 game in Python in easy steps. In this game, player has to slide the numbered tiles on the grid to create a tile with number 2048.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-2048-game\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-03T10:35:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T07:09:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create 2048 Game in Python - DataFlair","description":"Create 2048 game in Python in easy steps. In this game, player has to slide the numbered tiles on the grid to create a tile with number 2048.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-2048-game\/","og_locale":"en_US","og_type":"article","og_title":"Create 2048 Game in Python - DataFlair","og_description":"Create 2048 game in Python in easy steps. In this game, player has to slide the numbered tiles on the grid to create a tile with number 2048.","og_url":"https:\/\/data-flair.training\/blogs\/python-2048-game\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-09-03T10:35:41+00:00","article_modified_time":"2026-06-01T07:09:43+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Create 2048 Game in Python","datePublished":"2021-09-03T10:35:41+00:00","dateModified":"2026-06-01T07:09:43+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/"},"wordCount":780,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg","keywords":["python 2048 game","python game","python game projects","Python project","python project for beginners"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-2048-game\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/","url":"https:\/\/data-flair.training\/blogs\/python-2048-game\/","name":"Create 2048 Game in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg","datePublished":"2021-09-03T10:35:41+00:00","dateModified":"2026-06-01T07:09:43+00:00","description":"Create 2048 game in Python in easy steps. In this game, player has to slide the numbered tiles on the grid to create a tile with number 2048.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-2048-game\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/python-project-2048-game.jpg","width":1200,"height":628,"caption":"python project 2048 game"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-2048-game\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Create 2048 Game in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=100476"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100476\/revisions"}],"predecessor-version":[{"id":148623,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100476\/revisions\/148623"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/100486"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=100476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=100476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=100476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}