Last active
February 20, 2020 16:34
-
-
Save digitaljoni/afd3bb82ccab66df064c9b3c6633ca23 to your computer and use it in GitHub Desktop.
Saiyan Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Saiyan { | |
| Saiyan({this.name, this.power}); | |
| final String name; | |
| final int power; | |
| // Methods | |
| void punch() { | |
| print ('$name punched'); | |
| } | |
| void kick({int legs: 1}) { | |
| print('$name kicked using $legs legs'); | |
| } | |
| void specialMove() { | |
| // do special move | |
| } | |
| @override | |
| String toString() { | |
| return 'Saiyan $name Power Level : $power'; | |
| } | |
| } | |
| void main() { | |
| final Saiyan goku = Saiyan(name: 'Goku', power: 8000); | |
| print(goku); | |
| goku.punch(); | |
| final Saiyan vegeta = Saiyan(name: 'Vegeta', power: 6000); | |
| print(vegeta); | |
| vegeta.kick(); | |
| fight(goku, vegeta); | |
| } | |
| void fight(Saiyan saiyan1, Saiyan saiyan2) { | |
| if (saiyan1.power > saiyan2.power) { | |
| print('${saiyan1.name} wins'); | |
| } else { | |
| print('${saiyan2.name} wins'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment