/ Published in: PHP
Cows and Bulls logic game
Expand |
Embed | Plain Text
<?php class itergame { private $hidenum; public $turn; function __construct($number = "") { $this->turn = 0; if($number != "") { $this->hidenum = $number; } else { $this->Generate(); } } public function Generate() { $temp = ""; for($i=0; $i<4; $i++) { do { } $temp .= $k; $this->hidenum = $temp; } } public function Eval_n($num) { $r = 0; $b = 0; $nh = str_split($this->hidenum); if( NumValid($num) ) { for($i=0; $i < 4; $i++) { if( IsThere($num, $nh[$i])) $r++; if( InPos($num, $nh[$i], $i) ) $b++; $r -= $b; } $result = $r." ".$b; $this->turn++; } else { $result = ""; } return $result; } private function NumValid($num) { $vof = 1; $arr = str_split($num); for($i=0; $i < 4; $i++) { if($arr[$i] < 1 || $arr[$i] > 9) { $vof = 0; echo "Número Ilegal, cifra fuera de rango\n"; } } for($i=0; $i < 4; $i++) { $vof = 0; echo "Número Ilegal, tiene cifras repetidas\n"; } } return $vof; } private function InPos($cad, $n, $ind) { $arr = str_split($cad); $vof = ($arr[$ind] == $n); return $vof; } private function IsThere($cad, $n) { return $vof; } } ?>
You need to login to post a comment.
