Devnology codefest: Space Invaders quine


You saved the world - Invaders defeated
You saved the world

As a participant in Devnology Code Fest Space Invaders I knew immediately what the solution should be.

Some time ago I visited the Hot or Not Software Craftsmanship session by @KevlinHenney. In that session Kevlin introduced me to the principle of a quine and showed some examples. One of the examples was the Qlobe – a quine that shows a globe in the source code that rotates 45 degrees when executed.

So my contribution should be a space invaders quine. Furthermore my ruby skills need some practice so it will be a ruby space invaders quine. This is also a good excuse to finally finish reading Programming Ruby: The Pragmatic Programmers’ Guide. Below you a few possible game states are shown, the full solution can be found at GitHub.

"
#####################################################r
#01     **********                                   #
#02     **********                                   #
#03     **********                                   #
#04     **********                                   #
#05                                                  #
#06                                                  #
#07                                                  #
#08                   i                              #
#09                   i                              #
#XX                   %                              #
###0        1         2         3         4         5#
###12345678901234567890123456789012345678901234567890#
######################################################
"
"
#####################################################r
#01                 *********                        #
#02                 *********                        #
#03                 *********                        #
#04                 **    **                         #
#05                   i                              #
#06                   i                              #
#07                   i                              #
#08                        i                         #
#09                        i                         #
#XX                        %                         #
###0        1         2         3         4         5#
###12345678901234567890123456789012345678901234567890#
######################################################
"
"
#####################################################r
#01   **********                                     #
#02   **********                                     #
#03   **********                                     #
#04   **********                                     #
#05                                                  #
#06                                                  #
#07                                                  #
#08                                                  #
#09                                                  #
#XX                       %                          #
###0        1         2         3         4         5#
###12345678901234567890123456789012345678901234567890#
######################################################
"

invaders =  SpaceInvaders.new(field)
invaders.next_move
" ____  ____ ___ ___   ___       ___  __ __   ___ ____
 /    |/    |   |   | /  _]     /   \|  |  | /  _]    \
|   __|  o  | _   _ |/  [_     |     |  |  |/  [_|  D  )
|  |  |     |  \_/  |    _]    |  O  |  |  |    _]    /
|  |_ |  _  |   |   |   [_     |     |  :  |   [_|    \
|     |  |  |   |   |     |    |     |\   /|     |  .  \
|___,_|__|__|___|___|_____|     \___/  \_/ |_____|__|\_|


game has been reset for next try
"

One response to “Devnology codefest: Space Invaders quine”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.