Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Replace keylistener with RNG?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm making  a 2d fighting game with sprites. All the animation is done and everything.
I used KeyListener for user input but I'd like to replace them with a bot of some kind that randomly chooses to attack in various way until opponent is dead or timer runs out.

The only moves that can be made are attack moves so I need a bot that presses one of those moves randomly.

How do I go about replacing KeyListener with a RNG that loops random attacks until round ends?
 
Rancher
Posts: 978
23
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a listener you are waiting for an event to fire, a key is pressed in a KeyListener, so basically your code path there is dead until the event fires.  You need to replace that event with a different event, probably a timer as you suggested, which takes an ActionListener.
 
Saloon Keeper
Posts: 13294
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It strongly depends on how you've set up your main application loop. How do you update your user interface? How do you update your game state?
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic