hello_dart 0.2.0

  • Readme
  • Changelog
  • Installing
  • 49

Hello Dart #

Hello Dart is a visual and playful introduction to programming with Dart. It's your visual hello world for Dart.

Star this Repo Pub Package

GitHub | Pub | Course Materials

Hello Dart Screenshot

Course Materials #

Hello Dart contains free materials for a complete introductory course in programming. It includes theory, instructions, exercises, and solutions.

How it Works #

Hello Dart makes it easy to get startet with programming. It keeps the motivation high by providing an attractive visual feedback to the programmer.

Player and MyPlayer #

The class Player provides all functionality for controlling the character. The player provides various action methods (like move() and putStar()) and some sensory methods (like canMove() and treeLeft()).

The programming is done in the MyPlayer class which, through inheritance, can access all the methods of Player. Thus, the complexity of the player's methods are hidden from the programming novice at first.

MyPlayer has one method that must be implemented called start(). The start()-method is where the user writes his program. It is called automatically when the program is started.

MyPlayer should also have a main()-function that calls createWorld() to initialize the program.

Here is an example of a typical MyPlayer class:

import 'package:hello_dart/hello_dart.dart';

/// Your player.
class MyPlayer extends Player {

  /// Your program.
  start() {

main() {
  createWorld('scenario.txt', new MyPlayer());

World #

The class World is the central class that creates the visual environment and manages all actors.

Once the world is created and initialized with a call to createWorld(), the user's program in the start() method is executed. If we would just run the actions at full speed, the user would not see much of his program's execution. Therefore, we slow down the execution of each action step with the action queue.

Action Queue #

Dart and JavaScript are single-threaded programming languages. This means we cannot put a method to sleep in the middle of its execution as this would freeze the entire application including all animations.

When the World executes the start() method all actions (like move(), turnLeft(), etc.) are collected in an action queue. When all actions are queued they are played back in any desired speed.

This mechanism enables us to put a delay between each action which would otherwise not be possible.

We've set a limit to how many action methods may be called during the execution of the start()-method. The limit is 10'000 calls (see World.maxActionCalls) which should be more than enough for such simple programs. This also means that we will detect and report possibly never-ending cycles to the user at the end of the execution.

Scenarios #

Each Hello Dart scenario comes with a .txt file that provides information about the positions of the actors in the world (see example folder).

A Scenario contains a scenario title and information about the positions of the actors in the world.

The actors are described with the following signs:

  • Player: @
  • Tree: %
  • Star: .
  • Box: $
  • Box on star: *
  • Player on star: +

The background:

  • Empty: a space
  • Border or holes: #

Note: The border must form a polygon with the actors inside.

Here is how a scenario.txt file looks like:

1.03 - Around Tree
#         #
#@ % %  %.#

You may create your own scenarios, of course.

Options #

There are some options for changing the appearance and behavior of Hello Dart. Most options can be found in the hello_dart.dart file.

  • character: Defines the player image. Possible values are boy, catgirl, stargirl, pinkgirl.
  • field: The background field image. Possible values are grass, stone, wood, dirt.
  • backgroundColorTop: The top color of the background gradient. To take screenshots I usually set this color to white (#fff).
  • backgroundColorBottom: The bottom color of the background gradient.
  • messages: The error messages are in English but you may provide translations of those messages. An example can be found in the MessagesDe class.
  • Speed: The createWorld()-function provides an optional third argumtent to set the initial speed (in seconds). You may define the speed in a floating point number.

Here is an example of how to apply various options in the main()-function:

main() {
  // Change appearance.
  character = 'catgirl';
  field = 'stone';
  backgroundColorTop = '#fff';

  // Set to German error messages.
  messages = new MessagesDe();

  // Create the world with an initial speed of 0.3 seconds.
  createWorld('scenario.txt', new MyPlayer(), 0.3);

Attribution #

  • Planet Cute art by Daniel Cook (Lostgarden.com)
  • Oleg Yadrov has extended the "Planet Cute" theme with additional sprite perspectives. He was so kind to provide his graphics.
  • The sprites have been combined and optimized with TexturePacker.

Many thanks to Daniel and Oleg!

License #

The MIT License (MIT)

Changelog #

Version 0.2.0 (2018-11-07) #

  • Update to Dart 2

Version 0.1.1 (2015-03-20) #

  • Rename scenario1.04 from "around-tree-with-method" to "around-tree-with-function"
  • Add badges to readme.

Version 0.1.0 (2015-03-04) #

  • Contains all scenarios of the five parts.

Version 0.0.1 (2015-01-22) #

  • Initial Version.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  hello_dart: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:hello_dart/hello_dart.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4

Health suggestions

Fix lib/src/world/scenario.dart. (-16.09 points)

Analysis of lib/src/world/scenario.dart reported 35 hints, including:

line 51 col 23: Use = to separate a named parameter from its default value.

line 51 col 51: Use = to separate a named parameter from its default value.

line 54 col 13: Unnecessary new keyword.

line 97 col 30: Unnecessary new keyword.

line 100 col 30: Unnecessary new keyword.

Fix lib/src/actors/player.dart. (-14.82 points)

Analysis of lib/src/actors/player.dart reported 32 hints, including:

line 38 col 40: Unnecessary new keyword.

line 39 col 43: Unnecessary new keyword.

line 45 col 41: Unnecessary new keyword.

line 46 col 44: Unnecessary new keyword.

line 53 col 38: Unnecessary new keyword.

Fix lib/src/world/world.dart. (-10.44 points)

Analysis of lib/src/world/world.dart reported 22 hints, including:

line 80 col 44: Unnecessary new keyword.

line 130 col 20: Unnecessary new keyword.

line 155 col 26: This function has a return type of 'Animatable', but doesn't end with a return statement.

line 161 col 26: This function has a return type of 'Animatable', but doesn't end with a return statement.

line 180 col 13: Unnecessary new keyword.

Fix lib/src/actors/actor.dart. (-4.89 points)

Analysis of lib/src/actors/actor.dart reported 10 hints, including:

line 8 col 24: Avoid const keyword.

line 9 col 23: Avoid const keyword.

line 10 col 23: Avoid const keyword.

line 11 col 21: Avoid const keyword.

line 73 col 17: Unnecessary new keyword.

Fix lib/hello_dart.dart. (-1 points)

Analysis of lib/hello_dart.dart reported 2 hints:

line 54 col 21: Unnecessary new keyword.

line 63 col 17: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-22.19 points)

The package was last published 63 weeks ago.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and hello_dart.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
collection ^1.14.11 1.14.12
stagexl ^1.4.0+2 1.4.2
string_scanner ^1.0.4 1.0.5
Transitive dependencies
charcode 1.1.2
convert 2.1.1
meta 1.1.8
path 1.6.4
petitparser 3.0.0
source_span 1.6.0
term_glyph 1.1.0
typed_data 1.1.6
xml 3.7.0
Dev dependencies
build_runner ^1.1.1
build_web_compilers ^0.4.4+2