PDA

View Full Version : GGames: Container


Gambet
04-14-2007, 01:54 AM
//GGames: Container
//By: Gambet

//#CLIENTSIDE
function onCreated()
{
this.alphabet = {"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z"
};
ClearVariables();
setTimer(1);
}

function onPlayerChats()
{
if (player.chat == "/container")
{
player.chat = "";
this.container_on = !this.container_on;
if (this.container_on ? "On" : "Off" == "On") //Demonstrating how you can use conditional if statements
{
Container_GameGui();
this.current_level = 1;
ClearVariables();
}
}
}

function Container_GameGui()
{
new GuiWindowCtrl("container_game_window")
{
profile = GuiBlueWindowProfile;
x = (screenwidth/2);
y = (screenheight/2-100);
width = 360;
height = 220;
canclose = canmaximize = canminimize = canresize = "false";
text = "GGames: Container -By: Gambet-";
new GuiButtonCtrl("container_game_close")
{
profile = GuiBlueButtonProfile;
x = 5;
y = 194.5;
width = 350;
height = 20;
text = "Close";
}
new GuiProgressCtrl("container_game_player")
{
profile = GuiBlueProgressProfile;
x = 80;
y = 50;
width = 160;
height = 20;
}
new GuiTextCtrl("container_game_playertext")
{
profile = GuiBlueTextProfile;
x = 135;
y = 35;
height = 50;
text = "Yours:";
}
new GuiProgressCtrl("container_game_AI")
{
profile = GuiBlueProgressProfile;
x = 80;
y = 110;
width = 160;
height = 20;
}
new GuiTextCtrl("container_game_AItext")
{
profile = GuiBlueTextProfile;
x = 135;
y = 95;
height = 50;
text = "Computer:";
}
new GuiTextCtrl("container_game_text")
{
profile = GuiBlueTextProfile;
x = 105;
y = 155;
}
}
Start();
}

function container_game_close.onAction()
{
container_game_window.destroy();
}

function Start()
{
this.timer = int(timevar2 + 6);
container_game_player.progress = container_game_AI.progress = "";
}

function onTimeOut()
{
if (this.timer > int(timevar2))
{
container_game_text.text = "Time To Start:" SPC int(this.timer - timevar2);
}
else if (this.timer == int(timevar2))
{
container_game_text.text = "";
this.container_start = true;
}
if (this.container_start == true)
{
if (this.random == "")
{
LevelText();
}
container_game_AI.progress+=this.current_level / 100; //Computer's Progress Speed
if (container_game_AI.progress == 1)
{
container_game_window.destroy();
ClearVariables();
player.chat = "You lose! Level Reached: " @ this.current_level;
}
}
setTimer(1);
}

function LevelText()
{
container_game_text.text = "Level " @ this.current_level;
container_game_text.x = 135;
sleep(2);
Calculate();
}

function Calculate()
{
this.random = int(random(0,this.alphabet.size()));
if (this.random != this.random_last)
{
this.random_last = this.random;
container_game_text.text = "Press '" @ this.alphabet[this.random] @ "'";
container_game_text.x = 135;
}
else
{
Calculate();
}
}

function onKeyPressed(keycode,key)
{
if (key == this.alphabet[this.random])
{
if (container_game_player.progress < 1)
{
container_game_player.progress+=0.05; //Player's Progress Addition Amount
Calculate();
}
else
{
container_game_text.text = "You Win!";
if (this.current_level+1 <= 9)
{
this.current_level+=1;
ClearVariables();
Start();
}
else
{
container_game_window.destroy();
ClearVariables();
player.chat = "Congratulations, you have beaten all 9 levels!";
}
}
}
}

function ClearVariables()
{
this.random_last = this.container_start = this.random = "";
}



Objective:

Fill your container before the computer fills his.


How to Play:

Create a wNPC and add the entire script shown above. After doing so, add yourself the weapon. To fire the game, say '/container'. When you do so, the game window will appear and a 5 second countdown will start. As soon as you start, you will notice a text saying "Press 'button_here'". Basically, what you need to is, press the button that the text is telling you to press. Each time you press that button, your container will increase by a certain amount. The computer gets harder and harder as you get to a higher level, so try to be quick with your fingers. There are a total of 9 levels.


Educational Purposes:

Well, besides being able to learn some GS2 from this script, this game should also teach players where certain keys are on their keyboard. Seeing as how the game asks you to press a random key, from a to z, on your keyboard, you'll have to move around your keyboard quickly if you wish to advance to the next level. The more knowledgeable you are of where certain keys fall in your keyboard, the faster the typer you'll become, and the better you'll become in this game.


Screenshot:

http://img407.imageshack.us/img407/6625/containergamescreeniega9.jpg




Enjoy ^^

Skyld
04-14-2007, 11:42 AM
Interesting, although I feel randomstring(array); might be a bit more useful here (should avoid index stuff):
function Calculate()
{
this.random = int(random(0,this.alphabet.size()));
if (this.random != this.random_last)
{
this.random_last = this.random;
container_game_text.text = "Press '" @ this.alphabet[this.random] @ "'";
container_game_text.x = 135;
}
else
{
Calculate();
}
}

Something like:
function calculate()
{
this.random = randomstring(this.alphabet);

if (this.random != this.random_last)
{
this.random_last = temp.letter;

container_game_text.text = format("Press '%s'", this.random);
container_game_text.x = 135;
}
else
{
this.calculate();
}
}
Also, while it's probably nice that you've tried to demonstrate this, it's a bit misleading and probably not that efficient either, since you are running a check twice:
if (this.container_on ? "On" : "Off" == "On")
Perhaps changing it to standard true/false values and using:
if (this.container_on)

Gambet
04-14-2007, 05:30 PM
Interesting, although I feel randomstring(array); might be a bit more useful here (should avoid index stuff):

Something like:

function calculate()
{
this.random = randomstring(this.alphabet);

if (this.random != this.random_last)
{
this.random_last = temp.letter;

container_game_text.text = format("Press '%s'", this.random);
container_game_text.x = 135;
}
else
{
this.calculate();
}
}


Ah, I didn't know about this command. Either way, is there really a major difference?


Also, while it's probably nice that you've tried to demonstrate this, it's a bit misleading and probably not that efficient either, since you are running a check twice:
if (this.container_on ? "On" : "Off" == "On")
Perhaps changing it to standard true/false values and using:
if (this.container_on)


Yeah, I know. I was just wondering the different ways of using those conditional statements and found that you can do conditional if statements with them.


if (this.container_on)
{
//
}


or


if (this.container_on == true)
{
//
}



Both would have been better alternatives, I know. :)