Nimbin2git.christianimmanuel.de / Games / 2048_bash / 2048.sh

2048_bash git · main

git clone https://git.christianimmanuel.de/games/2048_bash.gitwget https://git.christianimmanuel.de/games/2048_bash/archive/2048_bash.tar.gz
2048.sh 936 B · 60 lines raw
#!/bin/bash
### 2048.sh

param=$1
sleepTime=$2
if [ -z "$sleepTime" ]; then sleepTime=0.0; fi
source functions.sh
source printMatrix.sh
source autorun.sh
rm log.log
clear -x



function at_exit() {
	printf "\e[?9l"          # Turn off mouse reading
        printf "\e[?12l\e[?25h"  # Turn on cursor
        stty "$_STTY"            # reinitialize terminal settings
	tput sgr0
	clear -x
}
trap at_exit ERR EXIT

autorun=false
if [ "$param" = "-a" ]; then
	autorun=true
	source autorun.sh
fi


startRun

########
##MAIN##
while true; do
	mainLoop=$((mainLoop+1))
	swipeState=("${newSwipeState[@]}")
	frameBottom=0


	log "main:$mainLoop: ${matrix[*]}"
	getRank
# auto or user
	if $autorun; then
		runAutoMx
	else
		waitForKey
	fi
# swipe to direction X
	swipeX
# set Random num matrix
	if ${swipeState[$swipeValue]}; then setRanN; fi
# write matrix
	logMatrix
	if $autorun; then sleep $sleepTime; fi
	printMatrix

# test 
	testSwipe
done