Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (613)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Cheat Code  (Read 858 times)
0 Members and 1 Guest are viewing this topic.
Offline 8bitooze

Senior Newbie

« Posted 2011-04-28 01:49:04 »

As most of you know i am working on my 8-bit style game and need help figuring out how to implement something. I want to implement an easter egg by having the user type in a certain word. However since i am creating a game, using a textfield would look out of place. So the person would need to enter the code while the game is running, in other words by pressing the correct keyboard letters to spell the secret code. public void keyPressed(KeyEvent e) only accepts on key at a time. I could use booleans for each key, but then it would require a lot of nested ifs not to mention it would decrease performance alot:
if(KeyJ == true)
   if(KeyA== true)

If someone could give me an elegent solution it would be greatly appreciated.



Offline ReBirth
« Reply #1 - Posted 2011-04-28 03:57:59 »

If it's a cheat then there's no need interface for it. GTA lets you type cheat but doesn't let you know about what you pressed. Array can be used for this. Let the array filled by keyCode (it's integer so easier) first and compare it to matched array to see if they have typed right.

Offline loom_weaver

JGO Coder

Medals: 17

« Reply #2 - Posted 2011-04-28 04:06:11 »

Basically keep a sliding buffer (FIFO queue) of the last X key-presses.

During each key-press event, also check this buffer and if it matches your cheat code then enable your easter egg.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Dx4

Junior Devvie

Medals: 5

« Reply #3 - Posted 2011-04-28 10:01:17 »

in your class add

StringBuffer keyboardString = new StringBuffer();

in keyPressed add


if (keyboardString.equals("yourcheat")) {
  lives = 999999999; // or whatever..
  keyboardString = new StringBuffer();

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (13 views)
2015-09-03 00:41:28

Andrew_3ds (24 views)
2015-09-01 19:08:10

afikri (16 views)
2015-08-31 09:30:22

afikri (24 views)
2015-08-31 09:30:07

afikri (12 views)
2015-08-31 09:27:24

afikri (16 views)
2015-08-31 09:26:40

Roquen (23 views)
2015-08-29 11:30:54

GamerC4 (34 views)
2015-08-22 20:38:50

GamerC4 (31 views)
2015-08-22 20:37:18

GamerC4 (37 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!