Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 690 times)
0 Members and 1 Guest are viewing this topic.
Offline 8bitooze

Senior Newbie





« Posted 2011-04-28 03: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:
1  
2  
3  
4  
5  
6  
7  
if(KeyJ == true)
{
   if(KeyA== true)
   {
      ...
   }
}

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

Sincerely,

8BitOoze

[size=3]8BitOoze[/size]
Offline ReBirth
« Reply #1 - Posted 2011-04-28 05: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 06: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 Member


Medals: 5



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

in your class add

1  
StringBuffer keyboardString = new StringBuffer();


in keyPressed add

1  
2  
3  
4  
5  
6  
keyboardString.append(kEvt.getKeyChar());

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (32 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!