Changeset 56 for trunk


Ignore:
Timestamp:
Aug 19, 2014, 12:39:54 AM (10 years ago)
Author:
chronos
Message:
  • Modified: Attack changed to risk game dice rolling system.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r55 r56  
    9797procedure TCore.DoOnWin(Player: TPlayer);
    9898begin
     99  FormMain.Redraw;
    99100  ShowMessage(Format(SPlayerWins, [Player.Name]));
    100101end;
  • trunk/UGame.pas

    r55 r56  
    10881088procedure TGame.Attack(var AttackPower, DefendPower: Integer);
    10891089var
    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;
    10921097begin
    10931098  if AttackPower < 1 then
     
    10961101    raise Exception.Create('Defender power have to be higher then or equal to 0.');
    10971102  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);
    11031127  end;
    11041128end;
Note: See TracChangeset for help on using the changeset viewer.