Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions evilman.py
Original file line number Diff line number Diff line change
@@ -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}.")
15 changes: 15 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()
116 changes: 116 additions & 0 deletions player.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
99 changes: 99 additions & 0 deletions player.py
Original file line number Diff line number Diff line change
@@ -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.
Loading