Here it is again John
--Tom
On Feb 13, 2008 10:05 AM, DeeJay <[EMAIL PROTECTED]> wrote:
> Look in http://code.whytheluckystiff.net/list/shoes/
>
> for " A clone of a clone of robots "
>
>
>
> On 13/02/2008, John Wise <[EMAIL PROTECTED]> wrote:
> > On Feb 12, 2008 5:16 PM, Thomas Bell <[EMAIL PROTECTED]> wrote:
> > > Man this is quite cool. I love all the games that are coming out for
> shoes.
> > > --tom
> > >
> >
> > I do too, There was a "daleks" game that was listed a while back but
> > I've been unable to find it in the archives. Anybody remember. I wiped
> > my google mail thread and now wish I had not.
> >
> >
> > --
> > -john
> > --
> > Even offering three hundred bowls of food three times a day does not
> > match the spiritual merit gained in one moment of love. - Nagarjuna
> >
>
class Dalek
attr_accessor :position
def initialize
@alive = true
@position = [rand(30),rand(30)]
end
def move(doctor)
doctor.ex_terminate if [EMAIL PROTECTED]
if doctor.position[0] > @position[0]
@position[0]+=1
elsif doctor.position[0] < @position[0]
@position[0]-=1
end
if doctor.position[1] > @position[1]
@position[1]+=1
elsif doctor.position[1] < @position[1]
@position[1]-=1
end
doctor.ex_terminate if [EMAIL PROTECTED]
end
def die
@alive = false
end
def alive?
@alive
end
end
class Doctor
attr_accessor :position
attr_reader :screwdrivers, :tardis_power
def initialize(daleks)
@alive,@tardis_power = true
@tardis_power = 3
@screwdrivers = 5
random_position(daleks)
end
def move(vector)
@position = [position[0]+vector[0], position[1]+vector[1]]
end
def sonic_screwdriver(daleks)
if @screwdrivers>0
@screwdrivers-=1
daleks.reject do |dalek|
self.collides_with? dalek
end
else
ex_terminate if rand(2)==1
daleks.reject do |dalek|
self.collides_with? dalek
end
end
end
def collides_with?(dalek)
((@[EMAIL PROTECTED]) === dalek.position[0]) &&
((@[EMAIL PROTECTED]) === dalek.position[1])
end
def random_position(daleks)
@position = rand(30),rand(30)
if daleks.any?{|dalek| self.collides_with? dalek }
random_position(daleks)
end
end
def tardis(daleks)
if @tardis_power>0
random_position(daleks)
@tardis_power-=1
else
ex_terminate if rand(2)==1
random_position(daleks)
end
end
def alive?
@alive
end
def ex_terminate
@alive = false
end
end
Shoes.app :width => 600, :height => 600 do
draw = lambda do |doctor, daleks|
clear do
background "#FFF".."#DDD"
stroke "#00F"
fill "#32F".."#FEE"
rect :left => doctor.position[0]*20+2, :top => doctor.position[1]*20+2,
:width => 18, :height => 18
daleks.select{|d| d.alive?}.each do |dalek|
stroke "#F00"
fill "#F23".."#FEE"
rect :left => dalek.position[0]*20+2, :top => dalek.position[1]*20+2,
:width => 18, :height => 18
end
daleks.reject{|d| d.alive?}.each do |dalek|
stroke "#000"
fill "#B3B3B3"
rect :left => dalek.position[0]*20+2, :top => dalek.position[1]*20+2,
:width => 18, :height => 18
end
para "s: #{doctor.screwdrivers} t: #{doctor.tardis_power}\n"
end
end
game = lambda do |doctor, daleks, k|
case k
when 'q'
doctor.move [-1,-1]
when 'w'
doctor.move [0,-1]
when 'e'
doctor.move [1,-1]
when 'a'
doctor.move [-1,0]
when 'd'
doctor.move [1,0]
when 'z'
doctor.move [-1,1]
when 'x'
doctor.move [0,1]
when 'c'
doctor.move [1,1]
when 't'
doctor.tardis(daleks)
when 's'
daleks = doctor.sonic_screwdriver(daleks)
end
daleks.select{|d| d.alive?}.each do |dalek|
dalek.move(doctor) if dalek.alive?
end
daleks.map {|d|
if (daleks-[d]).any? {|dalek| dalek.position == d.position}
d.die
end
}
draw[doctor,daleks]
[doctor, daleks]
end
@number_of_daleks = 10
new_level = lambda do
daleks = ([EMAIL PROTECTED]).map{Dalek.new}
[Doctor.new(daleks), daleks]
end
@doctor, @daleks = new_level.call
[EMAIL PROTECTED], @daleks]
title "Daleks!\n"
para "Welcome to Daleks.\n",
"Defeat daleks before they ex-term-i-nate the doctor\n",
"Press s to use your sonic scredriver, and t to hop in your tardis.\n",
"Press q,w,e,a,d,z,x and c to move around.\n"
keypress do |k|
@doctor, @daleks = [EMAIL PROTECTED], @daleks, k]
unless @doctor.alive?
confirm("The doctor is dead.Try again?")||quit
@number_of_daleks=10
@doctor, @daleks = new_level.call
@doctor, @daleks = [EMAIL PROTECTED], @daleks, k]
end
unless @daleks.any?{|d|d.alive?}
alert "The timelords have won! For now..."
@number_of_daleks+=10
@doctor, @daleks = new_level.call
@doctor, @daleks = [EMAIL PROTECTED], @daleks, k]
end
end
end