{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generating mini-games with random.choice()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ". . . . .. . . .. \n", " . . . . . . . . . . . \n", " . . . .. .. . . .\n", " . . . . . . . . \n", " . . . . . . . . . . \n", " . . . . . . . . . \n", " . . . . . . .. \n", " . . . .. . . . . .. . .. \n", " . . . . . . . .. . \n", ". . . . . . . . .. . \n", ". . . .. . . \n", " . . . . . . . .. . \n", " . . . . . \n", " . . . . . . . \n", " . . . . . . . .\n", ". . . .. . . . . . \n", " .. . . . . \n", " . . . . . . . . . . . \n", " . . . . . . . .. \n", " . . . . . \n", " . . . . . . . . . . . . \n", " . . . . . . . . . . . \n", " . . . . . . . . . . \n", " . . . . . . . . . \n", " . . . . . . . . . \n" ] } ], "source": [ "from random import choice\n", "\n", "characters = ['.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']\n", "width = 100\n", "height = 25\n", "\n", "for y in range(height):\n", " for x in range(width):\n", " print(choice(characters), end='')\n", " print('')" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " a o it m i i m f c \n", " c i ag n o amf f o i \n", " o i o f i a g af i g\n", " m i f a t g c f t i\n", " n o f a f tnf o f \n", " a i i i i i t in c caa \n", " t fa n f i t a i o\n", " o i ag ig g g a i i i n ag \n", " n m gt a i o f i o ni i i \n", " m i f i a a a o i m a g c \n", " f am a c o i f cna f mi\n", " t a i c f g f n i c o o g \n", " o f t a g ng i a i a n n o a t oi i it\n", " o t n o m f g a i a m ni \n", " f i i g m o i a n t a i a a m i a i a\n", "i a a ac i a t i tn t a \n", " o f tf i an i n o f i t t \n", " c g fg i o o ca i o o o m t \n", " f o i i i c i ta i ca c f \n", " c n aa g i m g m i c \n", " c i c i f i n m f i i \n", " a o i g m o ot a i a c f m i \n", " i a a i f f a c g i\n", " to in a t og im i o i f n c \n", "ao m g ii c n a to t \n" ] } ], "source": [ "from random import choice\n", "\n", "character_set = 'gamification '\n", "characters = [character for character in character_set]\n", "width = 100\n", "height = 25\n", "\n", "for y in range(height):\n", " for x in range(width):\n", " print(choice(characters), end='')\n", " print('')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# More games plz!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Try to make some more mini-games yourself.\n", "\n", "You can restrict yourself to using **ASCII characters only** (see https://en.wikipedia.org/wiki/ASCII) and stay in touch with early computer graphics ASCII art...\n", "\n", "Or you can extend your pallete with **Unicode characters**. This is a nice website that highlights specific character sets: http://xahlee.info/comp/unicode_index.html" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }