/// ---------------------------------------------------------------------------------------- /// <summary> /// Assign the costs. /// </summary> /// ---------------------------------------------------------------------------------------- private void AssignCost(Armee creas) { // Cache les valeurs de terrain possible pour aller plus vite int cCol = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.COLLINE)); int cEau = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.EAU)); int cFor = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.FORET)); int cHer = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.HERBE)); int cMar = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.MARECAGE)); int cMon = creas.getMouvementCost(new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.MONTAGNE)); TerrainDescription.TerrainCell cell = new TerrainDescription.TerrainCell(TerrainDescription.TypeTerrain.HERBE); cell.route = true; int cRou = creas.getMouvementCost(cell); for (int i = 0; i < this.Hauteur; i++) { for (int j = 0; j < this.Largeur; j++) { cell = _jeu.terrain.terrainDesc.getCellAt(j, i); int cost = Creature.MVTINFINI; if (cell.route) { cost = cRou; } else { switch (cell.type) { case TerrainDescription.TypeTerrain.COLLINE: cost = cCol; break; case TerrainDescription.TypeTerrain.EAU: cost = cEau; break; case TerrainDescription.TypeTerrain.FORET: cost = cFor; break; case TerrainDescription.TypeTerrain.HERBE: cost = cHer; break; case TerrainDescription.TypeTerrain.MARECAGE: cost = cMar; break; case TerrainDescription.TypeTerrain.MONTAGNE: cost = cMon; break; } } this._costs[j, i] = cost; } } }
// Constructeur ----------------- public Trajectoire(Jeu leJeu, Armee larmee) { _jeu = leJeu; _armee = larmee; _chemin = new List <Etape>(); // Pas de trajectoire si pas de destination if (_armee.moveTarget != null) { calculTrajectoire(); } }
/// <summary> /// Affiche l'overlay /// Appelé au sein d'un spriteBatch begin/end /// </summary> /// <param name="spriteBatch">spriteBatch du jeu</param> /// <param name="GraphicsDevice">gd du jeu</param> /// <param name="gameTime">temps du jeu</param> public override void draw(SpriteBatch spriteBatch, GraphicsDevice GraphicsDevice, GameTime gameTime) { // petite portion "update"... :( if (_jeu.selectedArmee != _groupOwner) { _groupOwner = _jeu.selectedArmee; _group.Clear(); } // vrai draw baseDraw(spriteBatch, GraphicsDevice, gameTime); // Si une armée est sélectionnée, affiche son contenu if (_jeu.selectedArmee != null) { int x = xoverlay + 16; int y = yoverlay + height - Creatures.CREATURE_SIZE - 16 * 2; for (int i = 0; i < _jeu.selectedArmee.getTaille(); i++) { Creature crea = _jeu.selectedArmee.getCreature(i); _jeu.creatures.draw(spriteBatch, GraphicsDevice, gameTime, x + _jeu.terrain.offsetCarte.X, y + _jeu.terrain.offsetCarte.Y, 0f, crea.typeCreature); if (_group.Contains(crea)) { // Marqueur de sélection spriteBatch.Draw(_jeu.pixelBlanc, new Rectangle(x + 3, y - 3, Creatures.CREATURE_SIZE - 6, 2), null, _jeu.factions.getFaction(_jeu.tourFaction).couleur, 0, Vector2.Zero, SpriteEffects.None, 0.5f); spriteBatch.Draw(_jeu.pixelBlanc, new Rectangle(x + 3, y + 3 + Creatures.CREATURE_SIZE, Creatures.CREATURE_SIZE - 6, 2), null, _jeu.factions.getFaction(_jeu.tourFaction).couleur, 0, Vector2.Zero, SpriteEffects.None, 0.5f); } x += Creatures.CREATURE_SIZE; } } // Paneau d'information sur les créatures int xpano = xoverlay + 16 + Creatures.CREATURE_SIZE * 10; int ypano = yoverlay + height - 64 - 16 * 2; spriteBatch.Draw(_jeu.pixelBlanc, new Rectangle(xpano, ypano, 369 - 56, 64), null, Color.DarkGray, 0, Vector2.Zero, SpriteEffects.None, 0.5f); // Info sur une créature if (_focusCreature != null) { spriteBatch.DrawString(_jeu.font, _focusCreature.vraiNom, new Vector2(xpano + 4, ypano + 4), Color.Black, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.49f); spriteBatch.DrawString(_jeu.font, _focusCreature.profilAsStr(), new Vector2(xpano + 4, ypano + 4 + 18), Color.Black, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.49f); spriteBatch.DrawString(_jeu.font, "Cout : " + _focusCreature.description.cout, new Vector2(xpano + 4, ypano + 4 + 18 * 2), Color.Black, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.49f); } // or restant int totalDep = _jeu.factions.getTotalDep(_jeu.tourFaction); int totalRev = _jeu.factions.getTotalRev(_jeu.tourFaction); spriteBatch.DrawString(_jeu.font, "Or disponible : " + _jeu.factions.getFaction(_jeu.tourFaction).or + " ~ Dépenses : " + totalDep + " ~ Revenus : " + totalRev, new Vector2(_xoverlay, _yoverlay + _height - 22), Color.White); }
/// ---------------------------------------------------------------------------------------- /// <summary> /// Create a new map. /// </summary> /// <param name="fullMapFile"> The map's path to load. </param> /// ---------------------------------------------------------------------------------------- public Map(Jeu leJeu, Point startPt, Point endPt, Armee creas) { // Calcul des coûts de façon optimisée _jeu = leJeu; _startPt = startPt; _endPt = endPt; _costs = new int[Largeur, Hauteur]; this.AssignCost(creas); foreach (VilleDescription vd in leJeu.villes.villeDesc) { if (vd.faction != creas.faction) { _costs[vd.positionMap.X, vd.positionMap.Y] = Creature.MVTINFINI; _costs[vd.positionMap.X + 1, vd.positionMap.Y] = Creature.MVTINFINI; _costs[vd.positionMap.X, vd.positionMap.Y + 1] = Creature.MVTINFINI; _costs[vd.positionMap.X + 1, vd.positionMap.Y + 1] = Creature.MVTINFINI; } else { // Si la ville est chez nous, toute position "dans la ville" est peu chère _costs[vd.positionMap.X, vd.positionMap.Y] = 1; _costs[vd.positionMap.X + 1, vd.positionMap.Y] = 1; _costs[vd.positionMap.X, vd.positionMap.Y + 1] = 1; _costs[vd.positionMap.X + 1, vd.positionMap.Y + 1] = 1; } } // On contourne les créatures ennemies foreach (Armee armee in leJeu.armees) { if (armee.faction != creas.faction) { _costs[armee.positionCarte.X, armee.positionCarte.Y] = Creature.MVTINFINI; } } }
/// <summary> /// Affiche l'overlay /// Appelé au sein d'un spriteBatch begin/end /// </summary> /// <param name="spriteBatch">spriteBatch du jeu</param> /// <param name="GraphicsDevice">gd du jeu</param> /// <param name="gameTime">temps du jeu</param> public override void draw(SpriteBatch spriteBatch, GraphicsDevice GraphicsDevice, GameTime gameTime) { baseDraw(spriteBatch, GraphicsDevice, gameTime); // Armées en défense for (int i = 0; i < _combat.defense.getTaille(); i++) { Creature crea = _combat.defense.getCreature(i); int x = xoverlay + Creatures.CREATURE_SIZE * (i + 1) + _jeu.terrain.offsetCarte.X; int y = yoverlay + Creatures.CREATURE_SIZE * 1 + _jeu.terrain.offsetCarte.Y; _jeu.creatures.draw(spriteBatch, GraphicsDevice, gameTime, x, y, 0.8f, crea.typeCreature); } // Armées en attaque for (int i = 0; i < _combat.attaque.getTaille(); i++) { Creature crea = _combat.attaque.getCreature(i); int x = xoverlay + Creatures.CREATURE_SIZE * (i + 1) + _jeu.terrain.offsetCarte.X; int y = yoverlay + Creatures.CREATURE_SIZE * 4 + _jeu.terrain.offsetCarte.Y; _jeu.creatures.draw(spriteBatch, GraphicsDevice, gameTime, x, y, 0.8f, crea.typeCreature); } if (_etat == Etat.AFFICHE_MORT_ATK) { spriteBatch.Draw(PanneauControle._texFintour, new Rectangle(xoverlay + Creatures.CREATURE_SIZE, yoverlay + Creatures.CREATURE_SIZE * 4, Creatures.CREATURE_SIZE, Creatures.CREATURE_SIZE), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0.7f); } else if (_etat == Etat.AFFICHE_MORT_DEF) { spriteBatch.Draw(PanneauControle._texFintour, new Rectangle(xoverlay + Creatures.CREATURE_SIZE, yoverlay + Creatures.CREATURE_SIZE * 1, Creatures.CREATURE_SIZE, Creatures.CREATURE_SIZE), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0.7f); } // Bonus en présence int bonusDefense = _combat.bonusDefense; int bonusAttaque = _combat.bonusAttaque; spriteBatch.Draw(_jeu.pixelBlanc, new Rectangle(xoverlay, yoverlay, 8, (height * bonusDefense) / (bonusDefense + bonusAttaque)), null, _jeu.factions.getFaction(_combat.defense.faction).couleur *0.5f, 0, Vector2.Zero, SpriteEffects.None, 0.6f); spriteBatch.Draw(_jeu.pixelBlanc, new Rectangle(xoverlay, yoverlay + (height * bonusDefense) / (bonusDefense + bonusAttaque), 8, (height * bonusAttaque) / (bonusDefense + bonusAttaque)), null, _jeu.factions.getFaction(_combat.attaque.faction).couleur *0.5f, 0, Vector2.Zero, SpriteEffects.None, 0.6f); // Pour simplifier, l'update se fait aussi dans le draw, à la fin _tempsmiseajour -= gameTime.ElapsedGameTime.TotalMilliseconds; if (_tempsmiseajour < 0) { _tempsmiseajour = TEMPO; switch (_etat) { case Etat.NOUVEAU_ROUND: _atkGagne = _combat.unRound(true); _etat = _atkGagne ? Etat.AFFICHE_MORT_DEF : Etat.AFFICHE_MORT_ATK; break; case Etat.AFFICHE_MORT_ATK: case Etat.AFFICHE_MORT_DEF: bool combatFini = _combat.roundSuivant(_atkGagne); _etat = Etat.NOUVEAU_ROUND; if (combatFini) { Armee perdante = _atkGagne ? _combat.defense : _combat.attaque; _jeu.removeArmee(perdante); // Si l'attaquant a perdu, on arrête, sinon on continue if (_atkGagne) { bool finCombat = !_combat.armeeSuivante(false); if (finCombat) { // Attaquant gagné _callBack(true); _jeu.popOverlay(); } } else { // Attaquant perdu _callBack(false); _jeu.popOverlay(); } } break; } } }
public PanneauControle(Jeu _jeu) : base(_jeu, Position.BAS_GAUCHE, LARGBTN * 6 + 16, 160, null, null) { // Ajout de boutons ---- Bouton boutonArmeeSuivante = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 0, yoverlay + 16, " Suivant ", _texSuivant, _jeu.isoFont); boutonArmeeSuivante.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonArmeeSuivanteClick(); } }; _controles.Add(boutonArmeeSuivante); Bouton boutonSuiteMouvement = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 1, yoverlay + 16, " Continue", _texContinuer, _jeu.isoFont); boutonSuiteMouvement.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonSuiteMouvementClick(); } }; _controles.Add(boutonSuiteMouvement); Bouton boutonDeselection = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 2, yoverlay + 16, " Déselect", _texDeselection, _jeu.isoFont); boutonDeselection.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonDeselectionClick(); } }; _controles.Add(boutonDeselection); Bouton boutonOublieArmee = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 3, yoverlay + 16, " Passer ", _texPasser, _jeu.isoFont); boutonOublieArmee.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonOublieArmeeClick(); } }; _controles.Add(boutonOublieArmee); Bouton boutonFouillerRuine = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 4, yoverlay + 16, " Fouille ", _texFouiller, _jeu.isoFont); boutonFouillerRuine.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonFouillerRuineClick(); } }; _controles.Add(boutonFouillerRuine); Bouton boutonFinTour = new Bouton(_jeu, xoverlay + 16 + LARGBTN * 5, yoverlay + 16, " Fin Tour", _texFintour, _jeu.isoFont); boutonFinTour.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonFinTourClick(); } }; _controles.Add(boutonFinTour); Bouton scinder = new Bouton(_jeu, xoverlay + 16 + Creatures.CREATURE_SIZE * 9, yoverlay + height - 64 - 16, "", _texScinder, _jeu.isoFont); scinder.click = delegate(Controle clicked, int x, int y, bool leftClick, bool rightClick, bool released) { if (released && _jeu.getTopOverlay().modalOverlay == ModalOverlay.AUCUN) { boutonScinderClick(); } }; _controles.Add(scinder); _focusCreature = null; _group = new HashSet <Creature>(); _groupOwner = null; }
// Boutons ------------------------------------------------------------------------------------------------------- private void boutonScinderClick() { if ((_jeu.selectedArmee != null) && (_jeu.selectedArmee.getTaille() != _group.Count) && (_group.Count > 0)) { // Crée une autre armée Armee nouvelle = new Armee(_jeu); // Déplace les créatures sélectionnées dedans foreach (Creature crea in _group) { _jeu.selectedArmee.removeCreature(crea); nouvelle.addCreature(crea); } // Déselectionne les armées sorites for (int i = 0; i < nouvelle.getTaille(); i++) { Creature crea = nouvelle.getCreature(i); _group.Remove(crea); } // Place la nouvelle armée à un emplacement libre à coté si il y a de la place Point?posNouvelle = nouvelle.getPositionLibre(_jeu.selectedArmee.positionCarte, true, true); // Si pas de place, annule tout ! if (posNouvelle == null) { _jeu.selectedArmee.ajouteTroupes(nouvelle); _jeu.messageInfo = "Pas de place pour placer cette armée"; } else { // Regarde si on a assez de mouvement pour aller jusqu'à la nouvelle position bool ok = true; for (int i = 0; i < nouvelle.getTaille(); i++) { Creature crea = nouvelle.getCreature(i); int mvtCost = crea.getMouvementCost(posNouvelle.Value, nouvelle); if (crea.mouvementCourant < mvtCost) { ok = false; break; } } if (!ok) { // annule tout ! _jeu.selectedArmee.ajouteTroupes(nouvelle); _jeu.messageInfo = "Plus assez de mouvement pour se séparer"; } else { // enlève le mouvement cette fois... Sinon on peut tricher avec des déplacements à coût 0 ! for (int i = 0; i < nouvelle.getTaille(); i++) { Creature crea = nouvelle.getCreature(i); int mvtCost = crea.getMouvementCost(posNouvelle.Value, nouvelle); crea.mouvementCourant -= mvtCost; } nouvelle.positionCarte = posNouvelle.Value; _jeu.addArmee(nouvelle); // change sans doute le mouvement et donc la trajectoire de l'armée sélectionnée _jeu.selectedArmee.reinitTrajectoire(); } } } }
//***************************************************************************************************************************** //***************************************************************************************************************************** /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> //***************************************************************************************************************************** //***************************************************************************************************************************** protected override void LoadContent() { jeu.graphicsDevice = GraphicsDevice; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Factions ----------------------------------------------------------- Factions fact = new Factions(jeu); jeu.factions = fact; // Création de la carte ------------------------------------------------ // Carte de test System.Drawing.Bitmap carteTest = new System.Drawing.Bitmap( System.Reflection.Assembly.GetEntryAssembly(). GetManifestResourceStream("SeigneursDeGuerre.Rsc.Cartes.Carte_Campagne1.png")); TerrainDescription td = new TerrainDescription(carteTest); Terrain t = new Terrain(jeu); t.terrainDesc = td; jeu.terrain = t; carteTest.Dispose(); // Création des villes ------------------------------------------------------- Villes v = new Villes(jeu, "Cartes.Ville_Campagne1.txt"); jeu.villes = v; // Ruines & liste d'item disponible pour la carte ---------------------------- jeu.items = new Items(jeu, "RuinesItems.items.txt"); jeu.ruines = new Ruines(jeu); // Créatures ----------------------------------------------------------------- Creatures c = new Creatures(jeu, "Creatures.CreaturesBase.txt"); jeu.creatures = c; // Armées -------------------------------------------------------------------- // Ajoute une armée pour chaque ville du type max de construction (sauf bateau) foreach (VilleDescription vil in jeu.villes.villeDesc) { int typecrea; if ((vil.typeCreatures[vil.typeCreatures.Length - 1] == Creatures.TYPE_BATEAU) && (vil.typeCreatures.Length > 1)) { typecrea = vil.typeCreatures[vil.typeCreatures.Length - 2]; } else { typecrea = vil.typeCreatures[vil.typeCreatures.Length - 1]; } Creature crea = new Creature(jeu, typecrea, vil.faction, vil.positionMap); Armee armee = new Armee(jeu); armee.addCreature(crea); jeu.addArmee(armee); } // Gestionnaires -------------------------------------------------------------- InfoCarte infoC = new InfoCarte(jeu); jeu.infoCarte = infoC; InteractionJoueur ijoueur = new InteractionJoueur(jeu); jeu.interactionJoueur = ijoueur; IAJoue iajoue = new IAJoue(jeu); jeu.IAJoue = iajoue; // Chargement des textures utilitaires de base jeu.load(Content); // Chargements complémentaires statiques PanneauControle.load(Content); // Si fichier existe, le charger if (File.Exists(this.saveFile)) { // Minimap jeu.addOverlay(new Minimap(jeu, Overlay.Position.HAUT_DROITE)); // Paneau de contrôle jeu.addOverlay(new PanneauControle(jeu)); // charge le jeu jeu.loadGame(saveFile); } else { // Choix des factions -------------------------------------------------------- jeu.addOverlay(new FactionOverlay(jeu, delegate() { // Overlays de base ---------------------------------------------------------- jeu.tourFaction = 1; // Minimap jeu.addOverlay(new Minimap(jeu, Overlay.Position.HAUT_DROITE)); // Paneau de contrôle jeu.addOverlay(new PanneauControle(jeu)); // Actions de début de tour jeu.debutTour(); })); // Personne ne joue encore jeu.tourFaction = 0; } }