Skip to content
Snippets Groups Projects
Select Git revision
  • df8ae10b456e1e26f08a108c451d0474e02693fc
  • main default protected
2 results

check05exe

Blame
  • Forked from LABOUREL Arnaud / M1 INFO FSI TP Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Patient.java 7.12 KiB
    package model.doctorviruspatient;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Objects;
    
    import javafx.scene.paint.Color;
    import model.Board;
    import model.Entity;
    import model.Square;
    import util.Position;
    import util.PositionUtil;
    
    public class Patient implements Entity {
        private final int priority = 0;
        Position position;
        private int age;
        private final Color viewColor = Color.BLUE;
        private Virus carriedVirus;
        List<Entity> visitedPatients;
        private static int patientsCount = 0;
        private int patientID;
        private Position ennemy;
        private boolean wandering;
    
        public Patient(Position p) {
            this.wandering = true;
            patientID = patientsCount;
            patientsCount += 1;
            this.visitedPatients = new ArrayList<Entity>();
            this.position = p;
        }
    
        public Patient(Position p, int age) {
            this.wandering = true;
            patientID = patientsCount;
            patientsCount += 1;
            this.visitedPatients = new ArrayList<Entity>();
            this.position = p;
            this.age = age;
        }
    
        @Override
        public List<Position> nextTurn(Board<Square> board) {
            if(isInfected()){
                return moveToDoctor();
            }
            updateWanderingStatus(board);
        
            if (wandering) {
                return performWandering(board);
            }
        
            resetVisitedPatientsIfNecessary();
        
            Position target = determineTarget(board);
        
            if (target == null) {
                visitedPatients.clear();
                return List.of();
            }
        
            Position nextPos = determineNextPosition(target, board);
        
            if (nextPos != null && board.doesPositionExist(nextPos)) {
                
                List<Position> adjacentPositions = PositionUtil.generateAllAdjacentPositions(nextPos, board);
                List<Position> result = interactWithAdjacentPositions(adjacentPositions, board);
                result.addAll(moveToPosition(nextPos, board));