Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  Code for a tamagotchi in javascript  (Read 3562 times)
0 Members and 1 Guest are viewing this topic.
Offline faeces1

Junior Newbie




Java games rock!


« Posted 2003-03-05 11:55:57 »

Hope you enjoy this!! Code below! Grin  ::)Just copy it into notepad and save as "monster.html". Then play!


<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Daniel Mullen (Faecesface1@yahoo.com) -->

<!-- Begin
now=new Date;
x=now.getTime() %32768;
function Random(min,max) {
x=(1103515245*x+12345) % 32768;
return Math.floor(x*(max-min+1)/32768+min);
}
var num = new Array;
num[0] = -1;
num[1] = 1;
var ctrsmit = new Array;
ctrsmit[0] = '<|x_x|>';
ctrsmit[1] = '<|!_!|>';
ctrsmit[2] = '<|"_"|>';
ctrsmit[3] = '<|#_#|>';
var i = 0, will2live = 0;
function livewill(j) {
i += j;
if (i == 0) tLiphe();
if (i < 6) stat(mood[3]);
if (oldstats == mood[3] && i >= 6) stat(mood[0]);
if (alive == true) {
barzies(i);
  }
}
var bars='';
function barzies(num) {
bars='';
for (var i=0;i!=num;i++) bars += '';
document.ctrform.will.value = bars;
}
var mood = new Array;
mood[0] = 'Happy';
mood[1] = 'Mad';
mood[2] = 'Ticked-Off';
mood[3] = 'Suicidal';
mood[4] = 'Elated';

var Stat = new Array;
Stat[0] = 'Alive';
Stat[1] = 'Monster Cleaned';
Stat[2] = 'Monster not dirty';
Stat[3] = 'In pain';
Stat[4] = 'Dead';
Stat[5] = 'Infected!';
Stat[6] = 'Disinfected!';
Stat[7] = 'Not infected';
Stat[8] = 'Drooling';
var alive = false, aniID, statID, moodID, liveID, crapID, sickID, illID, normguy = '<(^_^)>';
function gLiphe() {
normguy = '<(^_^)>';
stat('Catching...');
livewill(15);
statID = setTimeout("stat(Stat[0])",3500);
setTimeout("alive = true",3500);
Animate(false,'(-o-)');
aniID = setTimeout("Animate(false,'<(o_o)>')",2500);
aniID = setTimeout("Animate(false,'(O_o)>')",3500);
aniID = setTimeout("Animate(false,'<(o_o)>')",4300);
aniID = setTimeout("Animate(false,'<(o_O)')",4500);
aniID = setTimeout("Animate(false,'<(o_o)>')",5300);
aniID = setTimeout("Animate(false,'(O_o)>')",5500);
aniID = setTimeout("Animate(false,normguy)",6500);livewill(15);
setTimeout("independence()",6501)
}
function ID(dep) {
clearTimeout(aniID);
clearTimeout(statID);
clearTimeout(liveID);
clearTimeout(crapID);
if (dep == true) clearTimeout(independ);
}
var f, t = '          ';
function Animate(auto,ctrex) {
if (auto == false) f = ctrex;
if (auto == true) t = spacey.substring(0,Pos());
document.ctrform.ctr.value = t + ctrex + poopie();
}
var indID, independ;
function independence() {
independ = setTimeout("Animate(true,f)",400);
independ = setTimeout("Animate(true,f)",1200);
independ = setTimeout("Animate(true,f)",2000);
independ = setTimeout("Animate(true,f)",2800);
independ = setTimeout("Animate(true,f)",3600);
indID = setTimeout("independence()",4000);
}
var spacey = '                            ', k, l = 10;
function Pos() {
k = Random(0,1)
if (k == 0) {
if (t.length < 22) return l++;
else if (t.length >= 22) Pos()
}
if (k == 1) {
if (t.length > 0) return l--;
else if (t.length == 0) return l++;
  }
}
var poop = false;
function poopie() {
if (poop == true) return " <§> ";
else return '';
}
function eatpoop() {
if (poop == false) {
document.ctrform.phood.selectedIndex = 0;
stat(Stat[2]);
}
if (poop == true) {
ID(true);
eatpoopie();
  }
}
function eatpoopie() {
poop = false;
eat(false,'<§>');
aniID = setTimeout("Animate(false,'<(¯o>)>')",750);
if (sick == false) setTimeout("befect()",4000);
}
var pasto,healthy,eaty='<(¯o¯)>',eati='<(¯-¯)>',eaty2;
function eat(health,pasti) {
healthy = health;
pasto = pasti;
if (sick == true) {
eaty = '<(¡o¡)>';
eaty2 = '<(¡o)>';
eati = '<(¡-¡)>';
}
else {
eaty = '<(¯o¯)>';
eaty2 = '<(¯o)>';
eati = '<(¯-¯)>';
}
Animate(false,eati +'  '+ pasto);
aniID = setTimeout("Animate(false,eaty +'  '+ pasto)",150);
aniID = setTimeout("Animate(false,eaty +' '+ pasto)",300);
aniID = setTimeout("Animate(false,eaty + pasto)",450);
aniID = setTimeout("Animate(false,eaty2+ pasto)",600);
setTimeout("phood(healthy)",650);
}
function pheed(antipasto) {
if (antipasto == 0) eat(true,'>o<');
else if (antipasto == 1) eat(true,'ð');
else if (antipasto == 2) eatpoop();
}
function takeone() {
ID(true);
Animate(false,'<(¯=¯)>');
aniID = setTimeout("Animate(false,'<(>_<)>')",500);
aniID = setTimeout("Animate(false,'<(¯=¯)>')",1300);
aniID = setTimeout("Animate(false,'<(>_<)>')",2600);
aniID = setTimeout("Animate(false,normguy)",4800);
setTimeout("infekt()",4799);
setTimeout("poop = true",4799);
full = 0;
}
function cleancage() {
if (poop == false) stat(Stat[2]);
if (poop == true) {
poop = false;
Animate(false,normguy);
stat(Stat[1]);
clearTimeout(sickID);
ickcount = 0;
  }
}
function tLiphe() {
normguy = '<(×_×)>';
poop = false;
clearTimeout(sickID);
clearTimeout(illID);
clearTimeout(indID);
ID(true);
sick = false;
full = 0;
l = 1;
i = 0;
aniID = setTimeout("Animate(false,normguy)",1);
statID = setTimeout("stat(Stat[4])",1);
barzies(0);
bruised = 0;
poked = false;
alive = false;
}
var oldstats, ick = '';
function stat(stats) {
ick = '';
oldstats = stats;
if (sick == true) ick = '[sick] ';
document.ctrform.ctrstatus.value = ick + oldstats;
}
var j;
function smite() {
if (sick == false) normguy = '<(<¬>_<¬>)>';
ID(true);
statID = setTimeout("stat(Stat[3])",10);
aniID = setTimeout("Animate(false,ctrsmit[Random(0,1)])",10);
liveID = setTimeout("livewill(num[0])",20);
aniID = setTimeout("Animate(false,normguy)",1300);
statID = setTimeout("stat(mood[1])",1300);
}
var full = 0;
function phood(salubrious) {
if (sick == false) normguy = '<(^_^)>';
ID(true);
full++;
if (salubrious == true) livewill(num[1]);
aniID = setTimeout("Animate(false,eaty)",200);
aniID = setTimeout("Animate(false,eati)",700);
aniID = setTimeout("Animate(false,eaty)",1200);
aniID = setTimeout("Animate(false,eati)",1700);
aniID = setTimeout("Animate(false,eaty)",2200);
aniID = setTimeout("Animate(false,eati)",2700);
aniID = setTimeout("Animate(false,normguy)",3200);
if (full == 3) setTimeout("takeone()",6000);
if (full >= 3) full = 0;
}
var sick = false, ickcount = 0;
function infekt() {
ickcount++;
if (ickcount != 2) sickID = setTimeout("infekt()",30000);
if (ickcount == 2) befect();
}
function befect() {
sick = true;
setTimeout("stat(Stat[5])",500);
ickcount = 0;
besick();
normguy = '<(¡_¡)>';
}
function besick() {
livewill(num[0]);
Animate(false,normguy);
if (sick == true) illID = setTimeout("besick()",2000);
}
function dnfekt() {
if (sick == false) stat(Stat[7]);
if (sick == true) {
if (poop == false) clearTimeout(sickID);
normguy = '<(^_^)>';
eat(false,'&curren;');
sick = false;
setTimeout("stat(Stat[6])",4000);
ickcount = 0;
if (poop == true) infekt();
  }
}
function scratchyscratchy() {
normguy = '<(^_^)>';
ID(true);
statID = setTimeout("stat(Stat[8] +'(scratch scratch)')",710);
aniID = setTimeout("Animate(false,'&brvbar; p')",200);
aniID = setTimeout("Animate(false,'&brvbar; P&uml;')",800);
aniID = setTimeout("Animate(false,'&brvbar; p &uml;')",1400);
aniID = setTimeout("Animate(false,'&brvbar; P&uml;&uml;')",2000);
aniID = setTimeout("Animate(false,'&brvbar; p &uml;&uml;')",2600);
aniID = setTimeout("Animate(false,'&brvbar; P&uml;&uml;&uml;')",3400);
aniID = setTimeout("Animate(false,'&brvbar; p &uml;&uml;&uml;')",4200);
aniID = setTimeout("Animate(false,'&brvbar; P &uml;&uml;&uml;&uml;')",5000);
aniID = setTimeout("Animate(false,': P&uml;')",5600);
aniID = setTimeout("Animate(false,normguy)",6600);
statID = setTimeout("stat(mood[0])",6600);
liveID = setTimeout("livewill(num[1])",6600);
}
var bruised = 0, poked = false;
function poke() {
if (bruised >= 7) {
normguy='o_-';
aniID = setTimeout("Animate(false,'(O_-)')",1);
liveID = setTimeout("livewill(num[0])",1);
if (poked == false) statID = setTimeout("stat('You Sicko! You poked his bloody eye out!!')",10);
aniID = setTimeout("Animate(false,normguy)",300);
poked = true;
}
if (bruised < 7) {
bruised++;
normguy = '<(^_^)>'
aniID = setTimeout("Animate(false,' <(^o^)>')",1);
liveID = setTimeout("livewill(num[1])",1);
statID = setTimeout("stat('Raaaaarrrrggghh!!!')",10);
aniID = setTimeout("Animate(false,normguy)",300);
  }
}
//  End -->
</script>
</HEAD>



