Jump to content

i have a few questions for this code...

SirFriendly2525
Go to solution Solved by Biohazard777,
18 hours ago, fpo said:

I won't read your source code but let's say you manually shuffle your deck. 

Come on man, you could have taken a peek at least. 😁

 

On 6/2/2023 at 11:27 PM, SirFriendly2525 said:

I have the pokemon type effectiveness already worked out but that also takes

         a lot of code. I'm not sure if I need to try and minimize the amount of code for all of that or if its fine.

1) how can i add a third and fourth person, to allow for team battles?

You are writing Java code,
you should learn more about object oriented programming.

public class PokeD 
{
    // variable declarartion
    static int again = 2;
    static int loop = 2;
    static int counter = 1;
    static int hitRoll = 0;
    // player types
    static String playerType1 = "normal";
    static String playerType2 = "normal";
    static String playerMoveType = "normal";
    // player 1 stats
    static int playerOneHP = 0;
    static String playerOneStatus = "normal";
    static int playerOneSPD = 0;
    // player 2 stats
    static int playerTwoHP = 0;
    static String playerTwoStatus = "normal";
    static int playerTwoSPD = 0;
    /** player 3 stats
    static int playerThreeHP = 0;
    static String playerThreeStatus = "normal";
    static int playerThreeSPD = 0;

Player should be a class...
Then you can instantiate as many players as you'd like, a lot faster.

 

image.png.a83a3b60dcf430692fbb3d741b3647e5.png

burnedStatus and poisnedStatus should inherit or extend something like statusEffect.

Speaking of these two, you are going about it the wrong way...

package poked;

import static poked.PokeD.playerOneHP;
import static poked.PokeD.playerTwoHP;
import java.lang.Math; 

public class burnedStatus 
{
    static float burnedDMG = (float) 0.0;
    
    static void burnedP1()
    {
        System.out.println("player 2 is burned");
        burnedDMG = playerTwoHP / 10;
        playerTwoHP = playerTwoHP - Math.round(burnedDMG);
        System.out.println("Player 2 HP is: ");
    }
    
    static void burnedP2()
    {
        System.out.println("player 1 is burned");
        burnedDMG = playerOneHP / 10;
        playerOneHP = playerOneHP - Math.round(burnedDMG);
        System.out.println("Player 1 HP is: ");
    }
}

Status effects shouldn't have players... players should have status effects.

Your logic, what goes where is wonky IMO 😀.

What the heck is this? (never mind the comments, though those are bad as well)

Spoiler
public class turnOne 
{
    static int turnLoop1 = 2;
    static int crit = 1;
    static int finalDMG = 0;
    
    static void playerOneTurn()
    {
        fireTypeMoves Fire = new fireTypeMoves(); // Ln107
        waterTypeMoves Water = new waterTypeMoves(); // Ln122
        grassTypeMoves Grass = new grassTypeMoves(); // Ln137
        electricTypeMoves Electric = new electricTypeMoves(); // Ln152
        iceTypeMoves Ice = new iceTypeMoves(); // Ln167
        fightingTypeMoves Fighting = new fightingTypeMoves(); // Ln182
        poisonTypeMoves Poison = new poisonTypeMoves(); // Ln197
        groundTypeMoves Ground = new groundTypeMoves(); // Ln212
        flyingTypeMoves Flying = new flyingTypeMoves(); // Ln227
        psychicTypeMoves Psychic = new psychicTypeMoves(); //Ln242
        bugTypeMoves Bug = new bugTypeMoves(); // Ln257
        rockTypeMoves Rock = new rockTypeMoves(); // Ln272
        ghostTypeMoves Ghost = new ghostTypeMoves(); // Ln287
        dragonTypeMoves Dragon = new dragonTypeMoves(); // Ln302
        darkTypeMoves Dark = new darkTypeMoves(); // Ln317
        steelTypeMoves Steel = new steelTypeMoves(); //Ln332
        fairyTypeMoves Fairy = new fairyTypeMoves(); // Ln347
        DmgCalculator DmgCal = new DmgCalculator(); // Ln362
public class turnTwo 
{
    static int turnLoop2 = 2;
    static int crit = 1;
    static int finalDMG = 0;
    
    static void playerTwoTurn()
    {
        fireTypeMoves Fire = new fireTypeMoves(); // Ln107
        waterTypeMoves Water = new waterTypeMoves(); // Ln122
        grassTypeMoves Grass = new grassTypeMoves(); // Ln137
        electricTypeMoves Electric = new electricTypeMoves(); // Ln152
        iceTypeMoves Ice = new iceTypeMoves(); // Ln167
        fightingTypeMoves Fighting = new fightingTypeMoves(); // Ln182
        poisonTypeMoves Poison = new poisonTypeMoves(); // Ln197
        groundTypeMoves Ground = new groundTypeMoves(); // Ln212
        flyingTypeMoves Flying = new flyingTypeMoves(); // Ln227
        psychicTypeMoves Psychic = new psychicTypeMoves(); //Ln242
        bugTypeMoves Bug = new bugTypeMoves(); // Ln257
        rockTypeMoves Rock = new rockTypeMoves(); // Ln272
        ghostTypeMoves Ghost = new ghostTypeMoves(); // Ln287
        dragonTypeMoves Dragon = new dragonTypeMoves(); // Ln302
        darkTypeMoves Dark = new darkTypeMoves(); // Ln317
        steelTypeMoves Steel = new steelTypeMoves(); //Ln332
        fairyTypeMoves Fairy = new fairyTypeMoves(); // Ln347
        DmgCalculator DmgCal = new DmgCalculator(); // Ln362

That isn't just repeated code,
all these "moves" should be inside a super class of some sort.

 

Didn't see a proper constructor once, everything is static, all methods are static void without any arguments, excessive use of switch statements, Enums are nowhere to be seen, System.out.println...
I am gonna stop analyzing your code here.

On 6/2/2023 at 11:27 PM, SirFriendly2525 said:

So, I have been working on this program for about a year now.

In a year you should have had a lot better understanding of how OOP works.

My advice would be to scratch this project,
complete a course, then look up similar projects to yours, then start writing code again.
You can do a lot better job after that, about 3-6 months I'd say.

PS I know, I sound like a d*ck... maybe I am one, but my advice is sincere.

I have a few questions. 

 

So, I have been working on this program for about a year now.

I have it functioning (somewhat) correctly. It still has some logic errors but i can fix that. 

Anyways, it is a program to assist with battling in Pokemon 5e. it basically allow the users

to input their stats and then dice rolls to determine a winner in the same way it would in an actual pokemon game.

 

I have the pokemon type effectiveness already worked out but that also takes

         a lot of code. I'm not sure if I need to try and minimize the amount of code for all of that or if its fine. 

 

Here are my questions: 

 

1) how can i add a third and fourth person, to allow for team battles?

- this can be found in the main poked code.

    a) and along the same subject (kind of) how can I make it where each player can input their party instead of just a single pokemon?

-not sure where this should be in the code yet. 

 

2) How can I make the loop more efficient? 

-can be found in the main poked code.

    - The current loop works but does have a few logic bugs and it takes up a lot of lines. 

       I find that I have to repeat the code for each turn in order for it to avoid some logic error

 

3) I am having an issue figuring out how to make status conditions ( such as burned) work properly. 

-I have some classes made for burned and poisoned, but I'm not sure how to get them functioning properly. 

    any advice on that would be appreciated. 

 

here is the link to my GitHub that I created to try and get help with this. https://github.com/SirFriendly2525/Poke-D/tree/main

 

Thank you for any advice and assistance. 

 

Link to comment
Share on other sites

Link to post
Share on other sites

For team battles you would either have to design for the ability to do that from the beginning, hack it in with spaghetti code, or make another mode in addition to regular mode. 

 

Assuming your regular 1vs1 cannot just add more people. 

 

For making your loop more efficient you can

1. Figure out how to call code the least number of times. 

2. Do the least number of loops. (one of the best ways to improve performance.)

3. Use multi threading. IE figure out what tasks you can have done on the side without interfering. 

 

I won't read your source code but let's say you manually shuffle your deck. 

Player 1 has 100 cards and player 2 has 100 cards. 

 

To multi thread this, you can make a thread to just shuffle player 1 cards. Then the main thread shuffles player 2 cards. So you're using 2 CPU cores so it's like handing a deck to a friend to shuffle while you shuffle the other deck. 

 

Look into problems with multi threading and how to avoid them. There's a few to worry about. 

 

For your status effects, the easiest way I can think of is to add a boolean for every effect. 

This can be time consuming...

You can also make an interface (not a class) called effect, and then inherit from this effect like burned, sleep, poison, etc. 

Then you can have a data structure on every card tracking all the effects. 

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, fpo said:

I won't read your source code but let's say you manually shuffle your deck. 

Come on man, you could have taken a peek at least. 😁

 

On 6/2/2023 at 11:27 PM, SirFriendly2525 said:

I have the pokemon type effectiveness already worked out but that also takes

         a lot of code. I'm not sure if I need to try and minimize the amount of code for all of that or if its fine.

1) how can i add a third and fourth person, to allow for team battles?

You are writing Java code,
you should learn more about object oriented programming.

public class PokeD 
{
    // variable declarartion
    static int again = 2;
    static int loop = 2;
    static int counter = 1;
    static int hitRoll = 0;
    // player types
    static String playerType1 = "normal";
    static String playerType2 = "normal";
    static String playerMoveType = "normal";
    // player 1 stats
    static int playerOneHP = 0;
    static String playerOneStatus = "normal";
    static int playerOneSPD = 0;
    // player 2 stats
    static int playerTwoHP = 0;
    static String playerTwoStatus = "normal";
    static int playerTwoSPD = 0;
    /** player 3 stats
    static int playerThreeHP = 0;
    static String playerThreeStatus = "normal";
    static int playerThreeSPD = 0;

Player should be a class...
Then you can instantiate as many players as you'd like, a lot faster.

 

image.png.a83a3b60dcf430692fbb3d741b3647e5.png

burnedStatus and poisnedStatus should inherit or extend something like statusEffect.

Speaking of these two, you are going about it the wrong way...

package poked;

import static poked.PokeD.playerOneHP;
import static poked.PokeD.playerTwoHP;
import java.lang.Math; 

public class burnedStatus 
{
    static float burnedDMG = (float) 0.0;
    
    static void burnedP1()
    {
        System.out.println("player 2 is burned");
        burnedDMG = playerTwoHP / 10;
        playerTwoHP = playerTwoHP - Math.round(burnedDMG);
        System.out.println("Player 2 HP is: ");
    }
    
    static void burnedP2()
    {
        System.out.println("player 1 is burned");
        burnedDMG = playerOneHP / 10;
        playerOneHP = playerOneHP - Math.round(burnedDMG);
        System.out.println("Player 1 HP is: ");
    }
}

Status effects shouldn't have players... players should have status effects.

Your logic, what goes where is wonky IMO 😀.

What the heck is this? (never mind the comments, though those are bad as well)

Spoiler
public class turnOne 
{
    static int turnLoop1 = 2;
    static int crit = 1;
    static int finalDMG = 0;
    
    static void playerOneTurn()
    {
        fireTypeMoves Fire = new fireTypeMoves(); // Ln107
        waterTypeMoves Water = new waterTypeMoves(); // Ln122
        grassTypeMoves Grass = new grassTypeMoves(); // Ln137
        electricTypeMoves Electric = new electricTypeMoves(); // Ln152
        iceTypeMoves Ice = new iceTypeMoves(); // Ln167
        fightingTypeMoves Fighting = new fightingTypeMoves(); // Ln182
        poisonTypeMoves Poison = new poisonTypeMoves(); // Ln197
        groundTypeMoves Ground = new groundTypeMoves(); // Ln212
        flyingTypeMoves Flying = new flyingTypeMoves(); // Ln227
        psychicTypeMoves Psychic = new psychicTypeMoves(); //Ln242
        bugTypeMoves Bug = new bugTypeMoves(); // Ln257
        rockTypeMoves Rock = new rockTypeMoves(); // Ln272
        ghostTypeMoves Ghost = new ghostTypeMoves(); // Ln287
        dragonTypeMoves Dragon = new dragonTypeMoves(); // Ln302
        darkTypeMoves Dark = new darkTypeMoves(); // Ln317
        steelTypeMoves Steel = new steelTypeMoves(); //Ln332
        fairyTypeMoves Fairy = new fairyTypeMoves(); // Ln347
        DmgCalculator DmgCal = new DmgCalculator(); // Ln362
public class turnTwo 
{
    static int turnLoop2 = 2;
    static int crit = 1;
    static int finalDMG = 0;
    
    static void playerTwoTurn()
    {
        fireTypeMoves Fire = new fireTypeMoves(); // Ln107
        waterTypeMoves Water = new waterTypeMoves(); // Ln122
        grassTypeMoves Grass = new grassTypeMoves(); // Ln137
        electricTypeMoves Electric = new electricTypeMoves(); // Ln152
        iceTypeMoves Ice = new iceTypeMoves(); // Ln167
        fightingTypeMoves Fighting = new fightingTypeMoves(); // Ln182
        poisonTypeMoves Poison = new poisonTypeMoves(); // Ln197
        groundTypeMoves Ground = new groundTypeMoves(); // Ln212
        flyingTypeMoves Flying = new flyingTypeMoves(); // Ln227
        psychicTypeMoves Psychic = new psychicTypeMoves(); //Ln242
        bugTypeMoves Bug = new bugTypeMoves(); // Ln257
        rockTypeMoves Rock = new rockTypeMoves(); // Ln272
        ghostTypeMoves Ghost = new ghostTypeMoves(); // Ln287
        dragonTypeMoves Dragon = new dragonTypeMoves(); // Ln302
        darkTypeMoves Dark = new darkTypeMoves(); // Ln317
        steelTypeMoves Steel = new steelTypeMoves(); //Ln332
        fairyTypeMoves Fairy = new fairyTypeMoves(); // Ln347
        DmgCalculator DmgCal = new DmgCalculator(); // Ln362

That isn't just repeated code,
all these "moves" should be inside a super class of some sort.

 

Didn't see a proper constructor once, everything is static, all methods are static void without any arguments, excessive use of switch statements, Enums are nowhere to be seen, System.out.println...
I am gonna stop analyzing your code here.

On 6/2/2023 at 11:27 PM, SirFriendly2525 said:

So, I have been working on this program for about a year now.

In a year you should have had a lot better understanding of how OOP works.

My advice would be to scratch this project,
complete a course, then look up similar projects to yours, then start writing code again.
You can do a lot better job after that, about 3-6 months I'd say.

PS I know, I sound like a d*ck... maybe I am one, but my advice is sincere.

VGhlIHF1aWV0ZXIgeW91IGJlY29tZSwgdGhlIG1vcmUgeW91IGFyZSBhYmxlIHRvIGhlYXIu

^ not a crypto wallet

Link to comment
Share on other sites

Link to post
Share on other sites

lol. both of you, very helpful actually. despite my 4 years of college in programming and networking, I am very new to java (somehow). 

 

I know this code is a dumpster fire at best. It was thrown together as ideas and no planning and it shows... lol

 

let me get out some of my old books and take a crack at it again. I agree it needs more planning. I started this with the idea of the game we were playing just to make combat easier and less paper and pen. Each method and static void was added after I started trying to make the code easier to use while I updated it. 

A lot of the code is better then the Lua looking code it was at the beginning. 

 

On 6/3/2023 at 3:10 AM, fpo said:

For team battles you would either have to design for the ability to do that from the beginning, hack it in with spaghetti code, or make another mode in addition to regular mode. 

Thank you for all the advice. I need to plan the whole thing and write the methods and constructors prior to the main code. that way I can call methods as needed instead of repeating them. 

 

 

23 hours ago, Biohazard777 said:

I am gonna stop analyzing your code here.

you don't have to... lol i know its wonky. this has been me trying to update and correct the original pseudocode. 

Most of what your seeing is each idea being written and then trying to improve on those ideas. 

This is why it has no direction or logic.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×