gamefic 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19a80c1e4f84828c7b2bf27709fbb2c37c90100b
4
- data.tar.gz: 63e7a3a0062cb167a9b363083bf34700783240b8
3
+ metadata.gz: 20c3e34c3d13071e770eda8495d563a655dcbeb1
4
+ data.tar.gz: e426f447d23f070f3e8ba86e53869dfd1a1bbbaf
5
5
  SHA512:
6
- metadata.gz: e570aa3a5de2f2e321593e2eeb9fc239d12e30fecf2f9a235fe02fca947c084cf99c152c6f7ece6bf10dcc8bc1c9f0879aa0ddf82185b4cadd2d397d129278d1
7
- data.tar.gz: 43ea2d63958bd7570b3c955dc5b364da94c8a3cb1314e32730e0252ca9508205cd450884b1d2dda0cb756df67e97d539277f0f78379baf47c4db42a5354f6602
6
+ metadata.gz: e3021ba57098702d8432f469a5df40a69b18560cb51680bec94a5eae0dd55291432c1191faec2456554e42a53027f4a8e6439e5b7a5b509827181e34469228ca
7
+ data.tar.gz: 83877a6aef2eb5150087840fdd4f8349bf489e21b3b0516484f6a25a3d07ecadf2861ddedc6192afdad9ebfe67ba5c0713e5dc711074c410b654dba12b9fa215
@@ -1,36 +1,114 @@
1
1
  module Gamefic
2
2
 
3
+ Action.new nil, :look, Query.new(:family, Container) do |actor, thing|
4
+ passthru
5
+ if thing.closeable?
6
+ actor.tell "#{thing.longname.specify.cap_first} is #{thing.closed? ? 'closed' : 'open'}."
7
+ end
8
+ end
9
+
3
10
  Action.new nil, :look_inside, Query.new(:family, Container) do |actor, container|
4
- if container.children.length == 0
5
- actor.tell "You don't find anything."
6
- else
7
- actor.tell "#{container.longname} contains: #{container.children.join(', ')}"
8
- end
11
+ if container.closed?
12
+ actor.tell "#{container.longname.cap_first.specify} is closed."
13
+ else
14
+ if container.children.length == 0
15
+ actor.tell "You don't find anything."
16
+ else
17
+ if container.children.length == 1
18
+ actor.tell "#{container.longname.specify.cap_first} contains #{container.children[0].longname}."
19
+ else
20
+ actor.tell "#{container.longname.specify.cap_first} contains: #{container.children.join_and(', ')}."
21
+ end
22
+ end
23
+ end
9
24
  end
10
25
  Syntax.new nil, "look inside :container", :look_inside, :container
11
26
  Syntax.new nil, "search :container", :look_inside, :container
12
27
  Syntax.new nil, "look in :container", :look_inside, :container
13
28
 
14
29
  Action.new nil, :look_in_at, Query.new(:family, Container), Subquery.new(:children, Entity) do |actor, container, item|
15
- actor.tell item.description
30
+ if container.closed?
31
+ actor.tell "#{container.longname.cap_first.specify} is closed."
32
+ else
33
+ actor.tell item.description
34
+ end
16
35
  end
36
+
37
+ Action.new nil, :look_in_at, Query.new(:family, Container), Query.new(:string) do |actor, container, item|
38
+ if container.closed?
39
+ actor.tell "#{container.longname.cap_first.specify} is closed."
40
+ else
41
+ passthru
42
+ end
43
+ end
44
+
17
45
  Syntax.new nil, "look at :item in :container", :look_in_at, :container, :item
18
46
  Syntax.new nil, "look :item in :container", :look_in_at, :container, :item
19
47
 
20
- Action.new nil, :take_from, Query.new(:family, Container), Subquery.new(:children, Item) do |actor, container, item|
21
- item.parent = actor
22
- actor.tell "You take #{item.longname} from #{container.longname}."
48
+ Action.new nil, :take_from, Query.new(:family, Container), Subquery.new(:children, Portable) do |actor, container, item|
49
+ if container.closed?
50
+ actor.tell "#{container.longname.cap_first.specify} is closed."
51
+ else
52
+ item.parent = actor
53
+ actor.tell "You take #{item.longname} from #{container.longname.specify}."
54
+ end
23
55
  end
24
56
  Syntax.new nil, "take :item from :container", :take_from, :container, :item
25
57
  Syntax.new nil, "get :item from :container", :take_from, :container, :item
26
58
  Syntax.new nil, "remove :item from :container", :take_from, :container, :item
27
59
 
28
60
  Action.new nil, :drop_in, Query.new(:family, Container), Query.new(:children) do |actor, container, item|
29
- item.parent = container
30
- actor.tell "You put #{item.longname} in #{container.longname}."
61
+ if container.closed?
62
+ actor.tell "#{container.longname.cap_first.specify} is closed."
63
+ else
64
+ item.parent = container
65
+ actor.tell "You put #{item.longname} in #{container.longname}."
66
+ end
31
67
  end
32
68
  Syntax.new nil, "drop :item in :container", :drop_in, :container, :item
33
69
  Syntax.new nil, "put :item in :container", :drop_in, :container, :item
34
70
  Syntax.new nil, "place :item in :container", :drop_in, :container, :item
71
+
72
+ Action.new nil, :open, Query.new(:string) do |actor, string|
73
+ actor.tell "You don't see any \"#{string}\" here."
74
+ end
75
+
76
+ Action.new nil, :open, Query.new(:family, Entity) do |actor, thing|
77
+ actor.tell "You can't open #{thing.longname.specify}."
78
+ end
79
+
80
+ Action.new nil, :open, Query.new(:family, Container) do |actor, container|
81
+ if container.closeable?
82
+ if container.closed?
83
+ actor.tell "You open #{container.longname.specify}."
84
+ container.closed = false
85
+ else
86
+ actor.tell "It's already open."
87
+ end
88
+ else
89
+ actor.tell "You can't open #{container.longname.specify}."
90
+ end
91
+ end
92
+
93
+ Action.new nil, :close, Query.new(:string) do |actor, string|
94
+ actor.tell "You don't see any \"#{string}\" here."
95
+ end
35
96
 
97
+ Action.new nil, :close, Query.new(:family, Entity) do |actor, thing|
98
+ actor.tell "You can't close #{thing.longname.specify}."
99
+ end
100
+
101
+ Action.new nil, :close, Query.new(:family, Container) do |actor, container|
102
+ if container.closeable?
103
+ if container.closed?
104
+ actor.tell "It's already closed."
105
+ else
106
+ actor.tell "You close #{container.longname.specify}."
107
+ container.closed = true
108
+ end
109
+ else
110
+ actor.tell "You can't close #{container.longname.specify}."
111
+ end
112
+ end
113
+
36
114
  end
@@ -11,20 +11,36 @@ module Gamefic
11
11
 
12
12
  Action.new nil, :take, Query.new(:siblings, Portable) do |actor, thing|
13
13
  thing.parent = actor
14
- actor.tell "You take #{thing.longname}.", true
14
+ actor.tell "You take #{thing.longname.specify}.", true
15
15
  end
16
16
 
17
17
  Action.new nil, :take, Query.new(:siblings) do |actor, thing|
18
- actor.tell "You can't carry #{thing.longname}."
18
+ actor.tell "You can't carry #{thing.longname.specify}."
19
19
  end
20
20
 
21
- Action.new nil, :take, String do |actor, thing|
22
- actor.tell "You don't see anything called \"#{thing}\" here."
21
+ Action.new nil, :take, Query.new(:string) do |actor, thing|
22
+ containers = actor.children.that_are(Container)
23
+ containers = containers + actor.parent.children.that_are(Container)
24
+ found = false
25
+ containers.each { |container|
26
+ if container.closed? == false
27
+ query = Query.new(:children, Portable)
28
+ result = query.execute(container, thing)
29
+ if result.objects.length == 1
30
+ found = true
31
+ actor.perform "take #{result.objects[0].longname} from #{container.longname}"
32
+ break
33
+ end
34
+ end
35
+ }
36
+ if found == false
37
+ actor.tell "You don't see anything called \"#{thing}\" here."
38
+ end
23
39
  end
24
40
 
25
41
  Action.new nil, :drop, Query.new(:children) do |actor, thing|
26
42
  thing.parent = actor.parent
27
- actor.tell "You drop #{thing.longname}.", true
43
+ actor.tell "You drop #{thing.longname.specify}.", true
28
44
  end
29
45
 
30
46
  Syntax.new nil, "get :thing", :take, :thing
@@ -9,7 +9,7 @@ module Gamefic
9
9
  end
10
10
 
11
11
  Action.new nil, :itemize_room, Query.new(:string) do |actor, option|
12
- actor.tell "#{actor.parent.longname.cap_first}"
12
+ actor.tell "## #{actor.parent.longname.cap_first}"
13
13
  if option == "full"
14
14
  actor.tell actor.parent.description
15
15
  end
@@ -69,6 +69,13 @@ module Gamefic
69
69
  end
70
70
  end
71
71
  end
72
+ def prompt
73
+ "> "
74
+ end
72
75
  end
73
-
76
+ class GameOverState < CharacterState
77
+ def prompt
78
+ "GAME OVER"
79
+ end
80
+ end
74
81
  end
@@ -7,12 +7,12 @@ class String
7
7
  end
8
8
  def specify
9
9
  if self[0,2] == 'a ' or self[0,3] == 'an '
10
- "the #{self.split(' ').shift.join(' ')}"
10
+ return "the #{self.split(' ')[1..-1].join(' ')}"
11
11
  end
12
12
  if self[0,2] == 'A ' or self[0,3] == 'An '
13
- "The #{self.split(' ').shift.join(' ')}"
13
+ return "The #{self.split(' ')[1..-1].join(' ')}"
14
14
  end
15
- "#{self}"
15
+ return self
16
16
  end
17
17
  def terminalize
18
18
  output = ''
@@ -31,7 +31,12 @@ module Gamefic
31
31
  }
32
32
  options.push([
33
33
  Proc.new { |actor|
34
- actor.tell "I don't know what you mean by '#{command}.'"
34
+ first = Keywords.new(command)[0]
35
+ if actor.plot.commandwords.include?(first)
36
+ actor.tell "I know the verb '#{first}' but couldn't understand the rest of your sentence."
37
+ else
38
+ actor.tell "I don't understand '#{first}' as a command."
39
+ end
35
40
  }, [actor], -1
36
41
  ])
37
42
  del = Delegate.new(options)
@@ -8,7 +8,7 @@ module Gamefic
8
8
  user = User.new @plot
9
9
  @plot.introduce user.character
10
10
  while true
11
- user.stream.select
11
+ user.stream.select user.character.state.prompt
12
12
  user.state.update
13
13
  @plot.update
14
14
  end
@@ -4,6 +4,25 @@ module Gamefic
4
4
 
5
5
  class Container < Entity
6
6
  include Itemized
7
+ def closeable=(bool)
8
+ @closeable = bool
9
+ end
10
+ def closeable?
11
+ @closeable ||= false
12
+ if (@closeable == true && @closed == nil)
13
+ @closed = false
14
+ end
15
+ @closeable
16
+ end
17
+ def closed?
18
+ (@closed == true)
19
+ end
20
+ def closed=(bool)
21
+ if bool == true
22
+ @closeable = true
23
+ end
24
+ @closed = bool
25
+ end
7
26
  end
8
27
 
9
28
  end
data/lib/gamefic/plot.rb CHANGED
@@ -69,6 +69,7 @@ module Gamefic
69
69
  def conclude(player, key = nil)
70
70
  if key != nil and @conclusions[key]
71
71
  @conclusions[key].call(player)
72
+ player.state = GameOverState.new(player)
72
73
  end
73
74
  end
74
75
  def cue scene
data/lib/gamefic/user.rb CHANGED
@@ -35,9 +35,10 @@ module Gamefic
35
35
  def send(data)
36
36
  print data
37
37
  end
38
- def select
39
- print "> "
40
- @queue.push STDIN.gets
38
+ def select(prompt)
39
+ print prompt
40
+ line = STDIN.gets
41
+ @queue.push line.strip
41
42
  end
42
43
  def recv
43
44
  @queue.shift
@@ -56,7 +57,8 @@ module Gamefic
56
57
  def update
57
58
  line = @user.stream.recv
58
59
  if line != nil
59
- @user.character.perform line
60
+ #@user.character.perform line
61
+ @user.character.queue.push line
60
62
  end
61
63
  end
62
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An adventure game engine
14
14
  email: fsnyder@gamefic.com