mission_game 1.1.1 → 1.1.2

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.
Files changed (9) hide show
  1. checksums.yaml +4 -4
  2. data/lib/enemy.rb +49 -53
  3. data/lib/main.rb +148 -142
  4. data/lib/neworleans.rb +144 -149
  5. data/lib/player.rb +122 -121
  6. data/lib/story.rb +41 -45
  7. data/lib/ui.rb +269 -259
  8. data/mission_game.rb +41 -43
  9. metadata +1 -1
data/lib/neworleans.rb CHANGED
@@ -1,149 +1,144 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Written by Webster Avosa
4
-
5
- module MISSIONGAME
6
-
7
- MAP_WIDTH = 64
8
- MAP_HEIGHT = 14
9
-
10
- MAP_KEY_TREE = "\u2663"
11
- MAP_KEY_WATER = "\u2248"
12
- MAP_KEY_GRASS = "\u2588"
13
- MAP_KEY_MOUNTAIN = "\u25B2"
14
- MAP_KEY_ENEMY = "\u263A"
15
- MAP_KEY_WITCH = "\u263B"
16
- MAP_KEY_PLAYER = "\u1330"
17
-
18
- # Weighted
19
- MAP_POSSIBLE_KEYS = [
20
- MAP_KEY_TREE,
21
- MAP_KEY_TREE,
22
- MAP_KEY_TREE,
23
- MAP_KEY_TREE,
24
- MAP_KEY_WATER,
25
- MAP_KEY_GRASS,
26
- MAP_KEY_MOUNTAIN,
27
- MAP_KEY_ENEMY,
28
- MAP_KEY_ENEMY
29
- ]
30
-
31
- # Make grass more common
32
- 32.times.each do
33
- MAP_POSSIBLE_KEYS << MAP_KEY_GRASS
34
- end
35
-
36
- MAP_WITCH_X = MAP_WIDTH
37
- MAP_WITCH_Y = 1
38
-
39
- class NewOrleans
40
-
41
- attr_reader :the_map
42
-
43
- def initialize
44
- # Set initial New Orleans map
45
- generate_map
46
- end
47
-
48
- def get_width
49
- MAP_WIDTH
50
- end
51
-
52
- def get_height
53
- MAP_HEIGHT
54
- end
55
-
56
- # Return map data in a display format
57
- def get_map(args)
58
- player = args[:player]
59
- buffer = Array.new
60
- x = 1
61
- y = 1
62
- @the_map.each do |row|
63
- tmp_row = Array.new
64
- x = 1
65
- row.each do |col|
66
- placed = 0
67
- # Place WITCH
68
- if x == MAP_WITCH_X and y == MAP_WITCH_Y
69
- tmp_row << MAP_KEY_WITCH.colorize(:color => :white, :background => :red)
70
- placed = 1
71
- end
72
- # If player is here, display them
73
- if x == player.x and y == player.y
74
- tmp_row << MAP_KEY_PLAYER.colorize(:color => :red, :background => :white)
75
- placed = 1
76
- end
77
- # If we haven't already placed the Player, run through the rest of the options
78
- if placed == 0
79
- case col
80
- when MAP_KEY_TREE
81
- tmp_row << col.colorize(:color => :light_green, :background => :green)
82
- when MAP_KEY_GRASS
83
- tmp_row << col.colorize(:color => :green, :background => :green)
84
- when MAP_KEY_WATER
85
- tmp_row << col.colorize(:color => :white, :background => :blue)
86
- when MAP_KEY_MOUNTAIN
87
- tmp_row << col.colorize(:color => :yellow, :background => :green)
88
- when MAP_KEY_ENEMY
89
- tmp_row << col.colorize(:color => :red, :background => :green)
90
- end
91
- end
92
- x += 1
93
- end
94
- buffer << tmp_row
95
- y += 1
96
- end
97
-
98
- return buffer
99
- end
100
-
101
- # Check the current area on the map and describe it
102
- def check_area(args)
103
- player = args[:player]
104
- ui = args[:ui]
105
- story = args[:story]
106
- x = player.x
107
- y = player.y
108
- current_area = @the_map[y-1][x-1]
109
- case current_area
110
- when MAP_KEY_TREE
111
- ui.draw_frame({:text => story.area_tree})
112
- when MAP_KEY_WATER
113
- ui.draw_frame({:text => story.area_water})
114
- when MAP_KEY_MOUNTAIN
115
- ui.draw_frame({:text => story.area_mountain})
116
- when MAP_KEY_ENEMY
117
- ui.draw_frame({:text => story.area_enemy})
118
- return false
119
- end
120
- return true
121
- end
122
-
123
- private
124
-
125
- def new_line
126
- print "\n"
127
- end
128
-
129
- # Create a random new orleans map
130
- def generate_map
131
- tmp_map = Array.new
132
-
133
- # Step through MAX_HEIGHT times
134
- MAP_HEIGHT.times do
135
- tmp_row = Array.new
136
- MAP_WIDTH.times do
137
- tmp_row << MAP_POSSIBLE_KEYS.sample
138
- end
139
-
140
- # Add our assembled row to the map
141
- tmp_map << tmp_row
142
- tmp_row = nil
143
- end
144
- @the_map = tmp_map
145
-
146
- end
147
-
148
- end
149
- end
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Written by Webster Avosa
4
+
5
+ module MISSIONGAME
6
+ MAP_WIDTH = 64
7
+ MAP_HEIGHT = 14
8
+
9
+ MAP_KEY_TREE = "\u2663"
10
+ MAP_KEY_WATER = "\u2248"
11
+ MAP_KEY_GRASS = "\u2588"
12
+ MAP_KEY_MOUNTAIN = "\u25B2"
13
+ MAP_KEY_ENEMY = "\u263A"
14
+ MAP_KEY_WITCH = "\u263B"
15
+ MAP_KEY_PLAYER = "\u1330"
16
+
17
+ # Weighted
18
+ MAP_POSSIBLE_KEYS = [
19
+ MAP_KEY_TREE,
20
+ MAP_KEY_TREE,
21
+ MAP_KEY_TREE,
22
+ MAP_KEY_TREE,
23
+ MAP_KEY_WATER,
24
+ MAP_KEY_GRASS,
25
+ MAP_KEY_MOUNTAIN,
26
+ MAP_KEY_ENEMY,
27
+ MAP_KEY_ENEMY
28
+ ]
29
+
30
+ # Make grass more common
31
+ 32.times.each { MAP_POSSIBLE_KEYS << MAP_KEY_GRASS }
32
+
33
+ MAP_WITCH_X = MAP_WIDTH
34
+ MAP_WITCH_Y = 1
35
+
36
+ class NewOrleans
37
+ attr_reader :the_map
38
+
39
+ def initialize
40
+ # Set initial New Orleans map
41
+ generate_map
42
+ end
43
+
44
+ def get_width
45
+ MAP_WIDTH
46
+ end
47
+
48
+ def get_height
49
+ MAP_HEIGHT
50
+ end
51
+
52
+ # Return map data in a display format
53
+ def get_map(args)
54
+ player = args[:player]
55
+ buffer = Array.new
56
+ x = 1
57
+ y = 1
58
+ @the_map.each do |row|
59
+ tmp_row = Array.new
60
+ x = 1
61
+ row.each do |col|
62
+ placed = 0
63
+
64
+ # Place WITCH
65
+ if x == MAP_WITCH_X and y == MAP_WITCH_Y
66
+ tmp_row << MAP_KEY_WITCH.colorize(color: :white, background: :red)
67
+ placed = 1
68
+ end
69
+
70
+ # If player is here, display them
71
+ if x == player.x and y == player.y
72
+ tmp_row << MAP_KEY_PLAYER.colorize(color: :red, background: :white)
73
+ placed = 1
74
+ end
75
+
76
+ # If we haven't already placed the Player, run through the rest of the options
77
+ if placed == 0
78
+ case col
79
+ when MAP_KEY_TREE
80
+ tmp_row << col.colorize(color: :light_green, background: :green)
81
+ when MAP_KEY_GRASS
82
+ tmp_row << col.colorize(color: :green, background: :green)
83
+ when MAP_KEY_WATER
84
+ tmp_row << col.colorize(color: :white, background: :blue)
85
+ when MAP_KEY_MOUNTAIN
86
+ tmp_row << col.colorize(color: :yellow, background: :green)
87
+ when MAP_KEY_ENEMY
88
+ tmp_row << col.colorize(color: :red, background: :green)
89
+ end
90
+ end
91
+ x += 1
92
+ end
93
+ buffer << tmp_row
94
+ y += 1
95
+ end
96
+
97
+ return buffer
98
+ end
99
+
100
+ # Check the current area on the map and describe it
101
+ def check_area(args)
102
+ player = args[:player]
103
+ ui = args[:ui]
104
+ story = args[:story]
105
+ x = player.x
106
+ y = player.y
107
+ current_area = @the_map[y - 1][x - 1]
108
+ case current_area
109
+ when MAP_KEY_TREE
110
+ ui.draw_frame({ text: story.area_tree })
111
+ when MAP_KEY_WATER
112
+ ui.draw_frame({ text: story.area_water })
113
+ when MAP_KEY_MOUNTAIN
114
+ ui.draw_frame({ text: story.area_mountain })
115
+ when MAP_KEY_ENEMY
116
+ ui.draw_frame({ text: story.area_enemy })
117
+ return false
118
+ end
119
+ return true
120
+ end
121
+
122
+ private
123
+
124
+ def new_line
125
+ print "\n"
126
+ end
127
+
128
+ # Create a random new orleans map
129
+ def generate_map
130
+ tmp_map = Array.new
131
+
132
+ # Step through MAX_HEIGHT times
133
+ MAP_HEIGHT.times do
134
+ tmp_row = Array.new
135
+ MAP_WIDTH.times { tmp_row << MAP_POSSIBLE_KEYS.sample }
136
+
137
+ # Add our assembled row to the map
138
+ tmp_map << tmp_row
139
+ tmp_row = nil
140
+ end
141
+ @the_map = tmp_map
142
+ end
143
+ end
144
+ end
data/lib/player.rb CHANGED
@@ -1,121 +1,122 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Written by Webster Avosa
4
-
5
- module MISSIONGAME
6
-
7
- ENEMY_KILLED = "KILLED"
8
-
9
- HIT_CHANCE_MODIFIER = 5
10
- ATTACK_VALUE_MODIFIER = 1
11
-
12
- class Player
13
-
14
- attr_accessor :name
15
- attr_accessor :lives
16
- attr_accessor :bonus
17
- attr_accessor :x
18
- attr_accessor :y
19
- attr_accessor :level
20
- attr_accessor :str
21
- attr_accessor :int
22
- attr_accessor :in_combat
23
- attr_accessor :current_enemy
24
- attr_accessor :points
25
- attr_accessor :dead
26
-
27
- def initialize (args)
28
- name = args[:name]
29
- neworleans = args[:neworleans]
30
- @name = name
31
- @level = 1
32
- @lives = 100
33
- @bonus = 100
34
- @str = 5
35
- @int = 5
36
- @x = 1
37
- @y = neworleans.get_height
38
- @in_combat = false
39
- @current_enemy = nil
40
- @points = 0
41
- @dead = 0
42
- return "Welcome %{name}! Let's play!"
43
- end
44
-
45
- # Player attacks enemy
46
- def attack(args)
47
- player = self
48
- enemy = args[:enemy]
49
- ui = args[:ui]
50
-
51
- # Does the player even hit the enemy?
52
- # We could use a hit chance stat here, but since we don't have one,
53
- # we'll just base it off the player/enemy stength discrepency.
54
- ui.enemy_info({:player => player})
55
- ui.player_info({:player => player})
56
- str_diff = (player.str - enemy.str) * 2
57
- hit_chance = rand(1...100) + str_diff + HIT_CHANCE_MODIFIER
58
-
59
- if (hit_chance > 50)
60
- # Determine value of the attack
61
- attack_value = rand(1...player.str) + ATTACK_VALUE_MODIFIER
62
- if attack_value > enemy.lives
63
- print "You fought for your life and " + "hit".light_yellow + " " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damages, killing him!\n"
64
- print "You gain " + enemy.points.to_s.light_white + " points.\n"
65
- return ENEMY_KILLED
66
- else
67
- print "You fought for your life and " + "hit".light_yellow + " " + enemy.name.light_red + " for " + attack_value.to_s.light_white + " damages, killing him!\n"
68
- return attack_value
69
- end
70
- else
71
- print "You fought for your life and " + "missed".light_red + " " + enemy.name + "!\n"
72
- return 0
73
- end
74
- return true
75
- end
76
-
77
- def move(args)
78
- direction = args[:direction]
79
- neworleans = args[:neworleans]
80
- ui = args[:ui]
81
- story = args[:story]
82
- case direction
83
- when :up
84
- if @y > 1
85
- @y -= 1
86
- else
87
- ui.out_of_bounds
88
- return false
89
- end
90
- when :down
91
- if @y < neworleans.get_height
92
- @y += 1
93
- else
94
- ui.out_of_bounds
95
- return false
96
- end
97
- when :left
98
- if @x > 1
99
- @x -= 1
100
- else
101
- ui.out_of_bounds
102
- return false
103
- end
104
- when :right
105
- if @x < neworleans.get_width
106
- @x += 1
107
- else
108
- ui.out_of_bounds
109
- return false
110
- end
111
- end
112
- unless neworleans.check_area({:player => self, :ui => ui, :story => story})
113
- return false
114
- else
115
- return true
116
- end
117
- end
118
-
119
- end
120
-
121
- end
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Written by Webster Avosa
4
+
5
+ module MISSIONGAME
6
+ ENEMY_KILLED = 'KILLED'
7
+
8
+ HIT_CHANCE_MODIFIER = 5
9
+ ATTACK_VALUE_MODIFIER = 1
10
+
11
+ class Player
12
+ attr_accessor :name
13
+ attr_accessor :lives
14
+ attr_accessor :bonus
15
+ attr_accessor :x
16
+ attr_accessor :y
17
+ attr_accessor :level
18
+ attr_accessor :str
19
+ attr_accessor :int
20
+ attr_accessor :in_combat
21
+ attr_accessor :current_enemy
22
+ attr_accessor :points
23
+ attr_accessor :dead
24
+
25
+ def initialize(args)
26
+ name = args[:name]
27
+ neworleans = args[:neworleans]
28
+ @name = name
29
+ @level = 1
30
+ @lives = 100
31
+ @bonus = 100
32
+ @str = 5
33
+ @int = 5
34
+ @x = 1
35
+ @y = neworleans.get_height
36
+ @in_combat = false
37
+ @current_enemy = nil
38
+ @points = 0
39
+ @dead = 0
40
+ return "Welcome %{name}! Let's play!"
41
+ end
42
+
43
+ # Player attacks enemy
44
+ def attack(args)
45
+ player = self
46
+ enemy = args[:enemy]
47
+ ui = args[:ui]
48
+
49
+ # Does the player even hit the enemy?
50
+ # We could use a hit chance stat here, but since we don't have one,
51
+ # we'll just base it off the player/enemy stength discrepency.
52
+ ui.enemy_info({ player: player })
53
+ ui.player_info({ player: player })
54
+ str_diff = (player.str - enemy.str) * 2
55
+ hit_chance = rand(1...100) + str_diff + HIT_CHANCE_MODIFIER
56
+
57
+ if (hit_chance > 50)
58
+ # Determine value of the attack
59
+ attack_value = rand(1...player.str) + ATTACK_VALUE_MODIFIER
60
+ if attack_value > enemy.lives
61
+ print 'You fought for your life and ' + 'hit'.light_yellow + ' ' +
62
+ enemy.name.light_red + ' for ' +
63
+ attack_value.to_s.light_white + " damages, killing him!\n"
64
+ print 'You gain ' + enemy.points.to_s.light_white + " points.\n"
65
+ return ENEMY_KILLED
66
+ else
67
+ print 'You fought for your life and ' + 'hit'.light_yellow + ' ' +
68
+ enemy.name.light_red + ' for ' +
69
+ attack_value.to_s.light_white + " damages, killing him!\n"
70
+ return attack_value
71
+ end
72
+ else
73
+ print 'You fought for your life and ' + 'missed'.light_red + ' ' +
74
+ enemy.name + "!\n"
75
+ return 0
76
+ end
77
+ return true
78
+ end
79
+
80
+ def move(args)
81
+ direction = args[:direction]
82
+ neworleans = args[:neworleans]
83
+ ui = args[:ui]
84
+ story = args[:story]
85
+ case direction
86
+ when :up
87
+ if @y > 1
88
+ @y -= 1
89
+ else
90
+ ui.out_of_bounds
91
+ return false
92
+ end
93
+ when :down
94
+ if @y < neworleans.get_height
95
+ @y += 1
96
+ else
97
+ ui.out_of_bounds
98
+ return false
99
+ end
100
+ when :left
101
+ if @x > 1
102
+ @x -= 1
103
+ else
104
+ ui.out_of_bounds
105
+ return false
106
+ end
107
+ when :right
108
+ if @x < neworleans.get_width
109
+ @x += 1
110
+ else
111
+ ui.out_of_bounds
112
+ return false
113
+ end
114
+ end
115
+ unless neworleans.check_area({ player: self, ui: ui, story: story })
116
+ return false
117
+ else
118
+ return true
119
+ end
120
+ end
121
+ end
122
+ end
data/lib/story.rb CHANGED
@@ -4,82 +4,78 @@
4
4
  #
5
5
 
6
6
  module MISSIONGAME
7
-
8
7
  STORY_INTRO = [
9
- "This is a game based on the movie series," + "The Originals".light_green + ", that has it's setting in New Orleans, Louisiana, United States.",
10
- "Your mission is to meet "+ "Davina Clare".light_white + " a very powerful witch of New Orleans, and free her.",
11
- "She is currently hostaged by the vampirers under the reign of Klaus Mikaelson.",
12
- "She will provide you answers of all the questions you've always wanted to know.",
13
- "",
14
- "To get stated you will find a " + "map".light_white + " in the Mystic Falls of Virginia.",
15
- "Understanding the map will be key to reaching the destination"
8
+ 'This is a game based on the movie series,' + 'The Originals'.light_green +
9
+ ", that has it's setting in New Orleans, Louisiana, United States.",
10
+ 'Your mission is to meet ' + 'Davina Clare'.light_white +
11
+ ' a very powerful witch of New Orleans, and free her.',
12
+ 'She is currently hostaged by the vampirers under the reign of Klaus Mikaelson.',
13
+ "She will provide you answers of all the questions you've always wanted to know.",
14
+ '',
15
+ 'To get stated you will find a ' + 'map'.light_white +
16
+ ' in the Mystic Falls of Virginia.',
17
+ 'Understanding the map will be key to reaching the destination'
16
18
  ]
17
-
19
+
18
20
  STORY_AREA_TREE = [
19
- "Take a selfie of you before encountering a bloody scene lol."
21
+ 'Take a selfie of you before encountering a bloody scene lol.'
20
22
  ]
21
-
22
- STORY_AREA_WATER = [
23
- "You just got close to Mississippi River."
24
- ]
25
-
23
+
24
+ STORY_AREA_WATER = ['You just got close to Mississippi River.']
25
+
26
26
  STORY_AREA_MOUNTAIN = [
27
- "A cool place to get yourself a beer before continuing with your mission."
28
- ]
29
-
30
- STORY_AREA_VILLAINE = [
31
- "You encountered a hungry vampire!"
27
+ 'A cool place to get yourself a beer before continuing with your mission.'
32
28
  ]
33
-
29
+
30
+ STORY_AREA_VILLAINE = ['You encountered a hungry vampire!']
31
+
34
32
  STORY_PLAYER_DEAD = [
35
- "You have been fed on.",
36
- "",
37
- "You failed to reach the witch. Please try again.",
33
+ 'You have been fed on.',
34
+ '',
35
+ 'You failed to reach the witch. Please try again.'
38
36
  ]
39
-
37
+
40
38
  STORY_END = [
41
39
  "You've reached Davina Clare, the powerful witch!".light_white,
42
- "",
43
- "She stares at you and utters",
44
- "",
40
+ '',
41
+ 'She stares at you and utters',
42
+ '',
45
43
  "I can't imagine the time has finally come".light_yellow,
46
- "This is going to be the end of dominance by vampires becuase this is your kingdom".light_yellow,
47
- "you are special and powerful.".light_yellow,
48
- "",
49
- "THANK YOU FOR PLAYING!".light_red,
50
- "",
44
+ 'This is going to be the end of dominance by vampires becuase this is your kingdom'
45
+ .light_yellow,
46
+ 'you are special and powerful.'.light_yellow,
47
+ '',
48
+ 'THANK YOU FOR PLAYING!'.light_red,
49
+ ''
51
50
  ]
52
-
51
+
53
52
  class Story
54
-
55
53
  def intro
56
54
  return STORY_INTRO
57
55
  end
58
-
56
+
59
57
  def ending
60
58
  return STORY_END
61
59
  end
62
-
60
+
63
61
  def area_tree
64
62
  return STORY_AREA_TREE
65
63
  end
66
-
64
+
67
65
  def area_water
68
66
  return STORY_AREA_WATER
69
67
  end
70
-
68
+
71
69
  def area_mountain
72
70
  return STORY_AREA_MOUNTAIN
73
71
  end
74
-
75
- def area_villaine
72
+
73
+ def area_enemy
76
74
  return STORY_AREA_VILLAINE
77
75
  end
78
-
76
+
79
77
  def player_dead
80
78
  return STORY_PLAYER_DEAD
81
79
  end
82
-
83
80
  end
84
-
85
- end
81
+ end