| Author |
Message |
kaeza

Joined: 30 Nov 2011 Posts: 49 Location: Montevideo, Uruguay
|
Posted: Fri 20 Jul 2012, 14:27 Post subject:
Tiny linux games made with scripting languages |
|
Hello.
I created this thread so people can show some interesting games made using scripting languages.
The basic rules are:
- The code must be in a scripting language, be it bash, perl, lua, python, or whatever you can think of.
- The code must fit in a single post. You are not allowed to split the game into multiple posts or add attachments.
- Also related to the above rule, the less lines the better.
- The code you post here must be written by you, and by making it available here you put it in the public domain.
That's about it I think.
Heres one to get you started.
| Code: |
#! /bin/sh
ntries=0;
targetnum=$(((RANDOM%10)+1));
while [ $ntries -lt 10 ]; do
echo -n "Type a number between 1 and 10 inclusive:";
read num;
test "$num" || exit;
num=$((num));
ntries=$((ntries+1));
if [ "$num" -eq $targetnum ]; then
echo "Congrats pal! You got it in $ntries attempts!";
exit;
elif [ "$((num))" -gt $targetnum ]; then
echo "Target number is lower.";
else
echo "Target number is higher.";
fi
done
echo "You didn't make it in 10 attempts...";
|
_________________ "Courage is not the absence of fear, but rather the judgement that something else is more important than fear." -- Ambrose Redmoon
My Profile.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sat 21 Jul 2012, 12:44 Post subject:
Re: Tiny linux games |
|
| kaeza wrote: |
| Code: |
#! /bin/sh
ntries=0;
targetnum=$(((RANDOM%10)+1));
... |
| $RANDOM is a bashism, so should be #! /bin/bash or something really hacky using /dev/random
space invaders would actually be possible in shell using color formatting and storing positions of objects in a bash array to store the positions/conditions of the "sprites" ... mazes, snake, tetris are the easier ones but defender and galaga are even scriptable
I have actually been contemplating writing a mini game engine in shell that simply modifies an svg image (I have have code for automatiacally refreshing an image when the file is modified as part of my simple icon tray - which, btw, I PD'd along with the most permissive license I could come up with for locations that don't recognize public domain ) Pretty much any 2d game you could think of could be rendered using a single svg thanks to "include", but I have not seen too many PD svgs around, so I have been collecting ISC/MIT/BSD/UIUC licensed ones that I come across.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
kaeza

Joined: 30 Nov 2011 Posts: 49 Location: Montevideo, Uruguay
|
Posted: Sat 21 Jul 2012, 12:53 Post subject:
|
|
okay, that would be cool.
But the idea of this post is to make something like Speedhack.
I'm working myself in some tiny platform game using ANSI escape sequences for graphics. I don't know if every (virtual) terminal out there supports these, but I'll post it when I fix some minor things.
_________________ "Courage is not the absence of fear, but rather the judgement that something else is more important than fear." -- Ambrose Redmoon
My Profile.
|
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 2462 Location: Ontario
|
Posted: Sat 21 Jul 2012, 16:31 Post subject:
|
|
A game I recommend is 'Columns'
J-K-L keys are used for movement
It's possible to run it in mini vMac emulation.
I put it in the archive package to download. Everything
needed is in the package. Follow instructions.
http://murga-linux.com/puppy/viewtopic.php?p=639450
_______________________________________
|
|
Back to top
|
|
 |
darkcity

