​​This modular courseware teaches students basic programming concepts through game development. These concepts include variables, matrices,


Updated Mon, 30 Jan 2023 21:18:01 +0000

From GitHub

View License on GitHub

Treasure Hunt Game: Learn to Code

View Treasure Hunt Game on File Exchange or Open in MATLAB Online

Curriculum Module
Created with R2022b. Compatible with R2022b and later releases.


This curriculum module contains interactive live scripts that teach fundamental concepts and basic terminology related to programming computers. This includes discussion of variables, matrices, conditional statements, strings, arrays, indexing and functions.

These lessons can be used as part of a lecture, as activities in an instructional setting, or as interactive assignments to be completed outside class.

Please contact the MathWorks online teaching team with any feedback or questions.

Get started with the Treasure Hunt Game: Learn to Code interactive examples

Option 1: Download to Desktop Download and unzip the repository. Then, double-click the TreasureHunt.prj file inside MATLAB®.

Option 2: Open in MATLAB Online Log in to your MathWorks account to access your license. If you are associated with a university, use your university email to access a license.

  • The instructions inside the live scripts will guide you through the exercises and activities.
  • Get started with each live script by running it one section at a time.
  • To stop running the script or a section midway (for example, if a loop is running longer than intended), click the Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

Prerequisite Domain Knowledge

This module assumes an ability to identify and plot X,Y points on a grid. It is also intended for those who have an understanding of basic computer science concepts, such as syntax, variables, and arrays. If you would like more practice with these concepts, we recommend trying the set of exercises in Fundamentals of Programming.


GIF showing treasure hunt game being played

treasureHuntLearn.mlx Open in MATLAB Online This script walks the learner through the necessary steps to build the treasure hunting game, while teaching the relevant computer science concepts along the way.

treasureHuntLearnSoln.mlx Open in MATLAB Online This script contains the solutions for the treasureHuntLearn.mlx script.

treasureHuntPlay.mlx Open in MATLAB Online This script contains a barebones version of the playable treasure hunt game, with guidance for the learner to paste their code from treasureHuntLearn.mlx in order to make the game playable.

treasureHuntPlaySoln.mlx Open in MATLAB Online This script contains the solutions for the treasureHuntPlay.mlx script.

Learning Goals

  • Recognize and assign values to variables
  • Recognize and use built-in MATLAB functions and live controls
  • Interpret messages about syntax errors
  • Write comments in code and explain their importance
  • Use documentation to learn new functionality in a programming language
  • Assign values to the elements of a matrix and manipulate matrices
  • Identify and use conditional statements
  • Create and use custom functions




The license for this module is available in the License.txt file in this GitHub repository.


If you would like to provide feedback or have a question, contact the MathWorks online teaching team.

Copyright 2023 The MathWorks, Inc.

Cite As

Ryan Weinstein (2023). Treasure-Hunt (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2022b
Compatible with R2022b and later releases
Platform Compatibility
Windows macOS Linux
More Files in the  Distance Learning Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

See release notes for this release on GitHub:


To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.