Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   GGames: Container (https://forums.graalonline.com/forums/showthread.php?t=73476)

Gambet 04-14-2007 12:54 AM

GGames: Container
 
PHP Code:

//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;
   
= (screenwidth/2);
   
= (screenheight/2-100);
   
width 360;
   
height 220;
   
canclose canmaximize canminimize canresize "false";
   
text "GGames: Container -By: Gambet-";
   new 
GuiButtonCtrl("container_game_close"
    {
     
profile GuiBlueButtonProfile;
     
5;
     
194.5;
     
width 350;
     
height 20;
     
text "Close";
    }
   new 
GuiProgressCtrl("container_game_player"
    {
     
profile GuiBlueProgressProfile;
     
80;
     
50;
     
width 160;
     
height 20;
    }
   new 
GuiTextCtrl("container_game_playertext"
    {
     
profile GuiBlueTextProfile;
     
135;
     
35;
     
height 50;
     
text "Yours:";
    }
   new 
GuiProgressCtrl("container_game_AI"
    {
     
profile GuiBlueProgressProfile;
     
80;
     
110;
     
width 160;
     
height 20;
    }
   new 
GuiTextCtrl("container_game_AItext"
    {
     
profile GuiBlueTextProfile;
     
135;
     
95;
     
height 50;
     
text "Computer:";
    }
   new 
GuiTextCtrl("container_game_text"
    {
     
profile GuiBlueTextProfile;
     
105;
     
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.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.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+<= 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:





Enjoy ^^

Skyld 04-14-2007 10:42 AM

Interesting, although I feel randomstring(array); might be a bit more useful here (should avoid index stuff):
PHP Code:

 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.135;
  }
 else
  {
   
Calculate();
  }


Something like:
PHP Code:

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.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:
PHP Code:

if (this.container_on "On" "Off" == "On"

Perhaps changing it to standard true/false values and using:
PHP Code:

if (this.container_on


Gambet 04-14-2007 04:30 PM

Quote:

Originally Posted by Skyld (Post 1299850)
Interesting, although I feel randomstring(array); might be a bit more useful here (should avoid index stuff):

Something like:

PHP Code:

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.135;
  }
    else
  {
    
this.calculate();
  }



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

Quote:

Originally Posted by Skyld (Post 1299850)
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:
PHP Code:

if (this.container_on "On" "Off" == "On"

Perhaps changing it to standard true/false values and using:
PHP Code:

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.

PHP Code:

if (this.container_on)
{
 
//


or

PHP Code:

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



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


All times are GMT +2. The time now is 02:13 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.