Joined: 23 May 2010 Posts: 2215 Location: near here
|
Posted: Sat 21 Jul 2012, 22:45 Post subject:
|
|
can it run on Bash?
heres a pointless script-
| Code: | #! /bin/bash
#define board pieces
strpieceX=".XXXXXXXXXXXXXXXXXXXXXXXXXXXX."
strpiece[0]=".X.....X......" && strpiece[1]="............X."
strpiece[2]=".X..X........." && strpiece[3]="......XX......"
strpiece[4]=".X..........X." && strpiece[5]=".........X..X."
strpiece[6]=".X............" && strpiece[7]="......X.....X."
strpiece[8]="......X..X...." && strpiece[9]="....X..X......"
#set board
for (( i=0; i <= 9; i++ ))
do
stpiece[i]="X"${strpiece[$((RANDOM%10))]}${strpiece[$((RANDOM%10))]}"X"
done
#greeting
echo
echo Hello, I am the random Monkey Man!
echo
echo $strpieceX
for (( i=0; i <= 9; i++ ))
do
printf ${stpiece[$i]}
echo
done
echo $strpieceX
echo
#monkey business
echo -n "Can you guess the name of the map? ";
read str;
if [ $((RANDOM%2)) -eq 0 ]
then
echo "I can not believe you guessed '"$str"'."
if [ $((RANDOM%2)) -eq 0 ] ; then echo "very bad!"; fi
else
echo -n "Correct answer..."
if [ $((RANDOM%2)) -eq 0 ]
then
echo "but no gold for you, sorry."
else
echo "take 10 golden coins, well done, your welcome."
fi
fi
echo Now be on your way!!!
echo
|
_________________ Wiki Audacity 2.0.1
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 570
|
Posted: Thu 26 Jul 2012, 17:19 Post subject:
|
|
How about Mastermind?
I'm not a big fan of this game, but I can't come up with anything more interesting right now...
Here's my crude, textual version:
| Code: | #!/bin/bash
# Simple implementation of Mastermind by SFR'2012
# ===========================================
SET=A-F # Set of letters, max. A-Z
LENGHT=4 # Lenght of the code, max. 10
ATTEMPTS=12 # Number of tries
# ===========================================
C='!!!!!!!!!!'
W='??????????'
U='..........'
LEN=$(($LENGHT-1))
for i in `seq 0 $LEN`; do CODE[$i]=`cat /dev/urandom | tr -dc $SET | head -c 1`; done
clear
echo "The $LENGHT-character code out of $SET set has been generated."
echo "The code may contain repetitions."
echo "Try to guess it within $ATTEMPTS attempts!"
echo
echo "! - indicates the existence of a correct letter in the correct position."
echo "? - indicates the existence of a correct letter in the wrong position."
echo
echo "Lenght: $LENGHT Set: $SET Attempts: $ATTEMPTS"
echo
N=1
while [ $N -le $(($ATTEMPTS)) ]; do
while true; do
read -p "Attempt $N: " KEY
[ "$KEY" = "." ] && exit
TEST=`echo $KEY | tr [:lower:] [:upper:] | tr -dc $SET`
[ "${#TEST}" -eq $LENGHT ] && break
echo -e "\033[2A"
done
CODE_TEMP=( "${CODE[@]}" )
for i in `seq 0 $LEN`; do KEY_TEMP[$i]=`echo "${TEST:$i:1}"`; done
CORRECT_POS=0
for i in `seq 0 $LEN`; do
if [ "${CODE_TEMP[$i]}" = "${KEY_TEMP[$i]}" ]; then
CORRECT_POS=$(($CORRECT_POS+1))
CODE_TEMP[$i]=".1"; KEY_TEMP[$i]=".2"
fi
done
WRONG_POS=0
for i in `seq 0 $LEN`; do
for j in `seq 0 $LEN`; do
if [ "${CODE_TEMP[$i]}" = "${KEY_TEMP[$j]}" ]; then
WRONG_POS=$(($WRONG_POS+1))
CODE_TEMP[$i]=".1"; KEY_TEMP[$j]=".2"
fi
done
done
[ "${#N}" -eq 1 ] && N="0"$N
echo -ne "\n\033[2A"$N") "${TEST[@]}" : "
echo "$C" | head -c $CORRECT_POS; echo "$W" | head -c $WRONG_POS; echo "$U" | head -c $(($LENGHT-$CORRECT_POS-$WRONG_POS))
echo " "
[ "$CORRECT_POS" = "$LENGHT" ] && echo -e "\nCongratulations! You made it in $N attempt!" && exit
N=$((10#$N+1))
done
echo -ne "\nSorry, you didn't make it. The code was: "
echo "${CODE[@]:0}" | tr -d " "
exit |
Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1711 Location: Burghaslach, Germany
|
Posted: Fri 27 Jul 2012, 04:26 Post subject:
Subject description: mastermind |
|
| SFR wrote: | | How about Mastermind? |
OK, let´s play
| $HOME/my-applications/bin/mastermind wrote: | The 4-character code out of A-F set has been generated.
The code may contain repetitions.
Try to guess it within 12 attempts!
! - indicates the existence of a correct letter in the correct position.
? - indicates the existence of a correct letter in the wrong position.
Lenght: 4 Set: A-F Attempts: 12
01) AAAA : ....
02) BCDE : !?..
03) FFFF : !...
04) CDEF : ??..
05) DDDD : !!..
06) FDDE : !??.
07) DDFB : !!??
0 DFBD : !!??
09) DFCC : !!..
10) DFDB : !!!!
Congratulations! You made it in 10 attempt!
# |
|
|
Back to top
|
|
 |
Moose On The Loose

