I am a student working on a personal project of a virtual cardgame styled after hearthstone or mtg if you are familiar. The way it works is this: you have a "hand" of cards on the right side of the screen and you can click or drag them to 'play' them onto the board. The way i do this is implementing a mouse, mouse movement, and key listener onto a JFrame which contains a canvas that acts as the heart of the game by constantly refreshing to display the various game objects.
Here is the problem: During the Opponenet's (AI player's) turn, the mouse listener should not register the user's actions. ie you can't play cards when it isnt your turn. I do this by checking if it is the player's turn (Public Boolean) and if not, return immediately. Or at least thats what it SHOULD do, instead all the events that take place on the opponents turn are not heard by the listener until the player's turn begins once more, at which point ALL events that took place are heard at once So if you click on a card during the opponent's turn, it will play that card immediately unpon the beginning of your own turn.
Here is what the AI user's turn entails: A lot of Thread.sleep. The AI will perform some board action, then sleep the thread for about a second so that the user can follow along with what is going on (so the ai doesnt make all its attacks and plays at once and the turn is over in a split-second). I am wondering if this sleeping could be interferring with the listeners(?)
Click Method:
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(e.getX()/Board.xScale + ", " + e.getY()/Board.yScale);
if(!Board.playerHero.turn || !enabled) {return; //if its not our turn, ignore it
Card clickedCard = InputHandler.getCardAt(e.getX()/Board.xScale, e.getY()/Board.yScale);
if(clickedCard != null && clickedCard.isTargeted == false){
clickedCard.cast(null); //cast with null param becuase there is no target
}
}
Here is my project so far on github.
Here is the relevant InputHandler.Class
Further information: this class's nextTurn() method is what drives the game by changing turns, triggers this hero class's onTurnStart method, which checks to see if that hero is an AI player, and if so runs the AI's takeTurn() method
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I'm currently trying to use JNI for my project, and I've already created the library using maven aswellNow I just can't find any way to load the library that is not simply executing the java program from the command line
There's a presentation on AutoValue (a terse way to define immutable objects in Java, with sensible defaults for equals, hashCode, etc): https://docs
I am trying to create a type of Graphics Editor that allows users to create graphic depictions of American Football playsTo do this, the User should be able to do the following:
I have been finding the size of a stack in java and the run time is different every timeIs there any way the run time of the method be constant? What does run time depend upon? Would it help if the stack had a constant size?