MAINT: Apply pre-commit

Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
This commit is contained in:
Martin Thoma
2022-03-05 09:29:23 +01:00
parent f5e33ae38f
commit e64fb6795c
536 changed files with 6267 additions and 5556 deletions

View File

@@ -21,7 +21,7 @@ public abstract class AttackStrategy
{
Other.DamageTaken += 2;
}
Work.Push(punch.Punch switch
{
Punch.FullSwing => FullSwing,
@@ -36,7 +36,7 @@ public abstract class AttackStrategy
protected abstract void Hook();
protected abstract void Uppercut();
protected abstract void Jab();
protected void RegisterKnockout(string knockoutMessage)
{
Work.Clear();
@@ -45,4 +45,4 @@ public abstract class AttackStrategy
}
protected record AttackPunch(Punch Punch, bool IsBestPunch);
}
}

View File

@@ -42,4 +42,4 @@ public class Opponent : Boxer
Vulnerability = (Punch) GameUtils.Roll(4); // D1
} while (BestPunch == Vulnerability);
}
}
}

View File

@@ -112,4 +112,4 @@ public class OpponentAttackStrategy : AttackStrategy
private void RegisterOtherKnockedOut()
=> RegisterKnockout($"{Other} IS KNOCKED COLD AND {_opponent} IS THE WINNER AND CHAMP!");
}
}

View File

@@ -6,7 +6,7 @@ public class PlayerAttackStrategy : AttackStrategy
{
private readonly Boxer _player;
public PlayerAttackStrategy(Boxer player, Opponent opponent, Action notifyGameEnded, Stack<Action> work)
public PlayerAttackStrategy(Boxer player, Opponent opponent, Action notifyGameEnded, Stack<Action> work)
: base(opponent, work, notifyGameEnded) => _player = player;
protected override AttackPunch GetPunch()
@@ -118,4 +118,4 @@ public class PlayerAttackStrategy : AttackStrategy
void ScoreJabOnOpponent() => Other.DamageTaken += 3;
}
}
}

View File

@@ -6,9 +6,9 @@ WriteLine(new string('\t', 33) + "BOXING");
WriteLine(new string('\t', 15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
WriteLine("{0}{0}{0}BOXING OLYMPIC STYLE (3 ROUNDS -- 2 OUT OF 3 WINS){0}", Environment.NewLine);
var opponent = new Opponent();
var opponent = new Opponent();
opponent.SetName("WHAT IS YOUR OPPONENT'S NAME"); // J$
var player = new Boxer();
var player = new Boxer();
player.SetName("INPUT YOUR MAN'S NAME"); // L$
PrintPunchDescription();
@@ -26,4 +26,4 @@ for (var i = 1; i <= 3; i ++) // R
round.CheckPlayerWin();
if (round.GameEnded) break;
}
WriteLine("{0}{0}AND NOW GOODBYE FROM THE OLYMPIC ARENA.{0}", Environment.NewLine);
WriteLine("{0}{0}AND NOW GOODBYE FROM THE OLYMPIC ARENA.{0}", Environment.NewLine);

View File

@@ -6,4 +6,4 @@ public enum Punch
Hook = 2,
Uppercut = 3,
Jab = 4
}
}

View File

@@ -2,14 +2,14 @@
class Round
{
private readonly Boxer _player;
private readonly Boxer _opponent;
private readonly int _round;
private Stack<Action> _work = new();
private readonly PlayerAttackStrategy _playerAttackStrategy;
private readonly OpponentAttackStrategy _opponentAttackStrategy;
public bool GameEnded { get; private set; }
public Round(Boxer player, Opponent opponent, int round)
@@ -34,7 +34,7 @@ class Round
// This delay does not exist in the VB code but it makes a bit easier to follow the game.
// I assume the computers at the time were slow enough
// so that they did not need this delay...
Thread.Sleep(300);
Thread.Sleep(300);
action();
}
}
@@ -47,7 +47,7 @@ class Round
GameEnded = true;
}
}
public void CheckPlayerWin()
{
if (_player.IsWinner)
@@ -63,7 +63,7 @@ class Round
_opponent.ResetForNewRound();
_work.Push(RoundBegins);
}
private void RoundBegins()
{
Console.WriteLine();
@@ -93,4 +93,4 @@ class Round
{
_work.Push( GameUtils.RollSatisfies(10, x => x > 5) ? _opponentAttackStrategy.Attack : _playerAttackStrategy.Attack );
}
}
}

View File

@@ -17,7 +17,7 @@ public static class GameUtils
}
return result;
}
public static Func<int, int> Roll { get; } = upperLimit => (int) (upperLimit * Rnd.NextSingle()) + 1;
public static bool RollSatisfies(int upperLimit, Predicate<int> predicate) => predicate(Roll(upperLimit));
@@ -32,4 +32,4 @@ public static class GameUtils
_ => throw new ArgumentOutOfRangeException(nameof(punch), punch, null)
};
}
}

View File

@@ -42,4 +42,4 @@ final class Basic {
System.out.printf(message, args);
}
}
}
}

View File

@@ -7,9 +7,9 @@
* <p>
*/
public class Boxing {
private static final Basic.Console console = new Basic.Console();
private GameSession session;
public void play() {
@@ -224,4 +224,4 @@ public class Boxing {
console.print(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n");
console.print("BOXING OLYMPIC STYLE (3 ROUNDS -- 2 OUT OF 3 WINS)\n\n");
}
}
}

View File

@@ -64,4 +64,4 @@ public class GameSession {
public boolean isPlayerKnocked() {
return knocked;
}
}
}

View File

@@ -39,4 +39,4 @@ public class Player {
public boolean hitVulnerability(Punch punch) {
return vulnerability == punch;
}
}
}

View File

