Changeset 56
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r55 r56 97 97 procedure TCore.DoOnWin(Player: TPlayer); 98 98 begin 99 FormMain.Redraw; 99 100 ShowMessage(Format(SPlayerWins, [Player.Name])); 100 101 end; -
trunk/UGame.pas
r55 r56 1088 1088 procedure TGame.Attack(var AttackPower, DefendPower: Integer); 1089 1089 var 1090 AttackerRoll: Integer; 1091 DefenderRoll: Integer; 1090 AttackerDiceCount: Integer; 1091 DefenderDiceCount: Integer; 1092 AttackerHighestRoll: Integer; 1093 DefenderHighestRoll: Integer; 1094 RollResult: Integer; 1095 LoseCount: Integer; 1096 I: Integer; 1092 1097 begin 1093 1098 if AttackPower < 1 then … … 1096 1101 raise Exception.Create('Defender power have to be higher then or equal to 0.'); 1097 1102 while (AttackPower > 0) and (DefendPower > 0) do begin 1098 // Earch side do dice roll and compare result. Defender wins tie 1099 AttackerRoll := Random(6); 1100 DefenderRoll := Random(6); 1101 if AttackerRoll > DefenderRoll then Dec(DefendPower) 1102 else Dec(AttackPower); 1103 // Risk game rules: 1104 // Each side do their dice roll and compare result. Defender wins tie. 1105 // Attacer can use three dices and defender two 1106 if AttackPower < 3 then AttackerDiceCount := AttackPower 1107 else AttackerDiceCount := 3; 1108 if DefendPower < 2 then DefenderDiceCount := DefendPower 1109 else DefenderDiceCount := 2; 1110 // Roll and calculate each side highest number 1111 AttackerHighestRoll := 1; 1112 for I := 0 to AttackerDiceCount - 1 do begin 1113 RollResult := Random(7); 1114 if RollResult > AttackerHighestRoll then 1115 AttackerHighestRoll := RollResult; 1116 end; 1117 DefenderHighestRoll := 1; 1118 for I := 0 to DefenderDiceCount - 1 do begin 1119 RollResult := Random(7); 1120 if RollResult > DefenderHighestRoll then 1121 DefenderHighestRoll := RollResult; 1122 end; 1123 // Resolution 1124 LoseCount := Min(AttackerDiceCount, DefenderDiceCount); 1125 if AttackerHighestRoll > DefenderHighestRoll then Dec(DefendPower, LoseCount) 1126 else Dec(AttackPower, LoseCount); 1103 1127 end; 1104 1128 end;
Note:
See TracChangeset
for help on using the changeset viewer.