Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – Managing a fridge


We are going to create software to manage a fridge. We want to be able to add meals inside it, and to list what is in it. Ok, let's start!

  1. Create a folder that is going to hold your project's files.

  2. Create two folders inside it: a src folder and a bin folder.

  3. In your src folder, create a MyFridge folder. This way, we now have a MyFridge package.

  4. In the MyFridge package, create a Fridge.hx file with the following code inside it:

    package MyFridge;
    class Fridge
    {
       public static var meals = new List<Meals>();
    }
  5. This way, our fridge will hold a list of meals inside it. We can make this variable static because we will only have one fridge.

  6. Now, in the MyFridge package, create a file named Meal.hx and write the following code in it:

    package MyFridge;
    
    class Meal
    {
       public var name : String;
       
       public function new(f_name : String)
       {
          this.name = f_name;
       }
    }
  7. We now have a class Meal and its instances will have a name.

  8. We will now create a menu....