<BODY Bgcolor="000000">

<center>
<form name="ctrform">
<table BORDER="3" CELLSPACING="5" CELLPADDING="5" bgcolor="blue">
<tr><td><font color="blue"><br>
<table>
<tr>
<th>Life</th>
<th>Status</th>
</tr>
<tr>
<td><div align="center"><center><p><input type="text" size="20" name="will"></td>
<td align="center"><input type="text" size="25" name="ctrstatus"></td>
</tr>
<tr align="center">
<th>Monster</th>
<th>Options</th>
</tr>
<tr align="center">
<td><input type="text" name="ctr" size="30" onFocus="if (alive == true) tLiphe()"></td>
<td><div align="center"><center><p><input type="button" value="Catch a Monster"
onClick="if (alive == false) gLiphe()"></td>
</tr>
</table>
<div align="center"><center>
<table>
<tr>
<td><input type="button" value="Smack" onClick="if (alive == true) smite()"></td></tr><tr>
<td><input type="button" value="Give Bath" onClick="if (alive == true) cleancage()"></td></tr><tr>
<td><input type="button" value="Give Medicine" onClick="if (alive == true) dnfekt()"></td>
</tr>
<tr>
<td><input type="button" value="Give Food"
onClick="if (alive == true) pheed(document.ctrform.phood.selectedIndex)">
<select name="phood" size="1">
<option>Rare Candy</option>
<option>Apple</option>
</select></td>
</tr>
<tr>
<td><input type="button" value="Scratch" onClick="if (alive == true) scratchyscratchy()"></td>
</tr>
<tr>
<td><input type="button" value="Poke Monster" onClick="if (alive == true) poke()"><br></td>
</tr>
</table>
</center>
</div>
</td>
</tr>
</table>
</form>
<font color= "ffffff" face= "Comic sans ms" size= "5"><b>Instructions:</b> Catch your monster,
then look after it. If it dies, just catch another one!


<!-- Script Size:  9.71 KB -->

Offline Matzon
« League of Dukes »

JGO Knight


Medals: 13
Projects: 2


I'm gonna wring your pants!


« Reply #1 - Posted 2003-03-05 12:09:31 »

ohh my - you *do* know that Javascript isn't Java ?

JavaScript == ECMAScript != Java

Offline SpongeBob

Junior Member




Who lives in a pinnapple under the sea


« Reply #2 - Posted 2003-03-05 12:32:14 »

Its not Java but its interesting nonetheless.  Only problem I had is scratching the monster caused some garbage to appear in the monster view.

Anyone have links to a Tamagochi applet?
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline javatypo

Junior Member





« Reply #3 - Posted 2003-04-06 16:23:27 »

hehe.. being a programmer is so much fun. i might try porting this to an applet..
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (147 views)
2013-05-17 21:29:12

alaslipknot (155 views)
2013-05-16 21:24:48

gouessej (186 views)
2013-05-16 00:53:38

gouessej (180 views)
2013-05-16 00:17:58

theagentd (190 views)
2013-05-15 15:01:13

theagentd (174 views)
2013-05-15 15:00:54

StreetDoggy (218 views)
2013-05-14 15:56:26

kutucuk (242 views)
2013-05-12 17:10:36

kutucuk (240 views)
2013-05-12 15:36:09

UnluckyDevil (246 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.129 seconds with 20 queries.