@@ -12,10 +12,10 @@ function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env python3
import random
QUESTION_PROMPT = '? '
QUESTION_PROMPT = "? "
def play():
print('BOXING')
print('CREATIVE COMPUTING MORRISTOWN, NEW JERSEY')
print('\n\n')
print('BOXING OLYMPIC STYLE (3 ROUNDS -- 2 OUT OF 3 WINS)')
print("BOXING")
print("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print("\n\n")
print("BOXING OLYMPIC STYLE (3 ROUNDS -- 2 OUT OF 3 WINS)")
opponent_score = 0
player_score = 0
@@ -18,29 +19,32 @@ def play():
opponent_knockedout = False
player_knockedout = False
print('WHAT IS YOUR OPPONENT\'S NAME', end=QUESTION_PROMPT)
print("WHAT IS YOUR OPPONENT'S NAME", end=QUESTION_PROMPT)
opponent_name = input()
print('WHAT IS YOUR MAN\'S NAME', end=QUESTION_PROMPT)
print("WHAT IS YOUR MAN'S NAME", end=QUESTION_PROMPT)
player_name = input()
print('DIFFERENT PUNCHES ARE 1 FULL SWING 2 HOOK 3 UPPERCUT 4 JAB')
print('WHAT IS YOUR MAN\'S BEST', end=QUESTION_PROMPT)
print("DIFFERENT PUNCHES ARE 1 FULL SWING 2 HOOK 3 UPPERCUT 4 JAB")
print("WHAT IS YOUR MAN'S BEST", end=QUESTION_PROMPT)
player_best = int(input())
print('WHAT IS HIS VULNERABILITY', end=QUESTION_PROMPT)
print("WHAT IS HIS VULNERABILITY", end=QUESTION_PROMPT)
player_weakness = int(input())
opponent_best = 0
opponent_weakness = 0
opponent_weakness = 0
while opponent_best == opponent_weakness:
opponent_best = random.randint(1, 4)
opponent_weakness = random.randint(1, 4)
print('{}\'S ADVANTAGE is {} AND VULNERABILITY IS SECRET.'
.format(opponent_name, opponent_weakness))
print(
"{}'S ADVANTAGE is {} AND VULNERABILITY IS SECRET.".format(
opponent_name, opponent_weakness
)
)
for round in (1, 2, 3):
print('ROUND {} BEGINS...\n'.format(round))
print(f"ROUND {round} BEGINS...\n")
if opponent_score >= 2 or player_score >= 2:
break
@@ -53,96 +57,117 @@ def play():
player_damage += 2
if punch == 1:
print('{} TAKES A FULL SWING AND'.format(opponent_name), end = ' ')
print(f"{opponent_name} TAKES A FULL SWING AND", end=" ")
if player_weakness == 1 or random.randint(1, 60) < 30:
print('POW!!!! HE HITS HIM RIGHT IN THE FACE!')
print("POW!!!! HE HITS HIM RIGHT IN THE FACE!")
if player_damage > 35:
player_knockedout = True
break
player_damage += 15
else:
print('BUT IT\'S BLOCKED!')
print("BUT IT'S BLOCKED!")
elif punch == 2:
print('{} GETS {} IN THE JAW (OUCH!)'.format(opponent_name, player_name), end = ' ')
print(
"{} GETS {} IN THE JAW (OUCH!)".format(
opponent_name, player_name
),
end=" ",
)
player_damage += 7
print('....AND AGAIN')
print("....AND AGAIN")
if player_damage > 35:
player_knockedout = True
break
player_damage += 5
elif punch == 3:
print('{} IS ATTACKED BY AN UPPERCUT (OH,OH)'.format(player_name))
print(f"{player_name} IS ATTACKED BY AN UPPERCUT (OH,OH)")
if player_weakness == 3 or random.randint(1, 200) > 75:
print('{} BLOCKS AND HITS {} WITH A HOOK'.format(player_name, opponent_name))
print(
"{} BLOCKS AND HITS {} WITH A HOOK".format(
player_name, opponent_name
)
)
opponent_damage += 5
else:
print('AND {} CONNECTS...'.format(opponent_name))
print(f"AND {opponent_name} CONNECTS...")
player_damage += 8
else:
print('{} JABS AND'.format(opponent_name), end = ' ')
print(f"{opponent_name} JABS AND", end=" ")
if player_weakness == 4 or random.randint(1, 7) > 4:
print('BLOOD SPILLS !!!')
print("BLOOD SPILLS !!!")
player_damage += 3
else:
print('AND IT\'S BLOCKED (LUCKY BLOCK!)')
print("AND IT'S BLOCKED (LUCKY BLOCK!)")
else:
print('{}\'S PUNCH'.format(player_name), end='? ')
print(f"{player_name}'S PUNCH", end="? ")
punch = int(input())
if punch == opponent_weakness:
opponent_damage += 2
if punch == 1:
print('{} SWINGS AND'.format(player_name), end = ' ')
print(f"{player_name} SWINGS AND", end=" ")
if opponent_weakness == 1 or random.randint(1, 30) < 10:
print('HE CONNECTS!')
print("HE CONNECTS!")
if opponent_damage > 35:
opponent_knockedout = True
break
opponent_damage += 15
else:
print('HE MISSES')
print("HE MISSES")
elif punch == 2:
print('{} GIVES THE HOOK...'.format(player_name), end = ' ')
print(f"{player_name} GIVES THE HOOK...", end=" ")
if opponent_weakness == 2 or random.randint(1, 2) == 1:
print('CONNECTS...')
print("CONNECTS...")
opponent_damage += 7
else:
print('BUT IT\'S BLOCKED!!!!!!!!!!!!!')
print("BUT IT'S BLOCKED!!!!!!!!!!!!!")
elif punch == 3:
print('{} TRIES AN UPPERCUT'.format(player_name), end = ' ')
print(f"{player_name} TRIES AN UPPERCUT", end=" ")
if opponent_weakness == 3 or random.randint(1, 100) < 51:
print('AND HE CONNECTS!')
print("AND HE CONNECTS!")
opponent_damage += 4
else:
print('AND IT\'S BLOCKED (LUCKY BLOCK!)')
print("AND IT'S BLOCKED (LUCKY BLOCK!)")
else:
print('{} JABS AT {}\'S HEAD'.format(player_name, opponent_name), end = ' ')
print(
f"{player_name} JABS AT {opponent_name}'S HEAD",
end=" ",
)
if opponent_weakness == 4 or random.randint(1, 8) < 4:
print('AND HE CONNECTS!')
print("AND HE CONNECTS!")
opponent_damage += 3
else:
print('AND IT\'S BLOCKED (LUCKY BLOCK!)')
print("AND IT'S BLOCKED (LUCKY BLOCK!)")
if player_knockedout or opponent_knockedout:
break
elif player_damage > opponent_damage:
print('{} WINS ROUND {}'.format(opponent_name, round))
print(f"{opponent_name} WINS ROUND {round}")
opponent_score += 1
else:
print('{} WINS ROUND {}'.format(player_name, round))
print(f"{player_name} WINS ROUND {round}")
player_score += 1
if player_knockedout:
print('{} IS KNOCKED COLD AND {} IS THE WINNER AND CHAMP'.format(player_name, opponent_name))
print(
"{} IS KNOCKED COLD AND {} IS THE WINNER AND CHAMP".format(
player_name, opponent_name
)
)
elif opponent_knockedout:
print('{} IS KNOCKED COLD AND {} IS THE WINNER AND CHAMP'.format(opponent_name, player_name))
print(
"{} IS KNOCKED COLD AND {} IS THE WINNER AND CHAMP".format(
opponent_name, player_name
)
)
elif opponent_score > player_score:
print('{} WINS (NICE GOING), {}'.format(opponent_name, player_name))
print(f"{opponent_name} WINS (NICE GOING), {player_name}")
else:
print('{} AMAZINGLY WINS'.format(player_name))
print(f"{player_name} AMAZINGLY WINS")
print('\n\nAND NOW GOODBYE FROM THE OLYMPIC ARENA.')
print("\n\nAND NOW GOODBYE FROM THE OLYMPIC ARENA.")
if __name__ == '__main__':
if __name__ == "__main__":
play()