【ロボット暴走】STEP: 3 格闘ゲーム (paizaランク B 相当) 解答例 – PHP編【クラス・構造体メニュー】
【クラス・構造体メニュー】 > 【ロボット暴走】STEP: 3 格闘ゲーム (paizaランク B 相当)
※リンク先へ移動する為には「paiza」へのログインが必要です。
クラスを使って解こうとしたら今の自分じゃ無理だったので行き当たりばったりの記述で無理やり解いた(;^ω^)
解答例
|
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 |
<?php $input = explode(" ",trim(fgets(STDIN))); $n = $input[0]; $k = $input[1]; $player = array(); for($i = 1;$i <= $n;$i++){ $test = explode(" ",trim(fgets(STDIN))); $player[$i]["hp"] = $test[0]; $player[$i]["フレーム"][1] = $test[1]; $player[$i]["フレーム"][2] = $test[3]; $player[$i]["フレーム"][3] = $test[5]; $player[$i]["攻撃力"][1] = $test[2]; $player[$i]["攻撃力"][2] = $test[4]; $player[$i]["攻撃力"][3] = $test[6]; if($test[1] == 0 AND $test[2] == 0){ $player[$i]["種別"][1] = "bildup"; } else { $player[$i]["種別"][1] = "attack"; } if($test[3] == 0 AND $test[4] == 0){ $player[$i]["種別"][2] = "bildup"; } else { $player[$i]["種別"][2] = "attack"; } if($test[5] == 0 AND $test[6] == 0){ $player[$i]["種別"][3] = "bildup"; } else { $player[$i]["種別"][3] = "attack"; } } //print_r($player); for($i = 0;$i < $k;$i++){ $test = explode(" ",trim(fgets(STDIN))); $p1 = $test[0]; $p1sf = $player[$p1]["フレーム"][$test[1]]; $p1sa = $player[$p1]["攻撃力"][$test[1]]; $p1ss = $player[$p1]["種別"][$test[1]]; $p2 = $test[2]; $p2sf = $player[$p2]["フレーム"][$test[3]]; $p2sa = $player[$p2]["攻撃力"][$test[3]]; $p2ss = $player[$p2]["種別"][$test[3]]; if(isset($player[$p1]) AND isset($player[$p2])){ if($p1ss == "attack" AND $p2ss == "attack"){ if($p1sf < $p2sf){ $player[$p2]["hp"] -= $p1sa; } elseif($p1sf > $p2sf){ $player[$p1]["hp"] -= $p2sa; } elseif($p1sf == $p2sf){ } } else { if($p1ss == "attack" AND $p2ss == "bildup"){ for($j = 1;$j <= 3;$j++){ if($player[$p2]["種別"][$j] == "attack"){ $player[$p2]["フレーム"][$j] -= 3; if($player[$p2]["フレーム"][$j] <= 0){ $player[$p2]["フレーム"][$j] = 1; } $player[$p2]["攻撃力"][$j] += 5; } } $player[$p2]["hp"] -= $p1sa; } elseif ($p1ss == "bildup" AND $p2ss == "attack"){ for($x = 1;$x <= 3;$x++){ if($player[$p1]["種別"][$x] == "attack"){ $player[$p1]["フレーム"][$x] -= 3; if($player[$p1]["フレーム"][$x] <= 0){ $player[$p1]["フレーム"][$x] = 1; } $player[$p1]["攻撃力"][$x] += 5; } } $player[$p1]["hp"] -= $p2sa; } elseif ($p1ss == "bildup" AND $p2ss == "bildup"){ for($y = 1;$y <= 3;$y++){ if($player[$p2]["種別"][$y] == "attack"){ $player[$p2]["フレーム"][$y] -= 3; if($player[$p2]["フレーム"][$y] <= 0){ $player[$p2]["フレーム"][$y] = 1; } $player[$p2]["攻撃力"][$y] += 5; } } for($z = 1;$z <= 3;$z++){ if($player[$p1]["種別"][$z] == "attack"){ $player[$p1]["フレーム"][$z] -= 3; if($player[$p1]["フレーム"][$z] <= 0){ $player[$p1]["フレーム"][$z] = 1; } $player[$p1]["攻撃力"][$z] += 5; } } } } if($player[$p2]["hp"] <= 0){ unset($player[$p2]); } if($player[$p1]["hp"] <= 0){ unset($player[$p1]); } } } echo count($player); ?> |
