Commits

Siko Chen  committed 131078f

bowling score

  • Participants

Comments (0)

Files changed (1)

File bowling_score.php

+<?php
+// author sikocb@gmail.com
+//
+//generate the test point
+//
+function getpoint(){
+	
+	$frist = rand(0,10);
+	$second = $frist == 10 ? 0 : rand(0,10- $frist);
+	
+	return array($frist,$second);	
+}
+
+
+//show point
+//
+function showpoint(){
+
+	$sum = 0 ;
+	$points = array_fill(0, 10, array(0,0));
+	$points = array_map("getpoint",$points);
+	
+	if($points[9][0] ==10 || $points[9][1] == 10){
+		array_push($points,array(rand(0,10),0));
+	}
+
+	foreach($points as $k => $v){
+		$i = $k +1 ;
+		echo "Frame  $i  $v[0] : $v[1] \n <br />";
+        
+        if ( $v[0] == 10 || $v[1] == 10 ) {
+			$sum += $v[0] + $v[1] + $points[$i][0] + $points[$i][1];
+		}elseif ( ( $v[0] + $v[1] ) == 10 ) {
+			$sum += $v[0] + $v[1] + $points[$i][0];
+		}else{
+			$sum += $v[0] + $v[1];
+		}
+	}
+	echo "Score $sum";
+
+}
+
+showpoint();
+