Learning Loops And Arrays Through Games

in #steemiteducation7 years ago

I have decided to try something new in teaching computer science. I've been focussing on how to teach a language or how to use a language to teach, but this time I am going to demonstrate some language agnostics techniques to teach essential computer science concepts in a fun way.

Topics covered: Loops and Arrays

Basic Definitions: Loops and array are two of the most useful tools in a programmer toolbox for solving problems with code. Loops are a method of simplifying a repetitive task over a series of iterations. A loop consists of a starting state, a serious of instructions to be run multiple times and an end condition. A real-life example of a loop we perform on a weekly basis is grocery shopping. One heads to the store with a list of items. For each item on the list one performs a series of tasks:

  1. Read an item from the list
  2. Navigates to the item in the store
  3. Grabs item from the shelf
  4. Puts the item in the cart
  5. Crosses item off the list

This task is repeated until all items have been found. This is is a basic for loop. To store this list we can use an array. An array is an ordered list of items. Items on this list can be added to, modified, or removed. In our real-life example, the shopping list becomes an array of items. Building the list involves adding each item and when the item is found, on removes it from the list. Arrays can be multi-dimensional if needed. Two-dimensional arrays are fairly common to represent maps or populations over an area.

The Lesson: First, I have to give a good deal of credit to the TEALS Curriculum I teach from which I drew much inspiration from Project 2. The project has the students write a very simple dungeon adventure that involves three levels of five rooms each. Basically, we have the students writing a simple Roguelike. Roguelike games, in general, forgo fancy graphics for depth of gameplay and ease of development. Anybody can start writing a roguelike and make it as simple or complex as they desire. Below is an image to one of my favorite roguelikes of all time:
image.png

Don't worry, that is way more complicated than I'd expect for a class project. I just couldn't resist posting an image of one of the most complicated and complex roguelikes out there, Dwarf Fortress.

For loops feature prominently in this project because every game turn is another run through the loop. The program must interpret inputs like "east", "west", "south", "north", "up", or "down" while adjusting the game world to react to the player's actions. Other loops can search the room for interactions or resolve a combat. The game world itself can be stored in an array. The students can use a 2-d world for a flat dimension or go up to a 3-d array to model different floors for their world. By the time students get done navigating their world through the various loops and multidimensional arrays, they should have a good grasp on loops and arrays.
image.png
If a CRPG (computer role-playing game) doesn't get them excited, then the lesson can substitute board games instead. Games like chess or checkers can easily be represented by a two-dimensional array. Even games like Monopoly or even Candyland can be represented by even simpler single dimension arrays. Loops control player turns much like in a CRPG. Writing logic to resolve or validate piece movement in games like chess or checkers will definitely force them to understand how arrays work.

To wrap up, the heart of this lesson is to have them design a computer or board game and then implement the game with code. Be sure to rein in their ideas, because these type of design and implement projects could easily get very complicated very fast and you want to make sure your students can complete something in the time allotted to them.

If you have any questions or ideas, please comment below.

Image 1, 2

Sort:  

I love the idea of using games to teach! Very cool.

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Rantar from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.