1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| package main;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;
public class Personnage implements KeyListener {
public Personnage(int pv, int lvl, int abs, int ord, int sS) {
System.out.println("Initialisation des données.");
try{
if(Game.getBdif() == true){
System.out.println("Difficulté : " + Game.difficult);
}else{
Game.difficult = 2;
System.out.println("Difficulté : " + Game.difficult);
}
secretSetting = sS;
life = pv;
level = lvl;
setX(abs);
setY(ord);
for(;getX() < Objet.sol;x++){
System.out.print(this.getX());
}
this.setX(this.getX() + 1);
System.out.println("\n\nCoordonnée final : "+this.getX() +" "+ this.getY());
//Fin de la récupération
}catch(Exception e){
System.out.println("Erreur "+e.getMessage()+" : Initialisation du personnage incorrect, s'il vous plaît,\n"
+ "contactez le créateur.");
}
System.out.println("\nInitialisation réussi.");
}
public void deplace(int dx, int dy){
setX(getX() + dx);
setY(getY() + dy);
}
public void affiche(){
System.out.println("\nVous êtes au coordonnée: " + getX() +" et " + getY());
System.out.println("Vous avez "+life+" coeurs et "+level+" niveaux\n");
}
public void regeneration(){
life += 10;
testvie();
}
public void testvie(){
if(life >= 20){
life = 20;
System.out.println("Rectification de la vie à 20.");
}else if(life <= 0){
System.out.println("======== GAME OVER =========");
System.out.println("Recommencer? 0=non, 1=oui");
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
int tryagain = sc.nextInt();
if(tryagain == 0){
System.exit(0);
}else{
this.delete();
}
}
else{}
}
public void sS(){
if(secretSetting==1){
this.life=999;
this.level=999;
}
}
public void beattacked(int difficulty){
this.life -= 2 * difficulty;
}
public void testforblock(){
if(this.x <= Objet.sol){
this.x = Objet.sol + 1;
}
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyChar()=='d'){
int i = 0;
for(i=0;i<32;i++){
this.deplace(1, 1);
System.out.print(this.getX() +" "+ this.getY());
}
System.out.println("Nouvelle coordonnée à : "+this.getX() + " " + this.getY());
}
}
public void delete(){
Game.start();
this.level = 0;
this.life = 20;
this.setX(Objet.sol + 1);
this.setY(0);
map_generation.Seed.generateMap();
}
public void action(){
while(true){
System.out.println("Qu'est-ce que vous voulez faire?\n3=Aller à droite\n1=Aller à gauche\n"
+ "5=Sauter\n8=Quitter");
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
int rep = sc.nextInt();
if(rep == 3){
int i = 0;
for(i=0;i<32;i++){
this.deplace(0, 1);
System.out.print(this.getX() + " ");
System.out.print(this.getY() + " ");
}
System.out.println("\n\nNouvelle coordonnée à : "+this.getX() + " " + this.getY());
}else if(rep == 1){
int i = 0;
for(;i<32;i++){
this.deplace(0, -1);
System.out.print(this.getX() + " ");
System.out.print(this.getY() + " ");
}
System.out.println("\n\nNouvelle coordonnée à : "+this.getX() + " " + this.getY());
}else if(rep == 5){
int i = 0;
for(;i<32;i++){
this.deplace(1, 0);
System.out.print(this.getX() + " ");
System.out.print(this.getY() + " ");
}
for(i=0;i<32;i++){
this.deplace(-1, 0);
System.out.print(this.getX() + " ");
System.out.print(this.getY() + " ");
}
System.out.println("\n\nNouvelle coordonnée à : "+this.getX() + " " + this.getY());
}else if(rep == 8){
System.out.println("==== ENREVOIR ====");
System.exit(-1);
}else{}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private int x;
private int y;
private int life;
private int level;
private int secretSetting;
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
} |
Partager