Thread komischer fehler aber wo?
(7 answers)
Opened by conray at 2010-04-22 21:31
der code ist auch schön aber ich versteh den nicht so ganz :D ( wie erwähnt newbie :D )
was für eine lib ist denn 5.010? da ich wie gesagt das ganze an die EierlegendeWollMilchSau.pl hängen wollte widerstrebts mir jetzt einfach deinen Code daranzu nageln :D (verständlich) hab jetzt die arrayabfrage geändert nun geht alles (fänomenal :D ) Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 #/usr/bin/perl use strict; print "What's your name Player1?: "; my $player1 = <STDIN>; chomp $player1; print "\nWhat's your name Player2?: "; my $player2 = <STDIN>; chomp $player2; if ($player1 eq $player2) { $player2 = $player2."2"; } my @field = ("_", "_", "_", "_", "_", "_", "_", "_", "_", "_"); my @valids = (1, 2, 3, 4, 5, 6, 7, 8, 9); my $name = $player1; my $roundcount = 1; my $choose; my $stone = 'x'; my $win = 0; my $othername = $player2; my $tmpname; my $stone2 = 'o'; my $tmpstone; my $valid; system("cls"); while ($roundcount <= 9 ) { print "|$field[7]|$field[8]|$field[9]| |7|8|9|\n"; print "|$field[4]|$field[5]|$field[6]| |4|5|6|\n"; print "|$field[1]|$field[2]|$field[3]| |1|2|3|\n"; print "\n$name your turn\n"; print "In which field do you want to set? "; $choose = <STDIN>; chomp $choose; if(grep $_ eq $choose, @valids) { $valid = 1; } else { $valid = 0; } if ($field[$choose] ne '_') { if ($field[$choose] eq $stone) { print "you had set here before\n"; } else { print "$othername had set here before\n"; } $valid = 0; } else { $field[$choose] = $stone; } if ($field[1] eq $stone and $field[2] eq $stone and $field[3] eq $stone) { $win = 1; } elsif ($field[4] eq $stone and $field[5] eq $stone and $field[6] eq $stone) { $win = 1; } elsif ($field[7] eq $stone and $field[8] eq $stone and $field[9] eq $stone) { $win = 1; } elsif ($field[1] eq $stone and $field[4] eq $stone and $field[7] eq $stone) { $win = 1; } elsif ($field[2] eq $stone and $field[5] eq $stone and $field[8] eq $stone) { $win = 1; } elsif ($field[3] eq $stone and $field[6] eq $stone and $field[9] eq $stone) { $win = 1; } elsif ($field[1] eq $stone and $field[5] eq $stone and $field[9] eq $stone) { $win = 1; } elsif ($field[3] eq $stone and $field[5] eq $stone and $field[7] eq $stone) { $win = 1; } if ($win eq 1) { last; } $roundcount++; print "$win\n$stone\n$name\n$roundcount\n"; if ( $valid eq 1) { $tmpname = $name; $name = $othername; $othername = $tmpname; $tmpstone = $stone; $stone = $stone2; $stone2 = $tmpstone; system("cls"); } else { $roundcount--; } } print "|$field[7]|$field[8]|$field[9]| |7|8|9|\n"; print "|$field[4]|$field[5]|$field[6]| |4|5|6|\n"; print "|$field[1]|$field[2]|$field[3]| |1|2|3|\n"; if ($win eq 1) { print "Congratulations $name you win"; } else { print "--->DRAW<---"; } __END__ |