إعـــــــلان

تقليص
لا يوجد إعلان حتى الآن.

سكربت x/o من برمجتي

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • private
    رد
    أكيد، بالطبع

    كود PHP:
    sudo apt-get install csh 

    اترك تعليق:


  • أنس أحمد
    رد
    ملحوطة: تحتاج إلى تثبيت CSH قبل بدء اللعب على Ubuntu.

    اترك تعليق:


  • private
    كتب موضوع [سكربت] سكربت x/o من برمجتي

    سكربت x/o من برمجتي

    ان شاء الله يعجبكم، اﻷول باستخدام switch والثاني بدون switch

    كود PHP:
    #!/bin/csh 


    set array = (1 2 3 4 5 6 7 8 9)   #list of choices
    onintr controlC 
    echo "" 
    echo "" 
                    
    echo              "                                    welcom to X/o game" 

    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     


    echo "Player 1 please enter your name:" 
    set P1n = $< 
    echo 
    "Hi $P1n you will have X" 
    echo "Player 2 please enter your name:" 
    set P2n = $< 
    echo 
    "Hi $P2n you will have O" 
    set counter 0   # To stop loop

    while(1)
     
    try: 
    echo 
    "your move $P1n ?" 
    set choice = $<
    clear

    if($choice > $#array) then
    echo "OUT OF RANGE, PLEAS TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try
    endif
    if(
    $array[$choice] == 'x' || $array[$choice] == 'o'then  # if index not null
    echo "THIS INDEX USED BEFORE, PLEAS TRY AGAIN"

    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try
    endif 

    switch (
    $choice

    case 
    1:
          
    set array[1] = 'x'        
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    breaksw 
    case 2
          
    set array[2] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 3
          
    set array[3] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 4
          
    set array[4] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 5
          
    set array[5] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 6
          
    set array[6] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 7
          
    set array[7] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 8
          
    set array[8] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 9
          
    set array[9] = 'x' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     
    breaksw
    default :
    echo 
    "ERROR IN YOUR CHOICE, TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try  
    breaksw
    endsw 
    #endif
                                 #game conditions#
    if($array[1] == 'x'  &&  $array[2] == 'x' &&  $array[3]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[4] == 'x'  &&  $array[5] == 'x' &&  $array[6]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[7] == 'x'  &&  $array[8] == 'x' &&  $array[9]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[1] == 'x'  &&  $array[4] == 'x' &&  $array[7]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[2] == 'x'  &&  $array[5] == 'x' &&  $array[8]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[3] == 'x'  &&  $array[6] == 'x' &&  $array[9]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[1] == 'x'  &&  $array[5] == 'x' &&  $array[9]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif 
    if(
    $array[3] == 'x'  &&  $array[5] == 'x' &&  $array[7]  == 'x'then 
    echo "$P1n won the game" 
    exit(-1
    endif
    counter += 1
    #echo "$counter" 
    try2:
    #echo "$counter"
    if($counter == $#array) then # stop if all index not null and no winner
    echo "NO WINNER"
    exit(-1)
    endif 
    echo 
    "your move $P2n ?" 
    set choice2 = $<
    clear
    if($choice2 > $#array) then
    echo "OUT OF RANGE,PLEAS TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try2
    endif
    if(
    $array[$choice2] == 'o' || $array[$choice2] == 'x'  then      # if index not null
    echo "THIS INDEX USED BEFORE,PLEAS TRY AGAIN"

    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try2
    endif

    switch (
    $choice2

    case 
    1
          
    set array[1] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    #endif 
    breaksw 

    case 2
          
    set array[2] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 3
          
    set array[3] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 4
          
    set array[4] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 5
          
    set array[5] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 6
          
    set array[6] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    breaksw 
    case 7
          
    set array[7] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     
    breaksw 
    case 8
          
    set array[8] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     
    breaksw 
    case 9
          
    set array[9] = 'o' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     
    breaksw
    default :
    echo 
    "ERROR IN YOUR CHOICE, TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try2  
    breaksw
    endsw 
    #endif

                               #game conditions# 
    if($array[1] == 'o'  &&  $array[2] == 'o' &&  $array[3]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[4] == 'o'  &&  $array[5] == 'o' &&  $array[6]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[7] == 'o'  &&  $array[8] == 'o' &&  $array[9]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[1] == 'o'  &&  $array[4] == 'o' &&  $array[7]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[2] == 'o'  &&  $array[5] == 'o' &&  $array[8]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[3] == 'o'  &&  $array[6] == 'o' &&  $array[9]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[1] == 'o'  &&  $array[5] == 'o' &&  $array[9]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    if(
    $array[3] == 'o'  &&  $array[5] == 'o' &&  $array[7]  == 'o'then 
    echo "$P2n won the game" 
    exit(-1
    endif 
    counter += 1

    end


    controlC
    :
    echo 
    'Thanks for playing' # print this massege if you press ctrl-c and Enter 
    كود PHP:
    #!/bin/csh


    set array = (1 2 3 4 5 6 7 8 9)   #list of choices
    onintr controlC 
    echo "" 
    echo "" 
                    
    echo              "                                    welcom to X/O game" 

    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
     


    echo "Player 1 please enter your name:" 
    set P1n = $< 
    while ( 
    $P1n =~ *-* ||  $P1n == "" 
    echo 
    "plase enter name without <   -   > and not empty"
    set P1n = $<
    end
    echo "Hi $P1n you will have X" 
    echo "Player 2 please enter your name:" 
    set P2n = $< 
    while ( 
    $P2n =~ *-* ||  $P2n == "" 
    echo 
    "plase enter name without <   -   > and not empty"
    set P2n = $<
    end
    echo "Hi $P2n you will have O" 
    set counter 0   # To stop loop

    while(1)
     
    try: 
    echo 
    "your move $P1n ?" 
    set choice = $<
    clear

    if($choice == $array[1] || $choice == $array[2] || $choice == $array[3] || $choice == $array[4] || $choice == $array[5] || $choice == $array[6] || $choice == $array[7] || $choice == $array[8] || $choice == $array[9]) then
    echo ""
    else
    echo 
    "OUT OF RANGE OR THIS INDEX USED BEFORE, PLEAS TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try
    endif
     

          
    set array[$choice] = 'X'        
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    #endif
                                 #game conditions#
    if($array[1] == 'X'  &&  $array[2] == 'X' &&  $array[3]  == 'X' || $array[4] == 'X'  &&  $array[5] == 'X' &&  $array[6]  == 'X' || $array[7] == 'X'  &&  $array[8] == 'X' &&  $array[9]  == 'X' || $array[1] == 'X'  &&  $array[4] == 'X' &&  $array[7]  == 'X' || $array[2] == 'X'  &&  $array[5] == 'X' &&  $array[8]  == 'X' || $array[3] == 'X'  &&  $array[6] == 'X' &&  $array[9]  == 'X' || $array[1] == 'X'  &&  $array[5] == 'X' &&  $array[9]  == 'X' || $array[3] == 'X'  &&  $array[5] == 'X' &&  $array[7]  == 'X' then 
    echo "We have a winner. Congratulations $P1n." 
    exit(-1
    endif
    counter += 1
     
    try2
    :

    if(
    $counter == $#array) then # stop if all index not null and no winner
    echo "NO WINNER"
    exit(-1)
    endif 
    echo 
    "your move $P2n ?" 
    set choice2 = $<
    clear
    if($choice2 == $array[1] || $choice2 == $array[2] || $choice2 == $array[3] || $choice2 == $array[4] || $choice2 == $array[5] || $choice2 == $array[6] || $choice2 == $array[7] || $choice2 == $array[8] || $choice2 == $array[9]) then
    echo ""
    else
    echo 
    "OUT OF RANGE OR THIS INDEX USED BEFORE, PLEAS TRY AGAIN"
    cat << display

                                        look the table below                
                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display
    goto try2
    endif


          
    set array[$choice2] = 'O' 
    cat << display


                                            ____________ 
                                           
    $array[1]  | $array[2] | $array[3] |  
                                           |
    ____|___|___
                                           | 
    $array[4]  | $array[5] | $array[6] |  
                                           |
    ____|___|___
                                           | 
    $array[7]  | $array[8] | $array[9] |  
                                           |
    ____|___|___
    display

    #endif

                               #game conditions# 
    if($array[1] == 'O'  &&  $array[2] == 'O' &&  $array[3]  == 'O' || $array[4] == 'O'  &&  $array[5] == 'O' &&  $array[6]  == 'O' || $array[7] == 'O'  &&  $array[8] == 'O' &&  $array[9]  == 'O' || $array[1] == 'O'  &&  $array[4] == 'O' &&  $array[7]  == 'O' || $array[2] == 'O'  &&  $array[5] == 'O' &&  $array[8]  == 'O' || $array[3] == 'O'  &&  $array[6] == 'O' &&  $array[9]  == 'O' || $array[1] == 'O'  &&  $array[5] == 'O' &&  $array[9]  == 'O' || $array[3] == 'O'  &&  $array[5] == 'O' &&  $array[7]  == 'O'then 
    echo " We have a winner. Congratulations $P2n." 
    exit(-1
    endif 
    counter += 1

    end


    controlC
    :
    echo 
    'Thanks for playing' # print this massege if you press ctrl-c 
يعمل...
X