Tetris Game -- based on a shell script (new algorithm)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tetris Game -- based on a shell script (new algorithm)
# 22  
Old 01-09-2012
Here is a version of maxxy() that dosn't use the xargs or awk externals:

Code:
maxxy()
{
    local i a b
    set -- ${box[@]} 
    while [ $# -gt 0 ]
    do
       [ 0${a[$2]} -lt $1 ] && a[$2]=$1
       b[$2]="${a[$2]} $2"
       shift ; shift
    done
    for i in "${b[@]}"
    do
       echo $i
    done
}


Last edited by Chubler_XL; 01-09-2012 at 11:02 PM.. Reason: Make i a local var to
# 23  
Old 01-09-2012
Quote:
Originally Posted by Chubler_XL
Here is a version of maxxy() that dosn't use the xargs or awk externals:
Perfect Code!
a better optimization:
Code:
maxyx()
{
   local i a b
   set -- ${box[@]} 
   a[$2]=${1} 
   b[$2]="${1} ${2}" && shift 2
   while (( ${#} > 0 ))
   do
        (( a[$2] < ${1} )) && a[$2]=${1}
        b[$2]="${a[$2]} ${2}"
        shift 2
   done
   echo ${b[@]}
}

Thank you!

Last edited by complex.invoke; 01-10-2012 at 03:49 AM..
# 24  
Old 01-09-2012
Nice job. Looks good with bash 3.2.39 under a very out-dated (11.1) SUSE Linux and bash 4.1 under FreeBSD 8.2.

The only bug I've noticed is that a single block (1x1) always seems to go through the pile to the bottom. Maybe it's designed that way, but that seems odd if it is.
# 25  
Old 01-10-2012
Quote:
Originally Posted by agama
The only bug I've noticed is that a single block (1x1) always seems to go through the pile to the bottom. Maybe it's designed that way, but that seems odd if it is.
That isn't a bug! It's designed that way specially as the feature
Across area moving(ID=0)!

---------- Post updated 01-10-12 at 05:19 AM ---------- Previous update was 01-09-12 at 11:03 PM ----------

Updated the maxxy function to maxyx function!
# 26  
Old 01-10-2012
Quote:
Originally Posted by vbe
Neo,
I got it working on my powerbook (G4 1.67Ghz..) with bash and macOSX10.5.6 though a bit buggy.. but display quite some funny figures! Look to me it will be hard work to debug because of the figures produced...
Yah.. I think the terminal width may not be large enough on my 13" MBA.....
# 27  
Old 01-10-2012
I added runlevel support, now it's so easy to play with, just enjoy it, my friends!

Last edited by vbe; 01-10-2012 at 02:34 PM.. Reason: added word support,so to rm dupl message
# 28  
Old 01-21-2012
Tetris Game Version 5.0 released!
Added comments!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a text based game using shell script.

Hello guys I'm new to shell scripting and I need to make a game using shell script. I want to know if it is possible for me a total noob to shell scripting to make this game. The game concept is simple: First thing when you launch the script you get a menu in which you select if you want to... (3 Replies)
Discussion started by: Othmane
3 Replies

2. Shell Programming and Scripting

Proper distribution of cards in terminal based crazy8's game in bash script

When I run the following script at the bottom it say cards remaining=44...It should be=35. Can anyone tell me what I'm doing wrong. I've spent hours trying to get this to work and I can't go any further until this part works. thank you in advance Cogiz #!/bin/bash # Date="November, 2016" #... (2 Replies)
Discussion started by: cogiz
2 Replies

3. Shell Programming and Scripting

Understanding Tetris-game code. newbie

Hi All, Been trying to understand the code in tetris game (in the sticky threads) & i know i have a alot reading /practice to do. it's using advanced methods with arrays and arithmetic and would much appreciate if some one can guide me to good books that's not outdated that would help me take... (0 Replies)
Discussion started by: xcod3r
0 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Making a text based game

Hello, I am looking to make a text based game, that runs in the command window, or a window similar. I will only need to use 1 window. I read somewhere that there is libraries for this kind of thing? But I can't remember the name of them.. Can anyone point me in a direction? I will be... (2 Replies)
Discussion started by: murphy
2 Replies

5. Programming

Tetris Game in C++

Open Source Project: https://github.com/yongye/cpp Ported from the shell: Shell (0 Replies)
Discussion started by: complex.invoke
0 Replies

6. Shell Programming and Scripting

Shell Text Based Game, This Error Makes NO sense. Please help

Okay so I'm making a simple text based game that branches into different scenarios. By branching I mean branching off into whole different files with that part of the game in it. I got tired of working on scenario 1 so I'm working on scenario 2. As I get started and try to test it, I get an... (3 Replies)
Discussion started by: lemonoid
3 Replies

7. Shell Programming and Scripting

Making a Text based game. Need help.

Okay so Zork sparked my interest in this. I have been learning to program for the last year and a half. I've dabbled in everything from Java to Ruby to PHP & XHTML & SQL, and now I'm on bash. I really like bash scripting. Its easy and fun. I just started two days ago. Pretty much I've been writing... (1 Reply)
Discussion started by: lemonoid
1 Replies

8. UNIX for Dummies Questions & Answers

Is there picture based game under linux terminal?

Is there picture based game under linux terminal? Just like Supermario under DOS. (18 Replies)
Discussion started by: vistastar
18 Replies

9. UNIX for Dummies Questions & Answers

text based football game?

Is there a textbased football game (American) that I can download through ubuntu server edition? (1 Reply)
Discussion started by: dadoprso
1 Replies

10. Shell Programming and Scripting

Shell Script Poker Game

Original Code Taken from here: http://www.tldp.org/LDP/abs/html/bashver2.html#EX79 The code in the above link displays 4 unique 13 cards hands. I've modified it to deal a hand unique 2 card hand to 2 different players, then deal 5 unique community cards as in Texas Holdem (3 cards, then 1... (8 Replies)
Discussion started by: earnstaf
8 Replies
Login or Register to Ask a Question