Please enable JavaScript to use CodeHS

AP Computer Science A (Cortado)

2048 Lab

Students develop a complete version of the popular puzzle game 2048 by incrementally building its core functionality in Java. They begin by exploring the game mechanics and writing methods to place initial tiles on the board. Next, they implement movement logic to slide and merge tiles in all four directions while updating the score. Students then add a method to detect when the game is over and an optional feature to track and save high scores. Throughout the lab, they reinforce skills in 2D array traversal, control structures, and algorithmic problem-solving while applying object-oriented programming principles to manage game state and user interaction.

This lab can be completed after Unit 4: Data Collections in Cortado, Unit 7: ArrayList in Nitro (with Using Text Files lesson from Cortado), Unit 5: Data Structures in Mocha (with Using Text Files lesson from Cortado).

Lessons

10.1 Activity 1 - Exploring 2048

  • Exploring 2048
  • Activity 1 - Check for Understanding

10.2 Activity 2 – Adding First Two 2s

  • Adding First Two 2s
  • Activity 2 - Check for Understanding

10.3 Activity 3 – Sliding Tiles

  • Sliding Tiles Part A
  • Sliding Tiles Part B
  • Activity 3B - Check for Understanding
  • Sliding Tiles Part C
  • Sliding Tiles Part D
  • +1 more

10.4 Activity 4 – Merging Tiles

  • Merging Tiles Part A
  • Activity 4A - Check for Understanding
  • Merging Tiles Part B
  • Merging Tiles Part C
  • Merging Tiles Part D

10.5 Activity 5 – Game Over

  • Game Over Part A
  • Game Over Part B

Courses that include this module