diff --git a/evilman.py b/evilman.py new file mode 100644 index 0000000..5096392 --- /dev/null +++ b/evilman.py @@ -0,0 +1,13 @@ + +class Evilman: + def __init__(self, name, power1, power2, power3): + self.name = name # Name of the Evilman + self.power1 = power1 # Power 1 of the Evilman + self.power2 = power2 # Power 2 of the Evilman + self.power3 = power3 # Power 3 of the Evilman + + def counter_player(self, player): + """ + Counter the actions of the player. + """ + print(f"{self.name} uses {self.power1} to counter {player.name}.") \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..449d9ce --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +from protector import Protector +from player import Player +from evilman import Evilman + +# Creating the objects +protector = Protector(name="Guardian", power1="Speed++ !", power2="Stop the Evilman for 5 seconds !", power3="Invisibility !") +player = Player(name="Alex", objective="Find a job") +evilman = Evilman(name="Dark Lord", power1="Stop the player !", power2="Slow Motion !", power3="Make an obstacle appear !") + +# Using the methods +protector.help_player(player) +protector.counter_evilman(evilman) + +player.move_forward() +player.dash() \ No newline at end of file diff --git a/player.cs b/player.cs new file mode 100644 index 0000000..9552952 --- /dev/null +++ b/player.cs @@ -0,0 +1,116 @@ +using System; + +public enum PlayerStatus +{ + Normal, + Stopped, + SlowMotion, + Invisible, + SpeedBoost, + Blocked +} + +public class Player +{ + public string Name { get; set; } + public string Objective { get; set; } + public int[] Position { get; set; } + public PlayerStatus Status { get; set; } + + public Player(string name, string objective) + { + Name = name; + Objective = objective; + Position = new int[] { 0, 0 }; // x, y coordinates + Status = PlayerStatus.Normal; + } + + public void MoveLeft() + { + if (IsBlockedOrStopped()) + return; + + Position[0] -= 1; + Console.WriteLine($"{Name} moves left. New position: [{Position[0]}, {Position[1]}]"); + } + + public void MoveRight() + { + if (IsBlockedOrStopped()) + return; + + Position[0] += 1; + Console.WriteLine($"{Name} moves right. New position: [{Position[0]}, {Position[1]}]"); + } + + public void MoveForward() + { + if (IsBlockedOrStopped()) + return; + + Position[1] += 1; + Console.WriteLine($"{Name} moves forward. New position: [{Position[0]}, {Position[1]}]"); + } + + public void MoveBackward() + { + if (IsBlockedOrStopped()) + return; + + Position[1] -= 1; + Console.WriteLine($"{Name} moves backward. New position: [{Position[0]}, {Position[1]}]"); + } + + public void Jump() + { + if (IsBlockedOrStopped()) + return; + + Console.WriteLine($"{Name} jumps!"); + } + + public void Dash() + { + if (IsBlockedOrStopped()) + return; + + Position[1] += 2; + Console.WriteLine($"{Name} dashes forward. New position: [{Position[0]}, {Position[1]}]"); + } + + public void ChangeStatus(PlayerStatus newStatus) + { + Status = newStatus; + Console.WriteLine($"{Name} is now {Status}."); + } + + private bool IsBlockedOrStopped() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot move."); + return true; + } + if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot move."); + return true; + } + return false; + } +} + +// Example usage +public class Program +{ + public static void Main(string[] args) + { + Player player = new Player("Alex", "Find a job"); + + player.MoveForward(); // Normal state + player.ChangeStatus(PlayerStatus.Blocked); + player.MoveForward(); // Blocked state + player.ChangeStatus(PlayerStatus.SpeedBoost); + player.Dash(); // Speed boost state + } +} \ No newline at end of file diff --git a/player.py b/player.py new file mode 100644 index 0000000..f98c79b --- /dev/null +++ b/player.py @@ -0,0 +1,99 @@ +from enum import Enum + +class PlayerStatus(Enum): + NORMAL = "normal" + STOPPED = "stopped" + SLOW_MOTION = "in slow motion" + INVISIBLE = "invisible" + SPEED_BOOST = "speed++" + BLOCKED = "blocked by an obstacle" + + +class Player: + def __init__(self, name, objective): + self.name = name # Name of the player + self.objective = objective # Player's objective (e.g., find a job) + self.position = [0, 0] # Player's position on the map (x, y) + self.status = PlayerStatus.NORMAL # Default status is "normal" + + def move_left(self): + """ + Move the player to the left (decreases the x-coordinate). + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move left.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move left.") + else: + self.position[0] -= 1 + print(f"{self.name} moves left. New position: {self.position}") + + def move_right(self): + """ + Move the player to the right (increases the x-coordinate). + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move right.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move right.") + else: + self.position[0] += 1 + print(f"{self.name} moves right. New position: {self.position}") + + def move_forward(self): + """ + Move the player forward (increases the y-coordinate). + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move forward.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move forward.") + else: + self.position[1] += 1 + print(f"{self.name} moves forward. New position: {self.position}") + + def move_backward(self): + """ + Move the player backward (decreases the y-coordinate). + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move backward.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move backward.") + else: + self.position[1] -= 1 + print(f"{self.name} moves backward. New position: {self.position}") + + def jump(self): + """ + Make the player jump. + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot jump.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot jump.") + else: + print(f"{self.name} jumps!") + + def dash(self): + """ + Make the player dash forward quickly by 2 units. + """ + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot dash.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot dash.") + else: + self.position[1] += 2 + print(f"{self.name} dashes forward. New position: {self.position}") + + def change_status(self, new_status): + """ + Change the status of the player. + """ + self.status = new_status + print(f"{self.name} is now {self.status.value}.") + + +# Example usage in main.py would be similar to: +# player.move_left(), player.jump(), etc. \ No newline at end of file diff --git a/player2.cs b/player2.cs new file mode 100644 index 0000000..62e957a --- /dev/null +++ b/player2.cs @@ -0,0 +1,167 @@ +using System; +using System.Threading.Tasks; // For Task.Delay to simulate time.sleep() + +public enum PlayerStatus +{ + NORMAL, + STOPPED, + SLOW_MOTION, + INVISIBLE, + SPEED_BOOST, + BLOCKED +} + +public enum PowerType +{ + BONUS, + MALUS +} + +public class Power +{ + public string Name { get; } + public PowerType Type { get; } + public int CastingTime { get; } // Casting time in milliseconds + public int Cooldown { get; } // Cooldown in milliseconds + private DateTime lastUsedTime; + + public Power(string name, PowerType type, int castingTime, int cooldown) + { + Name = name; + Type = type; + CastingTime = castingTime; + Cooldown = cooldown; + lastUsedTime = DateTime.MinValue; // Initialized to a time in the past + } + + public async Task Activate(Player target) + { + var currentTime = DateTime.Now; + var timeSinceLastUse = (currentTime - lastUsedTime).TotalMilliseconds; + + if (timeSinceLastUse < Cooldown) + { + Console.WriteLine($"{Name} is still in cooldown. Wait {(Cooldown - timeSinceLastUse) / 1000.0:F2} seconds."); + return; + } + + Console.WriteLine($"Preparing {Name}... (casting time: {CastingTime / 1000.0:F2} seconds)"); + await Task.Delay(CastingTime); // Simulating casting time + + // Power is now activated + Console.WriteLine($"{Name} activated on {target.Name}!"); + lastUsedTime = DateTime.Now; // Reset cooldown timer + + if (Type == PowerType.BONUS) + { + target.ApplyBonus(this); + } + else if (Type == PowerType.MALUS) + { + target.ApplyMalus(this); + } + } +} + +public class Player +{ + public string Name { get; } + public PlayerStatus Status { get; set; } + + public Player(string name) + { + Name = name; + Status = PlayerStatus.NORMAL; // Player starts in a normal state + } + + public void ApplyBonus(Power power) + { + Console.WriteLine($"{Name} receives a bonus : {power.Name}!"); + // Apply the effect of the bonus here, such as changing the player's status + } + + public void ApplyMalus(Power power) + { + Console.WriteLine($"{Name} is affected by a malus : {power.Name}!"); + // Apply the effect of the malus here, such as slowing down the player + } +} + +public class Evilman +{ + public string Name { get; } + public Power MalusPower { get; } + public Power BlockPower { get; } + + public Evilman(string name = "Evilman") + { + Name = name; + SlowMotionPower = new Power("Slow Motion Trap", PowerType.MALUS, 3000, 8000); // 3 seconds casting, 8 seconds cooldown + BlockPower = new Power("Block Path", PowerType.MALUS, 2000, 10000); // 2 seconds casting, 10 seconds cooldown + } + + public async Task UseSlowMotionPower(Player player) + { + Console.WriteLine($"{Name} tries to use Slow Motion power: {SlowMotionPower.Name} on {player.Name}"); + await SlowMotionPower.Activate(player); + } + + public async Task UseBlockPower(Player player) + { + Console.WriteLine($"{Name} tries to block {player.Name}'s path with {BlockPower.Name}"); + await BlockPower.Activate(player); + } +} + +public class Protector +{ + public string Name { get; } + public Power BonusPower { get; } + public Power ShieldPower { get; } + + public Protector(string name = "Protector") + { + Name = name; + SpeedPower = new Power("Speed Boost", PowerType.BONUS, 2000, 5000); // 2 seconds casting, 5 seconds cooldown + InvisibleShieldPower = new Power("Invisible Shield", PowerType.BONUS, 1000, 7000); // 1 second casting, 7 seconds cooldown + } + + public async Task UseSpeedPower(Player player) + { + Console.WriteLine($"{Name} tries to use Speed Boost power: {SpeedPower.Name} on {player.Name}"); + await SpeedPower.Activate(player); + } + + public async Task UseInvisibleShieldPower(Player player) + { + Console.WriteLine($"{Name} tries to protect {player.Name} with {InvisibleShieldPower.Name}"); + await InvisibleShieldPower.Activate(player); + } +} + +public class Program +{ + public static async Task Main(string[] args) + { + // Creating actors + Player player = new Player("Alex"); + Evilman evilman = new Evilman(); + Protector protector = new Protector(); + + // Evilman uses a malus power on the player + await evilman.UseSlowMotionPower(player); // Slow motion trap, 3 seconds casting, 8 seconds cooldown + await Task.Delay(4000); // Simulating time passage = 4 seconds + await evilman.UseSlowMotionPower(player); // Still in cooldown + + // Protector uses a bonus power on the player + await protector.UseSpeedPower(player); // Speed Boost, 2 seconds casting, 5 seconds cooldown + await Task.Delay(6000); // Simulating time passage = 6 seconds + await protector.UseSpeedPower(player); // Can be used again after cooldown + + // Evilman tries to block the player + await evilman.UseBlockPower(player); // Block path, 2 seconds casting, 10 seconds cooldown + + // Protector protects the player with a shield + await protector.UseInvisibleShieldPower(player); // Invisible shield, 1 second casting, 7 seconds cooldown + } +} \ No newline at end of file diff --git a/player2.py b/player2.py new file mode 100644 index 0000000..a37ee02 --- /dev/null +++ b/player2.py @@ -0,0 +1,130 @@ +import time +from enum import Enum +from datetime import datetime, timedelta + +class PlayerStatus(Enum): + NORMAL = "normal" + STOPPED = "stopped" + SLOW_MOTION = "in slow motion" + INVISIBLE = "invisible" + SPEED_BOOST = "speed++" + BLOCKED = "blocked by an obstacle" + +class PowerType(Enum): + BONUS = "bonus" + MALUS = "malus" + +class Power: + def __init__(self, name, power_type, casting_time, cooldown): + self.name = name + self.type = power_type + self.casting_time = casting_time # in seconds + self.cooldown = cooldown # in seconds + self.last_used_time = datetime.min # Last time the power was used + + def activate(self, target): + current_time = datetime.now() + time_since_last_use = (current_time - self.last_used_time).total_seconds() + + if time_since_last_use < self.cooldown: + print(f"{self.name} is still in cooldown. Wait {self.cooldown - time_since_last_use:.2f} seconds.") + return + + print(f"Preparing {self.name}... (casting time: {self.casting_time} seconds)") + time.sleep(self.casting_time) # Simulating casting time + + # Power is now activated + print(f"{self.name} activated on {target.name}!") + self.last_used_time = datetime.now() # Reset cooldown timer + + if self.type == PowerType.BONUS: + target.apply_bonus(self) + elif self.type == PowerType.MALUS: + target.apply_malus(self) + +class Player: + def __init__(self, name): + self.name = name + self.status = PlayerStatus.NORMAL + + def apply_bonus(self, power): + print(f"{self.name} receives a bonus from {power.name}!") + # Apply the effect of the bonus here (e.g., change player status) + + def apply_malus(self, power): + print(f"{self.name} is affected by a malus from {power.name}!") + # Apply the effect of the malus here (e.g., slow down the player) + +class Evilman: + def __init__(self, name="Evilman"): + self.name = name + # Powers : + self.slowmotion_power = Power("Slow Motion Trap", PowerType.MALUS, 3, 8) # 3 seconds casting, 8 seconds cooldown + self.block_power = Power("Block Path", PowerType.MALUS, 2, 10) # 2 seconds casting, 10 seconds cooldown + self.stop_power = Power("Stop", PowerType.MALUS, 5, 10) # 5 seconds casting, 10 seconds cooldown + + def use_slowmotion_power(self, player): + print(f"{self.name} tries to use malus power: {self.malus_power.name} on {player.name}") + self.slowmotion_power.activate(player) + + def use_block_power(self, player): + print(f"{self.name} tries to block {player.name}'s path with {self.block_power.name}") + self.block_power.activate(player) + + def use_stop_power(self, player): + print(f"{self.name} tries to stop {player.name} with {self.stop_power.name}") + self.stop_power.activate(player) + +class Protector: + def __init__(self, name="Protector"): + self.name = name + # Powers : + self.speed_power = Power("Speed Boost", PowerType.BONUS, 2, 5) # 2 seconds casting, 5 seconds cooldown + self.invisibleshield_power = Power("Invisible Shield", PowerType.BONUS, 1, 7) # 1 second casting, 7 seconds cooldown + self.stop_evilman_power = Power("Stop Evilman", PowerType.BONUS, 5, 10) # 5 second casting, 10 seconds cooldown + + def use_speed_power(self, player): + print(f"{self.name} tries to use bonus power: {self.speed_power.name} on {player.name}") + self.speed_power.activate(player) + + def use_invisibleshield_power(self, player): + print(f"{self.name} tries to protect {player.name} with {self.invisibleshield_power.name}") + self.invisibleshield_power.activate(player) + + def use_stop_evilman_power(self, player): + print(f"{self.name} tries to protect {player.name} with {self.stop_evilman_power.name}") + self.stop_evilman_power.activate(player) + +# Main code to simulate interaction +def main(): + # Create actors + player = Player("Alex") + evilman = Evilman() + protector = Protector() + + # Evilman uses a malus power on the player + evilman.use_slowmotion_power(player) # Slow motion trap, 3 seconds casting, 8 seconds cooldown + time.sleep(4) # Simulating time passage + evilman.use_slowmotion_power(player) # Still in cooldown + + # Protector uses a bonus power on the player + protector.use_speed_power(player) # Speed Boost, 2 seconds casting, 5 seconds cooldown + time.sleep(6) # Simulating time passage + protector.use_speed_power(player) # Can be used again after cooldown + + # Evilman tries to block the player + evilman.use_block_power(player) # Block path, 2 seconds casting, 10 seconds cooldown + + # Protector protects the player with a shield + protector.use_invisibleshield_power(player) # Invisible shield, 1 second casting, 7 seconds cooldown + + # Evilman tries to stop the player + evilman.use_stop_power(player) # Player stopped, 5 seconds casting, 10 seconds cooldown + + # Protector helps the player stopping Evilman + protector.use_stop_evilman_power(player) # Stop Evilman, 5 second casting, 10 seconds cooldown + + + +if __name__ == "__main__": + main() diff --git a/player3.cs b/player3.cs new file mode 100644 index 0000000..fd81c6c --- /dev/null +++ b/player3.cs @@ -0,0 +1,188 @@ +using System; +using System.Threading; + +public enum PlayerStatus +{ + NORMAL, + STOPPED, + SLOW_MOTION, + INVISIBLE, + SPEED_BOOST, + BLOCKED +} + +public enum PowerType +{ + BONUS, + MALUS +} + +public class Power +{ + public string Name { get; private set; } + public PowerType Type { get; private set; } + public int CastingTime { get; private set; } // In seconds + public int Cooldown { get; private set; } // In seconds + private DateTime LastUsedTime; + + public Power(string name, PowerType type, int castingTime, int cooldown) + { + Name = name; + Type = type; + CastingTime = castingTime; + Cooldown = cooldown; + LastUsedTime = DateTime.MinValue; + } + + public void Activate(Player target) + { + TimeSpan timeSinceLastUse = DateTime.Now - LastUsedTime; + + if (timeSinceLastUse.TotalSeconds < Cooldown) + { + Console.WriteLine($"{Name} is still in cooldown. Wait {Cooldown - timeSinceLastUse.TotalSeconds:F2} seconds."); + return; + } + + Console.WriteLine($"Preparing {Name}... (casting time: {CastingTime} seconds)"); + Thread.Sleep(CastingTime * 1000); // Simulate casting time + + // Power is now activated + Console.WriteLine($"{Name} activated on {target.Name}!"); + LastUsedTime = DateTime.Now; // Reset cooldown timer + + if (Type == PowerType.BONUS) + { + target.ApplyBonus(this); + } + else if (Type == PowerType.MALUS) + { + target.ApplyMalus(this); + } + } +} + +public class Player +{ + public string Name { get; private set; } + public PlayerStatus Status { get; private set; } + + public Player(string name) + { + Name = name; + Status = PlayerStatus.NORMAL; + } + + public void ApplyBonus(Power power) + { + Console.WriteLine($"{Name} receives a bonus from {power.Name}!"); + // Apply the bonus effect here (e.g., change player status) + } + + public void ApplyMalus(Power power) + { + Console.WriteLine($"{Name} is affected by a malus from {power.Name}!"); + // Apply the malus effect here (e.g., slow down the player) + } +} + +public class Evilman +{ + public string Name { get; private set; } + public Power SlowMotionPower { get; private set; } + public Power BlockPower { get; private set; } + public Power StopPower { get; private set; } + + public Evilman(string name = "Evilman") + { + Name = name; + SlowMotionPower = new Power("Slow Motion Trap", PowerType.MALUS, 3, 8); + BlockPower = new Power("Block Path", PowerType.MALUS, 2, 10); + StopPower = new Power("Stop", PowerType.MALUS, 5, 10); + } + + public void UseSlowMotionPower(Player player) + { + Console.WriteLine($"{Name} tries to use malus power: {SlowMotionPower.Name} on {player.Name}"); + SlowMotionPower.Activate(player); + } + + public void UseBlockPower(Player player) + { + Console.WriteLine($"{Name} tries to block {player.Name}'s path with {BlockPower.Name}"); + BlockPower.Activate(player); + } + + public void UseStopPower(Player player) + { + Console.WriteLine($"{Name} tries to stop {player.Name} with {StopPower.Name}"); + StopPower.Activate(player); + } +} + +public class Protector +{ + public string Name { get; private set; } + public Power SpeedPower { get; private set; } + public Power InvisibleShieldPower { get; private set; } + public Power StopEvilmanPower { get; private set; } + + public Protector(string name = "Protector") + { + Name = name; + SpeedPower = new Power("Speed Boost", PowerType.BONUS, 2, 5); + InvisibleShieldPower = new Power("Invisible Shield", PowerType.BONUS, 1, 7); + StopEvilmanPower = new Power("Stop Evilman", PowerType.BONUS, 5, 10); + } + + public void UseSpeedPower(Player player) + { + Console.WriteLine($"{Name} tries to use bonus power: {SpeedPower.Name} on {player.Name}"); + SpeedPower.Activate(player); + } + + public void UseInvisibleShieldPower(Player player) + { + Console.WriteLine($"{Name} tries to protect {player.Name} with {InvisibleShieldPower.Name}"); + InvisibleShieldPower.Activate(player); + } + + public void UseStopEvilmanPower(Player player) + { + Console.WriteLine($"{Name} tries to protect {player.Name} with {StopEvilmanPower.Name}"); + StopEvilmanPower.Activate(player); + } +} + +class Program +{ + static void Main(string[] args) + { + // Create actors + Player player = new Player("Alex"); + Evilman evilman = new Evilman(); + Protector protector = new Protector(); + + // Evilman uses a malus power on the player + evilman.UseSlowMotionPower(player); // Slow motion trap, 3 seconds casting, 8 seconds cooldown + Thread.Sleep(4000); // Simulating time passage + evilman.UseSlowMotionPower(player); // Still in cooldown + + // Protector uses a bonus power on the player + protector.UseSpeedPower(player); // Speed Boost, 2 seconds casting, 5 seconds cooldown + Thread.Sleep(6000); // Simulating time passage + protector.UseSpeedPower(player); // Can be used again after cooldown + + // Evilman tries to block the player + evilman.UseBlockPower(player); // Block path, 2 seconds casting, 10 seconds cooldown + + // Protector protects the player with a shield + protector.UseInvisibleShieldPower(player); // Invisible shield, 1 second casting, 7 seconds cooldown + + // Evilman tries to stop the player + evilman.UseStopPower(player); // Player stopped, 5 seconds casting, 10 seconds cooldown + + // Protector helps the player by stopping Evilman + protector.UseStopEvilmanPower(player); // Stop Evilman, 5 seconds casting, 10 seconds cooldown + } +} diff --git a/player4.cs b/player4.cs new file mode 100644 index 0000000..36eea75 --- /dev/null +++ b/player4.cs @@ -0,0 +1,131 @@ +using System; +using System.Threading; + +enum PlayerStatus +{ + Normal, + Stopped, + SlowMotion, + Invisible, + SpeedBoost, + Blocked +} + +class Player +{ + public string Name { get; private set; } + public PlayerStatus Status { get; private set; } + public int[] Position { get; private set; } = new int[2]; // [x, y] + + public Player(string name) + { + Name = name; + Status = PlayerStatus.Normal; + Position[0] = 0; // X position + Position[1] = 0; // Y position + } + + public void MoveLeft() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot move left."); + } + else if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot move left."); + } + else + { + Position[0] -= 1; + Console.WriteLine($"{Name} moves left. New position: ({Position[0]}, {Position[1]})"); + } + } + + public void MoveRight() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot move right."); + } + else if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot move right."); + } + else + { + Position[0] += 1; + Console.WriteLine($"{Name} moves right. New position: ({Position[0]}, {Position[1]})"); + } + } + + public void MoveForward() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot move forward."); + } + else if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot move forward."); + } + else + { + Position[1] += 1; + Console.WriteLine($"{Name} moves forward. New position: ({Position[0]}, {Position[1]})"); + } + } + + public void MoveBackward() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot move backward."); + } + else if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot move backward."); + } + else + { + Position[1] -= 1; + Console.WriteLine($"{Name} moves backward. New position: ({Position[0]}, {Position[1]})"); + } + } + + public void Jump() + { + if (Status == PlayerStatus.Blocked) + { + Console.WriteLine($"{Name} is blocked and cannot jump."); + } + else if (Status == PlayerStatus.Stopped) + { + Console.WriteLine($"{Name} is stopped and cannot jump."); + } + else + { + Console.WriteLine($"{Name} jumps!"); + // Simulate jump by moving up and forward + Position[1] += 2; // Simulate upward jump + Position[0] += 2; // Simulate forward movement + Console.WriteLine($"{Name} is at position: ({Position[0]}, {Position[1]}) - Jumping"); + Thread.Sleep(500); // Short delay to simulate jump duration + Position[1] -= 2; // Simulate landing + Console.WriteLine($"{Name} lands. New position: ({Position[0]}, {Position[1]})"); + } + } +} + +class Program +{ + static void Main(string[] args) + { + Player player = new Player("Martin"); + + player.MoveLeft(); // Move left + player.Jump(); // Player jumps + player.MoveRight(); // Move right + player.Jump(); // Player jumps again + } +} diff --git a/player4.py b/player4.py new file mode 100644 index 0000000..8dfb789 --- /dev/null +++ b/player4.py @@ -0,0 +1,79 @@ +import time +from enum import Enum + +class PlayerStatus(Enum): + NORMAL = "normal" + STOPPED = "stopped" + SLOW_MOTION = "in slow motion" + INVISIBLE = "invisible" + SPEED_BOOST = "speed++" + BLOCKED = "blocked by an obstacle" + +class Player: + def __init__(self, name): + self.name = name + self.status = PlayerStatus.NORMAL + self.position = [0, 0] # (x, y) coordinates, y being vertical + + def move_left(self): + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move left.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move left.") + else: + self.position[0] -= 1 + print(f"{self.name} moves left. New position: {self.position}") + + def move_right(self): + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move right.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move right.") + else: + self.position[0] += 1 + print(f"{self.name} moves right. New position: {self.position}") + + def move_forward(self): + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move forward.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move forward.") + else: + self.position[1] += 1 + print(f"{self.name} moves forward. New position: {self.position}") + + def move_backward(self): + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot move backward.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot move backward.") + else: + self.position[1] -= 1 + print(f"{self.name} moves backward. New position: {self.position}") + + def jump(self): # Saute en hauteur de 2, en avant de 2 et redescends en hauteur de 2 + if self.status == PlayerStatus.BLOCKED: + print(f"{self.name} is blocked and cannot jump.") + if self.status == PlayerStatus.STOPPED: + print(f"{self.name} is stopped and cannot jump.") + else: + print(f"{self.name} jumps!") + # Simulate jump by moving up and down on the Y axis + self.position[1] += 2 # Simulate upward jump + self.position[0] += 2 # Simulate forward jump + print(f"{self.name} is at position: {self.position} - Jumping") + time.sleep(0.5) # Short delay to simulate the jump + self.position[1] -= 2 # Simulate landing + print(f"{self.name} lands. New position: {self.position}") + +# Example usage +def main(): + player = Player("Martin") + + player.move_left() # Move left + player.jump() # Player jumps + player.move_right() # Move right + player.jump() # Player jumps again + +if __name__ == "__main__": + main() diff --git a/protector.py b/protector.py new file mode 100644 index 0000000..3b3d8db --- /dev/null +++ b/protector.py @@ -0,0 +1,18 @@ +class Protector: + def __init__(self, name, power1, power2, power3): + self.name = name # Name of the protector + self.power1 = power1 # Power 1 of the protector + self.power2 = power2 # Power 2 of the protector + self.power3 = power3 # Power 3 of the protector + + def help_player(self, player): + """ + Help the player to reach his job. + """ + print(f"{self.name} uses {self.power1} to help {player.name} reach his job.") + + def counter_evilman(self, evilman): + """ + Counter the actions of Evilman to protect the player. + """ + print(f"{self.name} uses {self.power2} to counter {evilman.name} and protect the player.") \ No newline at end of file