السلام عليكم ورحمة الله وبركاته
الترم هذا عندي ماده اسمها برمجة النظم وكان المطلوب منا عمل برنامج x o بالسي شل
فاحببت اشاركمم وارى رأيكم
ثانيا انا عندي استفسار عن الفرق بين السي شي والشل والباش وايها افضل ؟؟
والكود بالاسفل
الترم هذا عندي ماده اسمها برمجة النظم وكان المطلوب منا عمل برنامج x o بالسي شل
فاحببت اشاركمم وارى رأيكم
ثانيا انا عندي استفسار عن الفرق بين السي شي والشل والباش وايها افضل ؟؟
والكود بالاسفل
كود PHP:
#!/bin/csh
#
#project.csh
#
#
#Mohammed Al-malki 428000595
#Mohammed Aldawood 428000064
#Abdullah Al-amri 428000770
#Due Date : 20/6/2010
#
#Describtion:
# this program is X and O game by C shell language
#
#Input:
# names of players and place in the board from 1 to 9
#
#Output:
# how winner , the board , No winner , and messege for out of program or play again
#
echo
if( $1 == "" || $1 =~ [0-9]* || $1 =~ *-* ) then
echo -n "Player 1 please enter your name : "
set name1 = $<
while ( $name1 == "" || $name1 =~ [0-9]* || $name1 =~ *-* )
echo -n "Player 1 please enter your name again : "
set name1 = $<
end
set name1 = $name1
else
set name1 = $1
endif
echo
if($2 == "" || $2 =~ [0-9]* || $2 =~ *-* ) then
echo -n "Player 2 please enter your name : "
set name2 = $<
while ($name2 == "" || $name2 =~ *-* || $name2 =~ [0-9]* )
echo -n "Player 2 please enter your name again : "
set name2 = $<
end
set name2 = $name2
else
set name2 = $2
endif
echo
echo "hi $name1, you will have X"
echo "hi $name2, you will have O"
sleep 2
onintr controlC
set a = ( 1 2 3 4 5 6 7 8 9)
set d = 0
set enter = 0
set count = 0
set last_1 = 'O'
while(1)
if ( $count >= 9) then
clear
echo
echo
echo " No winner in this playing "
echo
echo
sleep 1
echo "to play again press yes or any thing to out "
set d = $<
if( $d =~ y* || $d == 'yes') then
set last_1 = 'O'
set count = 0
set a = ( 1 2 3 4 5 6 7 8 9)
else
goto endOfScript
endif
endif
clear
echo
echo
cat<<ENDOFMENUE
| |
$a[1] | $a[2] | $a[3]
| |
| |
____________________________________________
| |
$a[4] | $a[5] | $a[6]
| |
| |
_____________________________________________
| |
$a[7] | $a[8] | $a[9]
| |
| |
ENDOFMENUE
echo
echo
if($last_1 == 'X' ) then
echo "your move $name2 ?"
echo "enter the number from 1 - 9 that not entered to put O , to exit from game ctrl+C"
set enter = $<
switch($enter)
case '1':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '2':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '3':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
onintr controlC
set a = ( 1 2 3 4 5 6 7 8 9)
endif
breaksw
case '4':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '5':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '6':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '7':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '8':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
case '9':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'O'
set a[$enter] = 'O'
@ count++
else
echo
endif
breaksw
default:
echo
breaksw
endsw
endif
############################################### chick winner for player O #############################################
if( $a[1] == $a[2] && $a[2] == $a[3] && $a[3] == 'O' || $a[4] == $a[5] && $a[5] == $a[6] && $a[6] == 'O' || $a[7] == $a[8] && $a[8] == $a[9] && $a[9] == 'O' || $a[1] == $a[4] && $a[4] == $a[7] && $a[7] == 'O' || $a[2] == $a[5] && $a[5] == $a[8] && $a[8] == 'O' || $a[3] == $a[6] && $a[6] == $a[9] && $a[9] == 'O' || $a[1] == $a[5] && $a[5] == $a[9] && $a[9] == 'O' || $a[3] == $a[5] && $a[5] == $a[7] && $a[7] == 'O' ) then
clear
echo " We have a winner. Congratulations $name2 ."
sleep 2
echo
echo
echo "to play again press yes or any thing to out "
set d = $<
if( $d =~ 'y' || $d == 'yes') then
set last_1 = 'O'
set count = 0
set a = ( 1 2 3 4 5 6 7 8 9)
else
goto controlC
endif
endif
##################################################################################################################
####################################################
clear
echo
echo
cat<<ENDOFMENUE
| |
$a[1] | $a[2] | $a[3]
| |
| |
____________________________________________
| |
$a[4] | $a[5] | $a[6]
| |
| |
_____________________________________________
| |
$a[7] | $a[8] | $a[9]
| |
| |
ENDOFMENUE
echo
echo
##################################################
if($last_1 == 'O' ) then
echo "your move $name1 ?"
echo "enter the number from 1 - 9 that not entered to put X , to exit from game ctrl+C"
set enter = $<
switch( $enter )
case '1':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '2':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '3':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '4':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '5':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '6':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '7':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '8':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
case '9':
if($a[$enter] != 'X' && $a[$enter] != 'O') then
set last_1 = 'X'
set a[$enter] = 'X'
@ count++
else
echo
endif
breaksw
default:
echo
breaksw
endsw
endif
################################################# chick winner for X player ############################################
if( $a[1] == $a[2] && $a[2] == $a[3] && $a[3] == 'X' || $a[4] == $a[5] && $a[5] == $a[6] && $a[6] == 'X' || $a[7] == $a[8] && $a[8] == $a[9] && $a[9] == 'X' || $a[1] == $a[4] && $a[4] == $a[7] && $a[7] == 'X' || $a[2] == $a[5] && $a[5] == $a[8] && $a[8] == 'X' || $a[3] == $a[6] && $a[6] == $a[9] && $a[9] == 'X' || $a[1] == $a[5] && $a[5] == $a[9] && $a[9] == 'X' || $a[3] == $a[5] && $a[5] == $a[7] && $a[7] == 'X' ) then
clear
echo " We have a winner. Congratulations $name1 ."
sleep 2
echo
echo
echo "to play again press yes or any thing to out "
set d = $<
if( $d =~ y || $d == 'yes') then
set last_1 = 'O'
set count = 0
set a = ( 1 2 3 4 5 6 7 8 9)
else
goto controlC
endif
endif
##########################################################################################################################
end ## end of while loop
################ ctrl-c ########################
controlC:
clear
echo " "
echo " "
echo " "
echo " "
echo " "
echo " Thanks for playing "
echo " "
echo " "
echo " "
echo " "
sleep 3
clear