Joined: 24 Feb 2011 Posts: 278
|
Posted: Sat 28 Jul 2012, 19:58 Post subject:
Tiny linux games Subject description: Tic Tack Toe |
|
| kaeza wrote: | Hello.
I created this thread so people can show some interesting games made using scripting languages.
|
This isn't completely tiny but here it is complete with a GUI.
It plays tictactoe and does a fairly good job of it.
| Code: |
#/bin/bash
DF=/tmp/tic
BB="X23456789"
W=false
function tot() {
Y=$(echo "${BB:$2:1}${BB:$3:1}${BB:$4:1}" | sed "s/[1-9]//g;s/X/+1/g;s/O/+10/g")
case $(( 0 $Y )) in
0) eval $1=1
;;
1) eval $1=2
;;
10) eval $1=2
;;
2) eval $1=1000
W=true
;;
20) eval $1=10
;;
30) echo "You win!"
exit
;;
*) eval $1=0
;;
esac
}
function but() {
local Z
if [[ "$1" > "A" ]] ; then
Z=text
else
Z=button
fi
echo "<$Z><label>$1</label></$Z>"
}
function dia() {
local I
local J
echo "<vbox>"
if [[ "$1" != "" ]] ; then
echo "<text><label>$1</label></text>"
fi
echo "<hbox>"
for I in 0 1 2 ; do
echo '<vbox homogeneous="true">'
for J in $I $(( $I + 3)) $(( $I + 6 )) ; do
but ${BB:$J:1}
done
echo "</vbox>"
done
echo "</hbox>"
if [[ "$2" != "" ]] ; then
echo "<button><label>$2</label></button>"
fi
echo "</vbox>"
}
MX="your move"
while true ; do
if ( echo $BB | grep -v -r -q "[1-9]" ) ; then
dia "Its a draw" "OK" >$DF
else
dia "$MX" >$DF
fi
M=$(gtkdialog3 -f /tmp/tic)
if ! (echo "$M" | grep -q "[1-9]") ; then
exit
fi
M=${M/EXIT/M}
eval $M
BB=${BB/$M/O}
for X in "A 0 1 2" "B 3 4 5" "C 6 7 8" "D 0 3 6" "E 1 4 7" "F 2 5 8" "G 0 4 8" "H 2 4 6" ; do
tot $X
done
M=$( echo "$((2 + $A + $D + $G )) 1 ${BB:0:1}
$(( $A + $E )) 2 ${BB:1:1}
$((2 + $A + $F + $H )) 3 ${BB:2:1}
$(( $B + $D )) 4 ${BB:3:1}
$(( $B + $E +$G + $H )) 5 ${BB:4:1}
$(( $B + $F )) 6 ${BB:5:1}
$((2 + $C + $D + $H )) 7 ${BB:6:1}
$(( $C + $E )) 8 ${BB:7:1}
$((2 + $C + $F + $G )) 9 ${BB:8:1}
" | grep -r "[1-9]\$" | sort -n | tail -1 | cut -d\ -f2 )
MX="I moved $M"
BB=${BB/$M/X}
if $W ; then
dia "I win at $M" "OK" >$DF
gtkdialog3 -f /tmp/tic
exit
fi
done
|
|
|
Back to top
|
|
 |
darkcity

Joined: 23 May 2010 Posts: 2215 Location: near here
|
Posted: Mon 30 Jul 2012, 08:12 Post subject:
|
|
seems like line 22 isn't needed ; -)
_________________ Wiki Audacity 2.0.1
|
|
Back to top
|
|
 |
Moose On The Loose

Joined: 24 Feb 2011 Posts: 278
|
Posted: Mon 30 Jul 2012, 11:10 Post subject:
|
|
| darkcity wrote: | | seems like line 22 isn't needed ; -) |
I would be nice if you quoted a bit of what you are reacting to. I went and looked at my code and lines 21-23 do serve an important purpose. I assumed that the user would look at the code before running it. Those lines serve to give a false hope of winning.
|
|
Back to top
|
|
 |
darkcity

Joined: 23 May 2010 Posts: 2215 Location: near here
|
Posted: Mon 30 Jul 2012, 15:30 Post subject:
|
|
fair play ; -)
_________________ Wiki Audacity 2.0.1
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Wed 15 Aug 2012, 23:13 Post subject:
|
|
http://murga-linux.com/puppy/viewtopic.php?t=80352
I thought outside the box a bit and just created a poor man's scriptable game framework... would be cool to have some kind of a contest
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
kaeza

Joined: 30 Nov 2011 Posts: 49 Location: Montevideo, Uruguay
|
Posted: Thu 16 Aug 2012, 09:36 Post subject:
|
|
Sory for the delay guys, I exceeded my bandwidth
Really nice games.
Been a bit busy "working", so I didn't have time to finish anything.
A new game coming soon...
_________________ "Courage is not the absence of fear, but rather the judgement that something else is more important than fear." -- Ambrose Redmoon
My Profile.
|
|
Back to top
|
|
 |
|