IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Programme RPG


Sujet :

Langage Java

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Programme RPG
    Voici mon programme: Désolé pour la longueur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JFrame;
    import java.io.*;
    import java.util.Scanner;
     
    class Player
    {
          double LifePoints = 30000;     
          int ATKPoints = 4500;
          int MagicPoints = 100;
          int Attack = 0;
          int LevelLocation = 10;
          int LeftRightLocation;
          int UpDownLocation;
    }
    class Monster
    {
         double DeathPoints;
         int PowerLevel;
         int ForcePoints;
         int LevelLocation;
         int LeftRightLocation;
         int UpDownLocation;
         int MonsterAttack = 0;
         int PowerPoints = 0;
    }
     
    /*class Sidekick
    {
         double DeathPoints;
         int ForcePoints;
         int LevelLocation;
         int LeftRightLocation;
         int UpDownLocation;
         int MonsterAttack = 0;
         int PowerPoints = 0;
    }*/
     
    public class TheSidekickGame extends JFrame
    {
        public static int levelarea = 1;
        public static void main(String[] args)
        {
            Player Player1 = new Player();
            Monster Aera1 = new Monster(); 
            Monster Sidekick1 = new Monster();          
            Player1.LeftRightLocation = 29;
            Player1.UpDownLocation = 29;
            Aera1.LeftRightLocation = 26;
            Aera1.UpDownLocation = 29;
            Aera1.DeathPoints = 1800;
            Aera1.ForcePoints = 1300;
            Aera1.PowerLevel = 42;
            Sidekick1.DeathPoints = 3000;
            Sidekick1.ForcePoints = 300;           
            Scanner in = new Scanner(System.in);
            int i, j, a, b;
            char[][] levelx;
            char[][] Levela;
            char[] temp;
            levelx = new char[3000][3000];
            Levela = new char[3000][3000];
            String level[];
            FileInputStream fin;
            level = new String [50];
            String MoveSet;
              try
            {
                fin = new FileInputStream ("d:/School Programmation3/Niveau test.txt");
     
             for(  i = 0; i < 45; i++)
             {
               level[i] = new DataInputStream(fin).readLine() ;
     
               for (j = 0; j < 122; j++)
               {
                   levelx[i][j] = level[i].charAt(j);
               }
              }
                fin.close();
            }
     
            catch (IOException e)
            {
                System.err.println("Unable to read from file");
                System.exit(-1);
            }
     
            TheSidekickGame frame = new TheSidekickGame();
            frame.setVisible(true);
            while (levelarea < 100)
            {           
                if (levelarea == 1)
                {
                 frame.setVisible(false);                           
                     for(i = 0; i < 45; i++)
                    {
                       for (j = 0; j < 122; j++)
                       {
                            Levela[i][j] = levelx[i][j];
                       }
                     }
                }
                 if (Player1.LifePoints > 0)
                Levela[Player1.UpDownLocation][Player1.LeftRightLocation] = 'P';
                 if(Aera1.DeathPoints > 0)
                Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation] = 'A';
                if (Sidekick1.DeathPoints > 0)
                Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';
                if (levelarea == 1)
                {
                     for(i = 0; i < 45; i++)
                       {
                       for (j = 0; j < 122; j++)
                       {
                         System.out.print(Levela[i][j]);
                         }
                        System.out.println("");
                        }
     
                        System.out.println("LifePoints = " + Player1.LifePoints);               
                        System.out.println("MagicPoints =  " + Player1.MagicPoints);
                      if (Math.abs(Player1.LeftRightLocation - Aera1.LeftRightLocation) < 5 && Math.abs(Player1.UpDownLocation - Aera1.UpDownLocation) < 4 && Aera1.PowerPoints == 0)                  
                           {
                           System.out.println(" \nAera1 DeathPoints =  " + Aera1.DeathPoints);
                        System.out.println("ForcePoints =  " + Aera1.ForcePoints);
                        System.out.println("PowerLevel =  " + Aera1.PowerLevel);
                            Aera1.MonsterAttack = 1;
                           }
     
                        if(Math.abs(Player1.LeftRightLocation - Aera1.LeftRightLocation) < 2 && Math.abs(Player1.UpDownLocation - Aera1.UpDownLocation) < 2 )
                        {
                          Player1.Attack = 1;                   
                        }
                        if(Aera1.DeathPoints <= 0 && Aera1.PowerPoints == 0)
                        {
                              System.out.println("You defeated the Aera1 !");
                              Aera1.MonsterAttack = 0;
                              Player1.Attack = 0;                        
                             Aera1.PowerPoints = 1;                     
                        }
                        if(Math.abs(Sidekick1.LeftRightLocation - Aera1.LeftRightLocation) < 5 && Math.abs(Sidekick1.UpDownLocation - Aera1.UpDownLocation) < 4)
                        {
                          Sidekick1.MonsterAttack = 1; 
                        }                 
                        if (Sidekick1.PowerPoints == 0)
                           {
                           System.out.println(" \nSideckick1 DeathPoints =  " + Sidekick1.DeathPoints);
                            Sidekick1.MonsterAttack = 1;
                           }            
     
                       if(Sidekick1.DeathPoints <= 0 && Sidekick1.PowerPoints == 0)
                        {
                              System.out.println(" The Sidekick was defeated !");
                              Sidekick1.MonsterAttack = 0;                       
                             Sidekick1.PowerPoints = 1; 
                             Aera1.DeathPoints = Aera1.DeathPoints;      
                        }
     
           MoveSet = in.nextLine();
           System.out.println("You typed : " + MoveSet);
             if (Levela[Player1.UpDownLocation][Player1.LeftRightLocation  + 1] == '.' )
             {
               if (MoveSet.indexOf('r') == 0)
                {
                Player1.LeftRightLocation += 1;
                if (Player1.LifePoints > 0)
                Levela[Player1.UpDownLocation][Player1.LeftRightLocation] = 'P';
                }
              }
               if (Levela[Player1.UpDownLocation + 1][Player1.LeftRightLocation  ] == '.' )
              if (Levela[Player1.UpDownLocation][Player1.LeftRightLocation + 1] != '_' )
             {
               if (MoveSet.indexOf('d') == 0)
                {
                Player1.UpDownLocation += 1;
                  if (Player1.LifePoints > 0)
                Levela[Player1.UpDownLocation][Player1.LeftRightLocation] = 'P';
                }
              }
               if (Levela[Player1.UpDownLocation][Player1.LeftRightLocation  - 1] == '.' )
              if (Levela[Player1.UpDownLocation][Player1.LeftRightLocation - 1] != '|' )
             {
               if (MoveSet.indexOf('l') == 0)
                {
                 if (Player1.LifePoints > 0)
                Levela[Player1.UpDownLocation][Player1.LeftRightLocation] = 'P';
                Player1.LeftRightLocation -= 1;
                }
              }
               if (Levela[Player1.UpDownLocation - 1][Player1.LeftRightLocation] == '.' )
                if (Levela[Player1.UpDownLocation - 1 ][Player1.LeftRightLocation] != '_' )
               {
               if (MoveSet.indexOf('u') == 0)
                {
                Player1.UpDownLocation -= 1;
                    if (Player1.LifePoints > 0)
                Levela[Player1.UpDownLocation][Player1.LeftRightLocation] = 'P';
                }
               }
                      Player1.Attack = 0;
                    if (MoveSet.indexOf('a') == 0)
                    {
                     Player1.Attack = 1;
                    }
                  if ( Math.abs(Player1.UpDownLocation - Aera1.UpDownLocation) < 2 && Math.abs(Player1.LeftRightLocation - Aera1.LeftRightLocation) < 2 && Aera1.MonsterAttack == 1)
                {
                    Player1.LifePoints = Player1.LifePoints - Aera1.ForcePoints;
                }
     
                if  ( Math.abs(Player1.UpDownLocation - Aera1.UpDownLocation) < 2 && Math.abs(Player1.LeftRightLocation - Aera1.LeftRightLocation) < 2 && Aera1.MonsterAttack == 1 && Player1.Attack == 1)
                 {
                    Aera1.DeathPoints = Aera1.DeathPoints - Player1.ATKPoints;
                 }    
     
                  if ( Math.abs(Sidekick1.UpDownLocation - Aera1.UpDownLocation) < 2 && Math.abs(Sidekick1.LeftRightLocation - Aera1.LeftRightLocation) < 2 && Aera1.MonsterAttack == 1)
                {
                    Sidekick1.DeathPoints = Sidekick1.DeathPoints - Aera1.ForcePoints;
                }
     
                  if  ( Math.abs(Sidekick1.UpDownLocation - Aera1.UpDownLocation) < 2 && Math.abs(Sidekick1.LeftRightLocation - Aera1.LeftRightLocation) < 2 && Sidekick1.MonsterAttack == 1)
                 {
                    Aera1.DeathPoints = Aera1.DeathPoints - Sidekick1.ForcePoints;
                 }        
     
     
                 if (Player1.Attack == 1)
                    {
                  System.out.print(" Strike! ");
                    }
     
                  if(MoveSet.indexOf('f') == 0)
                {     
               if (Player1.MagicPoints <= 100)
               {
               /*       if (Sidekick1.DeathPoints > 0)
                Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';*/
     
               Sidekick1.LeftRightLocation = Player1.LeftRightLocation + 1;
            Sidekick1.UpDownLocation = Player1.UpDownLocation + 1;
     
     
     
            Player1.MagicPoints = Player1.MagicPoints - 30;                                               
               }  
     
                }        
     
                 }
     
            /*    if (Levela[Sidekick1.UpDownLocation + 1][Sidekick1.LeftRightLocation ] == '.' )
               if( Player1.UpDownLocation > Sidekick1.UpDownLocation && Sidekick1.MonsterAttack == 1)
               {
                    Sidekick1.UpDownLocation += 1;
                    if (Sidekick1.DeathPoints > 0)
                 Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';
               }
                if (Levela[Sidekick1.UpDownLocation ][Sidekick1.LeftRightLocation - 1] == '.' )
             if( Player1.LeftRightLocation < Sidekick1.LeftRightLocation && Sidekick1.MonsterAttack == 1 )
               {
                    Sidekick1.LeftRightLocation -= 1;
                     if (Sidekick1.DeathPoints > 0)
                Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';
               }
                if (Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation + 1] == '.' )
               if( Player1.LeftRightLocation > Sidekick1.LeftRightLocation && Sidekick1.MonsterAttack == 1 )
               {
                    Sidekick1.LeftRightLocation += 1;
                   if (Sidekick1.DeathPoints > 0)
                Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';
               }
                   if (Levela[Sidekick1.UpDownLocation - 1][Sidekick1.LeftRightLocation] == '.' )
                     if( Player1.UpDownLocation < Sidekick1.UpDownLocation && Sidekick1.MonsterAttack == 1 )
               {
                    Sidekick1.UpDownLocation -= 1;
                        if (Sidekick1.DeathPoints > 0)
                Levela[Sidekick1.UpDownLocation][Sidekick1.LeftRightLocation] = 'S';
               }         */     
     
     
     
                if (Levela[Aera1.UpDownLocation + 1][Aera1.LeftRightLocation ] == '.' )
               if( Player1.UpDownLocation > Aera1.UpDownLocation && Aera1.MonsterAttack == 1)
               {
                    Aera1.UpDownLocation += 1;
                    if (Aera1.DeathPoints > 0)
                 Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation] = 'A';
               }
                if (Levela[Aera1.UpDownLocation ][Aera1.LeftRightLocation - 1] == '.' )
             if( Player1.LeftRightLocation < Aera1.LeftRightLocation && Aera1.MonsterAttack == 1 )
               {
                    Aera1.LeftRightLocation -= 1;
                     if (Aera1.DeathPoints > 0)
                Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation] = 'A';
               }
                if (Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation + 1] == '.' )
               if( Player1.LeftRightLocation > Aera1.LeftRightLocation && Aera1.MonsterAttack == 1 )
               {
                    Aera1.LeftRightLocation += 1;
                   if (Aera1.DeathPoints > 0)
                Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation] = 'A';
               }
                   if (Levela[Aera1.UpDownLocation - 1][Aera1.LeftRightLocation] == '.' )
                     if( Player1.UpDownLocation < Aera1.UpDownLocation && Aera1.MonsterAttack == 1 )
               {
                    Aera1.UpDownLocation -= 1;
                        if (Aera1.DeathPoints > 0)
                Levela[Aera1.UpDownLocation][Aera1.LeftRightLocation] = 'A';
               }                        
              }
        }      
    }
    dans les pièces jointes il y a le niveau test. Voici le probleme:

    Je cherche a créer un sidekick dans ce que vous avez comme slice de mon RPG, mais le problème est que je n'arrive pas à faire en sorte que ses PV s'affichent QUE quand je l'invoque avec la touche f et qu'ils restent constamment. J'avais programmé pour qu'il me suive et attaque l'ennemi, et si l'on réactive les mouvements il le fera, mais après le montre ennemi représenté par aera, perdra de la vie jusqu’à mourir alors que ça ne devrait pas être le cas. De plus je ne comprends pas quand les points magiques se sont vidés et que je rappuie sur la touche correspondante, les points magiques, au lieu d'être à zéro et d'empêcher que la magie fonctionne, fait le contraire et rend des -30, etc. Est-ce que quelqu'un peut m'aider ?
    Fichiers attachés Fichiers attachés

  2. #2
    Membre chevronné
    Avatar de professeur shadoko
    Homme Profil pro
    retraité nostalgique Java SE
    Inscrit en
    Juillet 2006
    Messages
    1 257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : retraité nostalgique Java SE

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 257
    Points : 1 855
    Points
    1 855
    Par défaut
    tu pars du principe que tout le monde sait ce que tu entends par "RPG" ...
    pour moi "RPG" = langage de programmation
    -> déception
    donc pour poser une question sort de ton monde et explique précisément le contexte de ta question ..... (désolé mais je suis un "vieux" donc RPG tel que tu en parles ne me dit rien : "sidekick", "slice" ,etc... c'est du chinois)
    J'ai des principes: je peux toujours trouver une bonne raison pour les contredire .... mais j'ai des principes!
    (mon excellent bouquin sur Java : https://eska-publishing.com/fr/livre...822407076.html)

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Mr Shadoko:

    RPG: Role Playing Game : Jeu De rôle
    Sidekick: Assistant / partenaire
    Slice : Partie de qu'ch. Dans ce contexte, ça voulait dire un extrait du jeu.
    PV: Points de vie

    Le reste je l'ai expliqué dans la question. J'espère que je suis suffisamment sorti de mon "monde" ou n'ais-je pas été suffisamment explicite ?

  4. #4
    Rédacteur/Modérateur
    Avatar de Logan Mauzaize
    Homme Profil pro
    Architecte technique
    Inscrit en
    Août 2005
    Messages
    2 894
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : Transports

    Informations forums :
    Inscription : Août 2005
    Messages : 2 894
    Points : 7 083
    Points
    7 083
    Par défaut
    Sans vouloir t'offenser ton exemple est difficilement lisible :
    • trop long
    • du code mort (ex: code en commentaire)
    • mal indenté
    • mal conçu (trop d'imbrications, peu ou pas de sémantique, peu de structure, etc.)

    Essayes d'aller à l'essentiel.

    Ton discours est également un peu brouillon. Tu commences par parler de l'affichage des PVs (en mode bascule via la touche 'F), puis tu enchaînes avec le comportement du partenaire et ensuite viennent les points de magie.

    Je te conseille réellement deux techniques d'analyses :
    • Réduction du problème. On prend le minimum de structures, d'entrées, d'algorithme et de sorties relatifs au problème. En général, rien que cette étape permet d'éliminer pas mal de problèmes en chemin.
    • Procéder par étape. Traiter un seul problème à la fois pour éviter que les effets de bord de résolution d'une partie d'un des problèmes ne viennent perturber le comportement liés aux autres problèmes.
    Java : Cours et tutoriels - FAQ - Java SE 8 API - Programmation concurrente
    Ceylon : Installation - Concepts de base - Typage - Appels et arguments

    ECM = Exemple(reproduit le problème) Complet (code compilable) Minimal (ne postez pas votre application !)
    Une solution vous convient ? N'oubliez pas le tag
    Signature par pitipoisson

  5. #5
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 316
    Points
    8 316
    Billets dans le blog
    52
    Par défaut
    J'approuve le commentaire de Logan Mauzaize.

    Il est important que tu réalise des développements et des débogage par "baby step".

    Quand on lit le poste on à l'impression que tu as codé l'ensemble des fonctions du sidekick en une seule fois. Ce qui visiblement n'est pas une bonne idée.
    Peut-être faudrait-il reprendre de la base et s'assurer que chaque étape fonctionne avant de passer à la suivante.


    Remarque au niveau du code :
    - camelCase pour les variables.
    - Pense à faire des sous-fonctions (Cela peut-être utile pour rendre le code plus lisible.)

    Exemple pour le code de la gestion de l'attaque du joueur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if (MoveSet.indexOf('a') == 0) {
    	Player1.Attack = 1;
    }
    if (Player1.Attack == 1) {
    	System.out.print(" Strike! ");
    }
    En plus lisible :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    if(isPlayerAttack(MoveSet) {
    	playerAttack();
    }
    // Avec les fonctions suivante :
    private boolean isPlayerAttack(String MoveSet){
    	return MoveSet.indexOf('a') == 0;
    }
    private void playerAttack() {
    	Player1.Attack = 1;
    	System.out.print(" Strike! ");
    }
    Cordialement,
    Patrick Kolodziejczyk.

    PS : un code qui fonctionne, c'est un code simple.
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

Discussions similaires

  1. Executer un programme RPG depuis une classe JAVA
    Par AnneCa dans le forum JDBC
    Réponses: 3
    Dernier message: 18/02/2018, 12h14
  2. Réponses: 2
    Dernier message: 24/02/2012, 16h01
  3. Ecrans type Web Html sur programmes RPG
    Par laurentb91 dans le forum AS/400
    Réponses: 1
    Dernier message: 31/08/2010, 17h44
  4. Utilisation SQL dans un programme RPG
    Par R4ndy dans le forum AS/400
    Réponses: 29
    Dernier message: 15/09/2008, 00h59
  5. base de programmation RPG 400
    Par dodyx dans le forum DB2
    Réponses: 1
    Dernier message: 01/09/2007, 19h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo