Skip to content

Commit 9f902fd

Browse files
committed
Initial commit.
1 parent f59fe46 commit 9f902fd

File tree

10 files changed

+853
-1
lines changed

10 files changed

+853
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
# lots
1+
# Legend of the Sourcerer
2+
3+
Legend of the Sourcerer is an open-source text-based adventure game written in Ruby.
4+
5+
# Credits
6+
Written by Robert W. Oliver II
7+
8+
* Email: robert@cidergrove.com
9+
* Sourcerer: https://sourcerer.io/rwoliver2
10+
* Twitter: @rwoliver2
11+
12+
# Copyright
13+
14+
Copyright (C) 2018 Sourcerer, All Rights Reserved.
15+
16+
# License
17+
18+
```
19+
This program is free software: you can redistribute it and/or modify
20+
it under the terms of the GNU General Public License as published by
21+
the Free Software Foundation, either version 3 of the License, or
22+
(at your option) any later version.
23+
24+
This program is distributed in the hope that it will be useful,
25+
but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
GNU General Public License for more details.
28+
29+
You should have received a copy of the GNU General Public License
30+
along with this program. If not, see <https://www.gnu.org/licenses/>.
31+
```

bin/lots

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative "../lib/lots.rb"

lib/character.rb

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Legend of the Sourcerer
4+
# Written by Robert W. Oliver II <robert@cidergrove.com>
5+
# Copyright (C) 2018 Sourcerer, All Rights Reserved.
6+
# Licensed under GPLv3.
7+
8+
module LOTS
9+
10+
ENEMY_KILLED = "KILLED"
11+
12+
HIT_CHANCE_MODIFIER = 5
13+
ATTACK_VALUE_MODIFIER = 1
14+
15+
class Character
16+
17+
attr_accessor :name
18+
attr_accessor :health
19+
attr_accessor :mana
20+
attr_accessor :x
21+
attr_accessor :y
22+
attr_accessor :level
23+
attr_accessor :str
24+
attr_accessor :int
25+
attr_accessor :in_combat
26+
attr_accessor :current_enemy
27+
attr_accessor :lines
28+
attr_accessor :dead
29+
30+
def initialize (args)
31+
name = args[:name]
32+
world = args[:world]
33+
@name = name
34+
@level = 1
35+
@health = 100
36+
@mana = 100
37+
@str = 5
38+
@int = 5
39+
@x = 1
40+
@y = world.get_height
41+
@in_combat = false
42+
@current_enemy = nil
43+
@lines = 0
44+
@dead = 0
45+
return "Welcome %{name}! Let's play Legend of the Sourcerer!"
46+
end
47+
48+
# Player attacks enemy
49+
def attack(args)
50+
player = self
51+
enemy = args[:enemy]
52+
53+
# Does the player even hit the enemy?
54+
# We could use a hit chance stat here, but since we don't have one,
55+
# we'll just base it off the player/enemy stength discrepency.
56+
puts player.inspect
57+
puts enemy.inspect
58+
str_diff = (player.str - enemy.str) * 2
59+
hit_chance = rand(1...100) + str_diff + HIT_CHANCE_MODIFIER
60+
61+
if (hit_chance > 50)
62+
# Determine value of the attack
63+
attack_value = rand(1...player.str) + ATTACK_VALUE_MODIFIER
64+
if attack_value > enemy.health
65+
print "You swing and " + "hit".light_yellow + " the " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damage, killing it!\n"
66+
print "You gain " + enemy.lines.to_s.light_white + " lines of code.\n"
67+
return ENEMY_KILLED
68+
else
69+
print "You swing and " + "hit".light_yellow + " the " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damage!\n"
70+
return attack_value
71+
end
72+
else
73+
print "You swing and " + "miss".light_red + " the " + enemy.name + "!\n"
74+
return 0
75+
end
76+
return true
77+
end
78+
79+
def move(args)
80+
direction = args[:direction]
81+
world = args[:world]
82+
ui = args[:ui]
83+
story = args[:story]
84+
case direction
85+
when :up
86+
if @y > 1
87+
@y -= 1
88+
else
89+
ui.out_of_bounds
90+
return false
91+
end
92+
when :down
93+
if @y < world.get_height
94+
@y += 1
95+
else
96+
ui.out_of_bounds
97+
return false
98+
end
99+
when :left
100+
if @x > 1
101+
@x -= 1
102+
else
103+
ui.out_of_bounds
104+
return false
105+
end
106+
when :right
107+
if @x < world.get_width
108+
@x += 1
109+
else
110+
ui.out_of_bounds
111+
return false
112+
end
113+
end
114+
unless world.check_area({:player => self, :ui => ui, :story => story})
115+
return false
116+
else
117+
return true
118+
end
119+
end
120+
121+
end
122+
123+
end

lib/enemy.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Legend of the Sourcerer
4+
# Written by Robert W. Oliver II <robert@cidergrove.com>
5+
# Copyright (C) 2018 Sourcerer, All Rights Reserved.
6+
# Licensed under GPLv3.
7+
#
8+
# Enemy Class
9+
#
10+
11+
module LOTS
12+
13+
ENEMY_CATALOG = [
14+
[:name => "Imp", :health => 3, :mana => 0, :str => 3, :lines => 1],
15+
[:name => "Rabid Wolf", :health => 4, :mana => 0, :str => 4, :lines => 2],
16+
[:name => "Rock Giant", :health => 7, :mana => 3, :str => 5, :lines => 5],
17+
[:name => "Toxic Toad", :health => 2, :mana => 6, :str => 1, :lines => 2],
18+
[:name => "Rabid Bear", :health => 5, :mana => 0, :str => 4, :lines => 3],
19+
[:name => "Angry Fae", :health => 3, :mana => 10, :str => 2, :lines => 5]
20+
]
21+
22+
PLAYER_DEAD = "PLAYER_DEAD"
23+
24+
class Enemy
25+
26+
attr_accessor :name
27+
attr_accessor :health
28+
attr_accessor :mana
29+
attr_accessor :str
30+
attr_accessor :int
31+
attr_accessor :lines
32+
33+
def initialize(args = nil)
34+
# Pick a random enemy
35+
selected_enemy = ENEMY_CATALOG.sample[0]
36+
@name = selected_enemy[:name]
37+
@health = selected_enemy[:health] + rand(0..3)
38+
@mana = selected_enemy[:mana] + rand(0..3)
39+
@str = selected_enemy[:str]
40+
@lines = selected_enemy[:lines]
41+
@int = rand(2..6)
42+
end
43+
44+
# Enemy attacks player
45+
def attack(args)
46+
enemy = self
47+
player = args[:player]
48+
49+
# Does the enemy even hit the player?
50+
str_diff = (enemy.str - player.str) * 2
51+
hit_chance = rand(1...100) + str_diff
52+
53+
if (hit_chance > 30)
54+
# Determine value of the attack
55+
attack_value = rand(1...player.str)
56+
print enemy.name.light_red + " hits you for " + attack_value.to_s.light_yellow + " damage!\n"
57+
if attack_value > player.health
58+
return PLAYER_DEAD
59+
else
60+
return attack_value
61+
end
62+
else
63+
print enemy.name.light_red + " misses you!\n"
64+
end
65+
return true
66+
end
67+
68+
69+
end
70+
71+
end

lib/lots.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Legend of the Sourcerer
4+
# Written by Robert W. Oliver II <robert@cidergrove.com>
5+
# Copyright (C) 2018 Sourcerer, All Rights Reserved.
6+
# Licensed under GPLv3.
7+
8+
LOTS_VERSION = "1.00"
9+
10+
begin
11+
require 'colorize'
12+
rescue LoadError
13+
puts
14+
puts "Legend of the Sourcerer requires the 'colorize' gem to run."
15+
puts
16+
puts "Installation Instructions"
17+
puts "-------------------------"
18+
puts
19+
puts "Debian/Ubuntu Linux:"
20+
puts " sudo apt install ruby-colorize"
21+
puts
22+
puts "Other Linux Distros:"
23+
puts " gem install colorize"
24+
puts
25+
puts "Windows:"
26+
puts " gem install colorize"
27+
puts
28+
puts "macOS:"
29+
puts " gem install colorize"
30+
puts
31+
puts
32+
exit
33+
end
34+
35+
# Require libraries
36+
require_relative "ui"
37+
require_relative "world"
38+
require_relative "character"
39+
require_relative "story"
40+
require_relative "enemy"
41+
42+
# Start
43+
require_relative "main"
44+

0 commit comments

Comments
 (0)