328 lines
13 KiB
C#
328 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
|
|
namespace Programmation_objet_TLESIO21.projet {
|
|
public class GameManager {
|
|
|
|
private string Path;
|
|
private List<Pokemon> pkm = new List<Pokemon>();
|
|
private List<Player> players = new List<Player>();
|
|
|
|
public GameManager() {
|
|
this.Path = "../../../csv/";
|
|
}
|
|
|
|
private static int getRandom(int max) {
|
|
Random r = new Random();
|
|
return r.Next(max);
|
|
}
|
|
|
|
private Nature GenerateNature() {
|
|
switch (getRandom(25)) {
|
|
case 0:
|
|
return Nature.BOLD;
|
|
case 1:
|
|
return Nature.QUIRKY;
|
|
case 2:
|
|
return Nature.BRAVE;
|
|
case 3:
|
|
return Nature.CALM;
|
|
case 4:
|
|
return Nature.QUIET;
|
|
case 5:
|
|
return Nature.DOCILE;
|
|
case 6:
|
|
return Nature.MILD;
|
|
case 7:
|
|
return Nature.RASH;
|
|
case 8:
|
|
return Nature.GENTLE;
|
|
case 9:
|
|
return Nature.HARDY;
|
|
case 10:
|
|
return Nature.JOLLY;
|
|
case 11:
|
|
return Nature.LAX;
|
|
case 12:
|
|
return Nature.IMPISH;
|
|
case 13:
|
|
return Nature.SASSY;
|
|
case 14:
|
|
return Nature.NAUGHTY;
|
|
case 15:
|
|
return Nature.MODEST;
|
|
case 16:
|
|
return Nature.NAIVE;
|
|
case 17:
|
|
return Nature.HASTY;
|
|
case 18:
|
|
return Nature.CAREFUL;
|
|
case 19:
|
|
return Nature.BASHFUL;
|
|
case 20:
|
|
return Nature.RELAXED;
|
|
case 21:
|
|
return Nature.ADAMANT;
|
|
case 22:
|
|
return Nature.SERIOUS;
|
|
case 23:
|
|
return Nature.LONELY;
|
|
case 24:
|
|
return Nature.TIMID;
|
|
default:
|
|
return Nature.NULL;
|
|
}
|
|
}
|
|
|
|
private Pokemon? CreatePokemon(String s) {
|
|
String[] tab = s.Split(";");
|
|
switch (tab[1]) {
|
|
case "Normal":
|
|
return new PokemonNormal(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Grass":
|
|
return new PokemonGrass(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Fire":
|
|
return new PokemonFire(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Water":
|
|
return new PokemonWater(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Electric":
|
|
return new PokemonElectric(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Flying":
|
|
return new PokemonFlying(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Bug":
|
|
return new PokemonBug(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Rock":
|
|
return new PokemonRock(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Ground":
|
|
return new PokemonGround(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Psychic":
|
|
return new PokemonPsychic(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Poison":
|
|
return new PokemonPoison(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Ghost":
|
|
return new PokemonGhost(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Dark":
|
|
return new PokemonDark(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Steel":
|
|
return new PokemonSteel(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Fighting":
|
|
return new PokemonFighting(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Ice":
|
|
return new PokemonIce(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Dragon":
|
|
return new PokemonDragon(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
case "Fairy":
|
|
return new PokemonFairy(tab[0], int.Parse(tab[2]), int.Parse(tab[3]), int.Parse(tab[5]), int.Parse(tab[4]), int.Parse(tab[6]), int.Parse(tab[7]));
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private Player createPlayer(String s) {
|
|
String[] tab = s.Split(";");
|
|
List<Pokemon> pokemons = new List<Pokemon>();
|
|
for(int i = 0; i < getRandom(30)+7; ++i) {
|
|
pokemons.Add(pkm.ElementAt(getRandom(1072)));
|
|
}
|
|
|
|
foreach (Pokemon pkm in pokemons) {
|
|
Nature n = GenerateNature();
|
|
pkm.SetNature(n);
|
|
this.ApplyNatureEffect(n, pkm);
|
|
this.ApplyPlayerEffect(tab[0], pkm);
|
|
}
|
|
|
|
return new Player(tab[0], tab[1], pokemons);
|
|
}
|
|
|
|
public void initializeGame() {
|
|
String line;
|
|
try {
|
|
//Pass the file path and file name to the StreamReader constructor
|
|
StreamReader srPkm = new StreamReader(this.Path + "Pokemon.csv");
|
|
StreamReader srPerso = new StreamReader(this.Path + "Characters.csv");
|
|
|
|
//Read the first line of text
|
|
line = srPkm.ReadLine();
|
|
//Continue to read until you reach end of file
|
|
while (line != null) {
|
|
if (line[0] == '/') {
|
|
line = srPkm.ReadLine();
|
|
}
|
|
//write the line to console window
|
|
pkm.Add(CreatePokemon(line));
|
|
//Read the next line
|
|
line = srPkm.ReadLine();
|
|
}
|
|
//close the file
|
|
srPkm.Close();
|
|
|
|
//Read the first line of text
|
|
line = srPerso.ReadLine();
|
|
//Continue to read until you reach end of file
|
|
while (line != null) {
|
|
if (line[0] == '/') {
|
|
line = srPerso.ReadLine();
|
|
}
|
|
//write the line to console window
|
|
players.Add(createPlayer(line));
|
|
//Read the next line
|
|
line = srPerso.ReadLine();
|
|
}
|
|
//close the file
|
|
srPkm.Close();
|
|
|
|
|
|
} catch (Exception e) {
|
|
Console.WriteLine("Exception: " + e.Message);
|
|
}
|
|
}
|
|
|
|
public void AlterPokemonStat(String stat, double value, Pokemon p) {
|
|
switch(stat) {
|
|
case "PV":
|
|
p.setPV((int)Math.Floor(p.getPV() * value));
|
|
break;
|
|
case "ATKPhys":
|
|
p.setATKPhys(((int)Math.Floor(p.getATKPhys() * value)));
|
|
break;
|
|
case "ATKSpe":
|
|
p.setATKSpe(((int)Math.Floor(p.getATKSpe() * value)));
|
|
break;
|
|
case "DEFPhys":
|
|
p.setDefPhys(((int)Math.Floor(p.getDEFPhys() * value)));
|
|
break;
|
|
case "DEFSpe":
|
|
p.setDefSpe(((int)Math.Floor(p.getDEFSpe() * value)));
|
|
break;
|
|
case "Speed":
|
|
p.setSpeed(((int)Math.Floor(p.getSpeed() * value)));
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
public void ApplyNatureEffect(Enum nature, Pokemon p) {
|
|
switch(nature) { //malus
|
|
case Nature.BOLD:
|
|
case Nature.CALM:
|
|
case Nature.MODEST:
|
|
case Nature.TIMID:
|
|
AlterPokemonStat("ATKPhys", 0.9, p);
|
|
break;
|
|
case Nature.MILD:
|
|
case Nature.GENTLE:
|
|
case Nature.HASTY:
|
|
case Nature.LONELY:
|
|
AlterPokemonStat("DEFPhys", 0.9, p);
|
|
break;
|
|
case Nature.JOLLY:
|
|
case Nature.IMPISH:
|
|
case Nature.CAREFUL:
|
|
case Nature.ADAMANT:
|
|
AlterPokemonStat("ATKSpe", 0.9, p);
|
|
break;
|
|
case Nature.RASH:
|
|
case Nature.LAX:
|
|
case Nature.NAUGHTY:
|
|
case Nature.NAIVE:
|
|
AlterPokemonStat("DEFSpe", 0.9, p);
|
|
break;
|
|
case Nature.BRAVE:
|
|
case Nature.QUIET:
|
|
case Nature.SASSY:
|
|
case Nature.RELAXED:
|
|
AlterPokemonStat("Speed", 0.9, p);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
switch(nature) { //bonus
|
|
case Nature.BRAVE:
|
|
case Nature.NAUGHTY:
|
|
case Nature.ADAMANT:
|
|
case Nature.LONELY:
|
|
AlterPokemonStat("ATKPhys", 1.1, p);
|
|
break;
|
|
case Nature.BOLD:
|
|
case Nature.LAX:
|
|
case Nature.IMPISH:
|
|
case Nature.RELAXED:
|
|
AlterPokemonStat("DEFPhys", 1.1, p);
|
|
break;
|
|
case Nature.QUIET:
|
|
case Nature.MILD:
|
|
case Nature.RASH:
|
|
case Nature.MODEST:
|
|
AlterPokemonStat("ATKSpe", 1.1, p);
|
|
break;
|
|
case Nature.CALM:
|
|
case Nature.GENTLE:
|
|
case Nature.SASSY:
|
|
case Nature.CAREFUL:
|
|
AlterPokemonStat("DEFSpe", 1.1, p);
|
|
break;
|
|
case Nature.JOLLY:
|
|
case Nature.NAIVE:
|
|
case Nature.HASTY:
|
|
case Nature.TIMID:
|
|
AlterPokemonStat("Speed", 1.1, p);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void ApplyPlayerEffect(String playerName, Pokemon p) {
|
|
switch(playerName) {
|
|
case "Applejack":
|
|
AlterPokemonStat("PV", 1.05, p);
|
|
break;
|
|
case "Rainbow Dash":
|
|
AlterPokemonStat("ATKPhys", 1.03, p);
|
|
break;
|
|
case "Twilight Sparkle":
|
|
AlterPokemonStat("Speed", 1.07, p);
|
|
break;
|
|
case "Pinkie Pie":
|
|
AlterPokemonStat("DEFPhys", 1.04, p);
|
|
break;
|
|
case "Fluttershy":
|
|
AlterPokemonStat("DEFPhys", 0.96, p);
|
|
break;
|
|
case "Izzy Moonbow":
|
|
AlterPokemonStat("PV", 1.05, p);
|
|
AlterPokemonStat("Speed", 0.95, p);
|
|
break;
|
|
case "Zipp Storm":
|
|
AlterPokemonStat("PV", 0.95, p);
|
|
AlterPokemonStat("Speed", 1.05, p);
|
|
break;
|
|
case "Sunny Starscout":
|
|
AlterPokemonStat("ATKSpe", 1.03, p);
|
|
break;
|
|
case "Derpy Hooves":
|
|
AlterPokemonStat("PV", 0.95, p);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public List<Pokemon> GetPokemons() {
|
|
return this.pkm;
|
|
}
|
|
|
|
public List<Player> GetPlayers() {
|
|
return this.players;
|
|
}
|
|
}
|
|
}
|