Sponsored Content
Full Discussion: Rock Paper Scissors
Top Forums UNIX for Dummies Questions & Answers Rock Paper Scissors Post 302303495 by Gunther on Thursday 2nd of April 2009 06:37:58 PM
Old 04-02-2009
PHP

Hi,

here's my version of RPS. I tried to get basic functionality for keeping track of the score. Of course, there's still much to improve, but that's your job Smilie

Code:
#!/bin/bash

# Load score from files player1.score and player2.score, if they exist.
# Otherwise leave them 0.

p1_number_of_victories=0
p2_number_of_victories=0

if [ -e player1.score -a -e player2.score ]; then
        p1_number_of_victories=`cat player1.score`
        p2_number_of_victories=`cat player2.score`
fi

function p1_wins() {
        p1_number_of_victories=`expr $p1_number_of_victories + 1`
}

function p2_wins() {
        p2_number_of_victories=`expr $p2_number_of_victories + 1`
}

abort_game=n

until [ $abort_game = y ]; do
        PS3='Choose your action, player 1: '
        select action1 in "Rock" "Paper" "Scissors"; do break; done
        PS3='Choose your action, player 2: '
        select action2 in "Rock" "Paper" "Scissors"; do break; done

        case $action1 in
        "Rock")
                case $action2 in
                        "Rock") echo "Draw";;
                        "Paper") echo "Player 2 wins"; p2_wins;;
                        "Scissors") echo "Player 1 wins"; p1_wins;;
                esac
                ;;
        "Paper")
                case $action2 in
                        "Rock") echo "Player 1 wins"; p1_wins;;
                        "Paper") echo "Draw";;
                        "Scissors") echo "Player 2 wins"; p2_wins;;
                esac
                ;;
        "Scissors")
                case $action2 in
                        "Rock") echo "Player 2 wins"; p2_wins;;
                        "Paper") echo "Player 1 wins"; p1_wins;;
                        "Scissors") echo "Draw";;
                esac
                ;;
        esac

echo "Do you want to quit the game? [y/N]"
read abort_game
if [ -z "$abort_game" ]; then abort_game=n; fi # -z: input is empty -> ENTER was pressed

done
# end of loop

# Write new score to .score files
echo $p1_number_of_victories > player1.score
echo $p2_number_of_victories > player2.score

# exit gently
exit 0

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Research paper

I am doing a "research" paper for school and i'm having a hard time finding accurate information. I am supposed to choose three differant versions of unix, give a brief explination of each, tell why there each differant from each other. I have found a ton of web sites but the information is so vast... (1 Reply)
Discussion started by: pantsusan
1 Replies

2. OS X (Apple)

Mac OS X: Based on UNIX - Solid As a Rock

See this threads: Page Not Found - Apple Open Source - Apple (0 Replies)
Discussion started by: Neo
0 Replies

3. UNIX for Dummies Questions & Answers

Rock Cluster

Hello, I had install the rock cluster 4.3 version on my pcs..but i can't access into the desktop...may i know what is the problem? (1 Reply)
Discussion started by: joannetan9984
1 Replies

4. UNIX for Dummies Questions & Answers

MPI in Rock cluster

hi, may i know how to run mpi after i had install the rock cluster? is there any guidelines or examples? (0 Replies)
Discussion started by: joannetan9984
0 Replies

5. High Performance Computing

problem in the of installation rock cluster

Hai, I am trying to install rock4.3 in my Intel core2 quad process, but when i insert kernel cd which is the first step in the installation procedure, it asks for driver disk not found.. insert CD/DVD ROM even after i inserted my CD in my driver.. could anyone help me in solving this problem...... (1 Reply)
Discussion started by: sasirekha
1 Replies

6. UNIX and Linux Applications

Problems of sharing of disk space in Rock Clusters

Hi Server configuration is Processor : xeon 64 bit Os: centos 5 We are in the process of setting up the Rock Cluster with 5 node.Currently the node are communication with each other however the disk space is not being shared in the cluster We would like to know how to used one disk space... (1 Reply)
Discussion started by: airquality
1 Replies

7. Red Hat

i want to enjoy and rock my career as linux admin

hello i want to build my career as linux admin.I have completed my Engineering and had one month training on LINUX ADMIN course.I am doing well now in basics.Kindly provide suggetions or advice or books etc etc so that it will enhance my knowledge in linux Redhat. (1 Reply)
Discussion started by: dillipkmrpadhy
1 Replies
TENMADO(6)							  tenmado manual							TENMADO(6)

NAME
tenmado - hard-core shoot 'em up game in blue-or-red world SYNOPSIS
tenmado [ --dump stage ] [ --full-screen ] [ --help ] [ --slow ] [ --stage stage ] [ --undump stage ] [ --undump-default ] [ --version ] DESCRIPTION
tenmado is a vertically scrolling, late 1990s style (that is, a massive number of enemy shots against a smaller-than-it-looks spaceship) shoot 'em up game. A very accurate collision detection makes it a game of dexterity. If something looks like a triangle, it is a trian- gle, not a rectangle of similar size. However, surviving is only 20% of the game. The main feature of tenmado is the "color chain bonus". You can get a very big score (about 100 times bigger than a normal enemy-destruction point) by destroying enemies of the same color successively. It is easy or difficult depending on how greedy you are. In the game, use cursor keys to move, press space key to shoot (auto-repeat). A joystick is also available for move and shoot. Note that you must plug the joystick before you invoke tenmado. For more information, see the tutorial demo by choosing it from the menu in the title. Also check the README file which can be found at /usr/share/doc/tenmado/README . OPTIONS
--dump stage Write high score data to standard output and exit. Usually you save the output in a file and later use that file as the input of --undump. stage must be between 0 and 5. stage 0 means total score. stage 1 -- 5 means each stage score. --full-screen Run the game in the full screen mode. --help Print a help message and exit. --slow Run the game at the half speed. Technically, the length of waiting between each frame is doubled. This slows down everything in the game, including your ship. The idea is to study the enemy formations for a later (normal speed) play. The animation may be rough because this option gives you only about 16 fps. You can't enter the high score lists with this option. --stage stage Start the game at the specified stage. stage must be between 1 and 5. Note that you can play only one stage (the specified one) and you can't enter the high score lists. --undump stage Read high score data from standard input, save them and exit. The input is usually the output of --dump. stage must be between 0 and 5. stage 0 means total score. stage 1 -- 5 means each stage score. Only the superuser may use this option. --undump-default If at least one high score list is empty, read the default high score data, save them and exit. If not, do nothing. The main pur- pose of this option is to create high score database files at installation time so that you can set their permission. --version Print version information, license information and the disclaimer, then exit. BUGS
Please report any bugs you find to Oohara Yuuma <oohara@libra.interq.or.jp>. AUTHOR
Oohara Yuuma <oohara@libra.interq.or.jp> Project Geeste Thu, 16 Jan 2003 TENMADO(6)
All times are GMT -4. The time now is 01:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy