x1c-studio-game 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README +253 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +141 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +31 -0
- data/lib/studio_game/clumsy_player.rb +45 -0
- data/lib/studio_game/die.rb +19 -0
- data/lib/studio_game/game.rb +117 -0
- data/lib/studio_game/game_turn.rb +25 -0
- data/lib/studio_game/iterators.rb +32 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +65 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +30 -0
- data/spec/studio_game/clumsy_player_spec.rb +49 -0
- data/spec/studio_game/game_spec.rb +86 -0
- data/spec/studio_game/player_spec.rb +103 -0
- data/spec/studio_game/spec_helper.rb +8 -0
- data/spec/studio_game/treasure_trove_spec.rb +57 -0
- metadata +343 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49d785f5616be94eeb10049ef7af358356754e4ce8db9fc523bb2e4d90efbf3f
|
4
|
+
data.tar.gz: fb6494196bbf31afcf21f39ca465cb910a7d7c86bc6040a57caeaa1d4a6acf3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ceb91169e8bc32821aa6f42cd5e9b25a8b0b42d1951452cb0be7ad7f934b9db2d6e1493c74ae4e4e1c4b851d09c1708c0775bee18b64a06937ac2a9cf0ba328
|
7
|
+
data.tar.gz: a76d032d134c54ee8a36b6c23840a2415b61ce57f4e23f7e25b7de4a622631d070c33d5a3f70699ea4dab812665c3dedf6aa8fd2642db0df188e7ed42a7837b4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 RubyCourse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
<div id="top"></div>
|
2
|
+
<!--
|
3
|
+
*** Thanks for checking out the Best-README-Template. If you have a suggestion
|
4
|
+
*** that would make this better, please fork the repo and create a pull request
|
5
|
+
*** or simply open an issue with the tag "enhancement".
|
6
|
+
*** Don't forget to give the project a star!
|
7
|
+
*** Thanks again! Now go create something AMAZING! :D
|
8
|
+
-->
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
<!-- PROJECT SHIELDS -->
|
13
|
+
<!--
|
14
|
+
*** I'm using markdown "reference style" links for readability.
|
15
|
+
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
16
|
+
*** See the bottom of this document for the declaration of the reference variables
|
17
|
+
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
18
|
+
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
19
|
+
-->
|
20
|
+
[![Contributors][contributors-shield]][contributors-url]
|
21
|
+
[![Forks][forks-shield]][forks-url]
|
22
|
+
[![Stargazers][stars-shield]][stars-url]
|
23
|
+
[![Issues][issues-shield]][issues-url]
|
24
|
+
[![MIT License][license-shield]][license-url]
|
25
|
+
[![LinkedIn][linkedin-shield]][linkedin-url]
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
<!-- PROJECT LOGO -->
|
30
|
+
<br />
|
31
|
+
<div align="center">
|
32
|
+
<a href="https://github.com/othneildrew/Best-README-Template">
|
33
|
+
<img src="images/logo.png" alt="Logo" width="80" height="80">
|
34
|
+
</a>
|
35
|
+
|
36
|
+
<h3 align="center">Best-README-Template</h3>
|
37
|
+
|
38
|
+
<p align="center">
|
39
|
+
An awesome README template to jumpstart your projects!
|
40
|
+
<br />
|
41
|
+
<a href="https://github.com/othneildrew/Best-README-Template"><strong>Explore the docs »</strong></a>
|
42
|
+
<br />
|
43
|
+
<br />
|
44
|
+
<a href="https://github.com/othneildrew/Best-README-Template">View Demo</a>
|
45
|
+
·
|
46
|
+
<a href="https://github.com/othneildrew/Best-README-Template/issues">Report Bug</a>
|
47
|
+
·
|
48
|
+
<a href="https://github.com/othneildrew/Best-README-Template/issues">Request Feature</a>
|
49
|
+
</p>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
<!-- TABLE OF CONTENTS -->
|
55
|
+
<details>
|
56
|
+
<summary>Table of Contents</summary>
|
57
|
+
<ol>
|
58
|
+
<li>
|
59
|
+
<a href="#about-the-project">About The Project</a>
|
60
|
+
<ul>
|
61
|
+
<li><a href="#built-with">Built With</a></li>
|
62
|
+
</ul>
|
63
|
+
</li>
|
64
|
+
<li>
|
65
|
+
<a href="#getting-started">Getting Started</a>
|
66
|
+
<ul>
|
67
|
+
<li><a href="#prerequisites">Prerequisites</a></li>
|
68
|
+
<li><a href="#installation">Installation</a></li>
|
69
|
+
</ul>
|
70
|
+
</li>
|
71
|
+
<li><a href="#usage">Usage</a></li>
|
72
|
+
<li><a href="#roadmap">Roadmap</a></li>
|
73
|
+
<li><a href="#contributing">Contributing</a></li>
|
74
|
+
<li><a href="#license">License</a></li>
|
75
|
+
<li><a href="#contact">Contact</a></li>
|
76
|
+
<li><a href="#acknowledgments">Acknowledgments</a></li>
|
77
|
+
</ol>
|
78
|
+
</details>
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
<!-- ABOUT THE PROJECT -->
|
83
|
+
## About The Project
|
84
|
+
|
85
|
+
[![Product Name Screen Shot][product-screenshot]](https://example.com)
|
86
|
+
|
87
|
+
There are many great README templates available on GitHub; however, I didn't find one that really suited my needs so I created this enhanced one. I want to create a README template so amazing that it'll be the last one you ever need -- I think this is it.
|
88
|
+
|
89
|
+
Here's why:
|
90
|
+
* Your time should be focused on creating something amazing. A project that solves a problem and helps others
|
91
|
+
* You shouldn't be doing the same tasks over and over like creating a README from scratch
|
92
|
+
* You should implement DRY principles to the rest of your life :smile:
|
93
|
+
|
94
|
+
Of course, no one template will serve all projects since your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue. Thanks to all the people have contributed to expanding this template!
|
95
|
+
|
96
|
+
Use the `BLANK_README.md` to get started.
|
97
|
+
|
98
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
### Built With
|
103
|
+
|
104
|
+
This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
|
105
|
+
|
106
|
+
* [Next.js](https://nextjs.org/)
|
107
|
+
* [React.js](https://reactjs.org/)
|
108
|
+
* [Vue.js](https://vuejs.org/)
|
109
|
+
* [Angular](https://angular.io/)
|
110
|
+
* [Svelte](https://svelte.dev/)
|
111
|
+
* [Laravel](https://laravel.com)
|
112
|
+
* [Bootstrap](https://getbootstrap.com)
|
113
|
+
* [JQuery](https://jquery.com)
|
114
|
+
|
115
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<!-- GETTING STARTED -->
|
120
|
+
## Getting Started
|
121
|
+
|
122
|
+
This is an example of how you may give instructions on setting up your project locally.
|
123
|
+
To get a local copy up and running follow these simple example steps.
|
124
|
+
|
125
|
+
### Prerequisites
|
126
|
+
|
127
|
+
This is an example of how to list things you need to use the software and how to install them.
|
128
|
+
* npm
|
129
|
+
```sh
|
130
|
+
npm install npm@latest -g
|
131
|
+
```
|
132
|
+
|
133
|
+
### Installation
|
134
|
+
|
135
|
+
_Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services._
|
136
|
+
|
137
|
+
1. Get a free API Key at [https://example.com](https://example.com)
|
138
|
+
2. Clone the repo
|
139
|
+
```sh
|
140
|
+
git clone https://github.com/your_username_/Project-Name.git
|
141
|
+
```
|
142
|
+
3. Install NPM packages
|
143
|
+
```sh
|
144
|
+
npm install
|
145
|
+
```
|
146
|
+
4. Enter your API in `config.js`
|
147
|
+
```js
|
148
|
+
const API_KEY = 'ENTER YOUR API';
|
149
|
+
```
|
150
|
+
|
151
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<!-- USAGE EXAMPLES -->
|
156
|
+
## Usage
|
157
|
+
|
158
|
+
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
|
159
|
+
|
160
|
+
_For more examples, please refer to the [Documentation](https://example.com)_
|
161
|
+
|
162
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
<!-- ROADMAP -->
|
167
|
+
## Roadmap
|
168
|
+
|
169
|
+
- [x] Add Changelog
|
170
|
+
- [x] Add back to top links
|
171
|
+
- [ ] Add Additional Templates w/ Examples
|
172
|
+
- [ ] Add "components" document to easily copy & paste sections of the readme
|
173
|
+
- [ ] Multi-language Support
|
174
|
+
- [ ] Chinese
|
175
|
+
- [ ] Spanish
|
176
|
+
|
177
|
+
See the [open issues](https://github.com/othneildrew/Best-README-Template/issues) for a full list of proposed features (and known issues).
|
178
|
+
|
179
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
<!-- CONTRIBUTING -->
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
187
|
+
|
188
|
+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
189
|
+
Don't forget to give the project a star! Thanks again!
|
190
|
+
|
191
|
+
1. Fork the Project
|
192
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
193
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
194
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
195
|
+
5. Open a Pull Request
|
196
|
+
|
197
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<!-- LICENSE -->
|
202
|
+
## License
|
203
|
+
|
204
|
+
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
205
|
+
|
206
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
<!-- CONTACT -->
|
211
|
+
## Contact
|
212
|
+
|
213
|
+
Your Name - [@your_twitter](https://twitter.com/your_username) - email@example.com
|
214
|
+
|
215
|
+
Project Link: [https://github.com/your_username/repo_name](https://github.com/your_username/repo_name)
|
216
|
+
|
217
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
<!-- ACKNOWLEDGMENTS -->
|
222
|
+
## Acknowledgments
|
223
|
+
|
224
|
+
Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!
|
225
|
+
|
226
|
+
* [Choose an Open Source License](https://choosealicense.com)
|
227
|
+
* [GitHub Emoji Cheat Sheet](https://www.webpagefx.com/tools/emoji-cheat-sheet)
|
228
|
+
* [Malven's Flexbox Cheatsheet](https://flexbox.malven.co/)
|
229
|
+
* [Malven's Grid Cheatsheet](https://grid.malven.co/)
|
230
|
+
* [Img Shields](https://shields.io)
|
231
|
+
* [GitHub Pages](https://pages.github.com)
|
232
|
+
* [Font Awesome](https://fontawesome.com)
|
233
|
+
* [React Icons](https://react-icons.github.io/react-icons/search)
|
234
|
+
|
235
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
<!-- MARKDOWN LINKS & IMAGES -->
|
240
|
+
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
241
|
+
[contributors-shield]: https://img.shields.io/github/contributors/othneildrew/Best-README-Template.svg?style=for-the-badge
|
242
|
+
[contributors-url]: https://github.com/othneildrew/Best-README-Template/graphs/contributors
|
243
|
+
[forks-shield]: https://img.shields.io/github/forks/othneildrew/Best-README-Template.svg?style=for-the-badge
|
244
|
+
[forks-url]: https://github.com/othneildrew/Best-README-Template/network/members
|
245
|
+
[stars-shield]: https://img.shields.io/github/stars/othneildrew/Best-README-Template.svg?style=for-the-badge
|
246
|
+
[stars-url]: https://github.com/othneildrew/Best-README-Template/stargazers
|
247
|
+
[issues-shield]: https://img.shields.io/github/issues/othneildrew/Best-README-Template.svg?style=for-the-badge
|
248
|
+
[issues-url]: https://github.com/othneildrew/Best-README-Template/issues
|
249
|
+
[license-shield]: https://img.shields.io/github/license/othneildrew/Best-README-Template.svg?style=for-the-badge
|
250
|
+
[license-url]: https://github.com/othneildrew/Best-README-Template/blob/master/LICENSE.txt
|
251
|
+
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
|
252
|
+
[linkedin-url]: https://linkedin.com/in/othneildrew
|
253
|
+
[product-screenshot]: images/screenshot.png
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/player'
|
4
|
+
require_relative '../lib/studio_game/game'
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
6
|
+
require_relative '../lib/studio_game/berserk_player'
|
7
|
+
|
8
|
+
# greeting = "Welcome!"
|
9
|
+
|
10
|
+
# 3.times do
|
11
|
+
# puts greeting.upcase
|
12
|
+
# end
|
13
|
+
|
14
|
+
# puts Time.new
|
15
|
+
|
16
|
+
# name1 = "larry"
|
17
|
+
# health1 = 60
|
18
|
+
# puts "#{ name1 }\t health \n is #{ health1 / 9.0 }"
|
19
|
+
|
20
|
+
# name2 = "curly"
|
21
|
+
# name3 = "moe"
|
22
|
+
|
23
|
+
# puts "Players:\n\t#{ name1 }\n\t#{ name2 }\n\t#{ name3 }"
|
24
|
+
|
25
|
+
# project1 = "ABC"
|
26
|
+
# project2 = "LMN"
|
27
|
+
# project3 = "XYZ"
|
28
|
+
|
29
|
+
# puts "Project #{ project1 } has $1000 in funding."
|
30
|
+
# puts "Projects: \n\t#{ project1 }\n\t#{ project2 }\n\t#{ project3 }"
|
31
|
+
|
32
|
+
# name1 = "larry"
|
33
|
+
# health1 = 60
|
34
|
+
# puts "#{ name1.capitalize } has a health of #{ health1 }"
|
35
|
+
|
36
|
+
# name2 = "curly"
|
37
|
+
# health2 = 125
|
38
|
+
# puts "#{ name2.upcase } has a health of #{ health2 }"
|
39
|
+
|
40
|
+
# health2 = health1
|
41
|
+
# puts "#{ name2.upcase } has a health of #{ health2 }"
|
42
|
+
|
43
|
+
# health1 = 30
|
44
|
+
# puts "#{ name1.capitalize } has a health of #{ health1 }"
|
45
|
+
# puts "#{ name2.upcase } has a health of #{ health2 }"
|
46
|
+
|
47
|
+
# name3 = "moe"
|
48
|
+
# health3 = 100
|
49
|
+
# puts "#{ name3.capitalize } has a health of #{ health3 }".center(50, '*')
|
50
|
+
|
51
|
+
# name4 = "shemp"
|
52
|
+
# health4 = 90
|
53
|
+
# puts "#{ name4.capitalize.ljust(30, '.') } #{ health4 } health"
|
54
|
+
|
55
|
+
# puts "Game started on #{Time.new.strftime("%A %d/%m/%Y at %I:%M%p")}"
|
56
|
+
|
57
|
+
# puts self.class
|
58
|
+
|
59
|
+
# def movie_listing(title, rank=title.length)
|
60
|
+
# "Movie: #{title.capitalize} has a rank of #{ rank }"
|
61
|
+
# end
|
62
|
+
|
63
|
+
# puts movie_listing("goonies")
|
64
|
+
# puts movie_listing("ghostbuster", 9)
|
65
|
+
# def time
|
66
|
+
# Time.new.strftime("%T")
|
67
|
+
# end
|
68
|
+
|
69
|
+
# def say_hello(name, health=100)
|
70
|
+
# "I'm #{name.capitalize} with a health of #{health} as of #{time}."
|
71
|
+
# end
|
72
|
+
|
73
|
+
# puts say_hello("larry", 60)
|
74
|
+
# puts say_hello("curly", 125)
|
75
|
+
# puts say_hello("moe")
|
76
|
+
# puts say_hello("shemp", 90)
|
77
|
+
|
78
|
+
|
79
|
+
# player1 = Player.new("moe")
|
80
|
+
# puts player1.health
|
81
|
+
# puts player1.name
|
82
|
+
# puts player1
|
83
|
+
|
84
|
+
# player2 = Player.new("larry", 60)
|
85
|
+
# player2.name = "Lawrence"
|
86
|
+
# puts player2
|
87
|
+
|
88
|
+
# player3 = Player.new("curly", 125)
|
89
|
+
# player3.blam
|
90
|
+
# puts player3
|
91
|
+
# player3.w00t
|
92
|
+
# puts player3
|
93
|
+
|
94
|
+
# puts player3
|
95
|
+
|
96
|
+
# players = [player1, player2, player3]
|
97
|
+
# puts "There are #{players.size} players in a game:"
|
98
|
+
|
99
|
+
# players.pop
|
100
|
+
# players.push(Player.new("Shemp", 90))
|
101
|
+
# players.each do |player|
|
102
|
+
# player.blam
|
103
|
+
# player.w00t
|
104
|
+
# player.w00t
|
105
|
+
# puts player
|
106
|
+
# end
|
107
|
+
|
108
|
+
# player1 = Player.new("moe")
|
109
|
+
# player2 = Player.new("larry", 60)
|
110
|
+
# player3 = Player.new("curly", 125)
|
111
|
+
# player4 = Player.new("andrii", 135)
|
112
|
+
|
113
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
114
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
115
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
116
|
+
|
117
|
+
# knuckleheads.load_players('players.csv')
|
118
|
+
knuckleheads.add_player(StudioGame::ClumsyPlayer.new("klutz", 105))
|
119
|
+
knuckleheads.add_player(StudioGame::ClumsyPlayer.new("klutz-powered", 90, 5))
|
120
|
+
knuckleheads.add_player(StudioGame::BerserkPlayer.new("berserker", 50))
|
121
|
+
# knuckleheads.add_player(player2)BerserkPlayer
|
122
|
+
# knuckleheads.add_player(player3)
|
123
|
+
# knuckleheads.add_player(player4)
|
124
|
+
|
125
|
+
loop do
|
126
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
127
|
+
answer = gets.chomp.downcase
|
128
|
+
case answer
|
129
|
+
when /^\d+/
|
130
|
+
knuckleheads.play(answer.to_i) do
|
131
|
+
knuckleheads.total_points >= 2000
|
132
|
+
end
|
133
|
+
when "quit", "exit"
|
134
|
+
knuckleheads.print_stats
|
135
|
+
break
|
136
|
+
else
|
137
|
+
puts "Please enter a number or 'quit'"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
knuckleheads.save_high_scores
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
def initialize(name, health=100)
|
6
|
+
super(name, health)
|
7
|
+
@w00t_count = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def berserk?
|
11
|
+
@w00t_count > 5
|
12
|
+
end
|
13
|
+
|
14
|
+
def w00t
|
15
|
+
super
|
16
|
+
@w00t_count += 1
|
17
|
+
puts "#{@name} is berserk!" if berserk?
|
18
|
+
end
|
19
|
+
|
20
|
+
def blam
|
21
|
+
berserk? ? w00t : super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
27
|
+
6.times { berserker.w00t }
|
28
|
+
2.times { berserker.blam }
|
29
|
+
puts berserker.health
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
attr_reader :boost_factor
|
6
|
+
|
7
|
+
def initialize(name, health=100, boost_factor=1)
|
8
|
+
super(name, health)
|
9
|
+
@boost_factor = boost_factor
|
10
|
+
end
|
11
|
+
|
12
|
+
def w00t
|
13
|
+
@boost_factor.times { super }
|
14
|
+
end
|
15
|
+
|
16
|
+
def found_treasure(treasure)
|
17
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
18
|
+
super damaged_treasure
|
19
|
+
# points = (treasure.points / 2)
|
20
|
+
# @found_treasures[treasure.name] += points
|
21
|
+
|
22
|
+
# puts "#{@name} found a #{treasure.name}" +
|
23
|
+
# " worth #{points} points."
|
24
|
+
# puts "#{@name}'s treasures: #{@found_treasures}"
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $0
|
30
|
+
clumsy = ClumsyPlayer.new("klutz")
|
31
|
+
|
32
|
+
hammer = Treasure.new(:hammer, 50)
|
33
|
+
clumsy.found_treasure(hammer)
|
34
|
+
clumsy.found_treasure(hammer)
|
35
|
+
clumsy.found_treasure(hammer)
|
36
|
+
|
37
|
+
crowbar = Treasure.new(:crowbar, 400)
|
38
|
+
clumsy.found_treasure(crowbar)
|
39
|
+
|
40
|
+
clumsy.each_found_treasure do |treasure|
|
41
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
42
|
+
end
|
43
|
+
puts "#{clumsy.points} grand total points"
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
require 'csv'
|
6
|
+
|
7
|
+
module StudioGame
|
8
|
+
class Game
|
9
|
+
attr_reader :title
|
10
|
+
|
11
|
+
def initialize(title)
|
12
|
+
@title = title
|
13
|
+
@players = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_players(from_file)
|
17
|
+
|
18
|
+
CSV.foreach(from_file) do |line|
|
19
|
+
player = Player.new(line[0], Integer(line[1]))
|
20
|
+
add_player(player)
|
21
|
+
end
|
22
|
+
|
23
|
+
# we have it in tests, but do not use
|
24
|
+
# File.readlines(from_file).each do |line|
|
25
|
+
# player = Player.from_csv(line)
|
26
|
+
# add_player(player)
|
27
|
+
# end
|
28
|
+
end
|
29
|
+
|
30
|
+
def save_high_scores(to_file='high_scores.txt')
|
31
|
+
File.open(to_file, 'w') do |file|
|
32
|
+
file.puts "#{@title} High Scores:"
|
33
|
+
@players.sort.each do |player|
|
34
|
+
file.puts high_score_entry(player)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def high_score_entry(player)
|
40
|
+
"#{player.name.ljust(30, '.')}" + " #{player.score}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_player(player)
|
44
|
+
@players << player
|
45
|
+
end
|
46
|
+
|
47
|
+
def play(rounds)
|
48
|
+
puts "There are #{@players.size} players in #{@title}:"
|
49
|
+
puts @players
|
50
|
+
|
51
|
+
treasures = TreasureTrove::TREASURES
|
52
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
53
|
+
treasures.each do |treasure|
|
54
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
55
|
+
end
|
56
|
+
|
57
|
+
1.upto(rounds) do |round|
|
58
|
+
if block_given?
|
59
|
+
break if yield
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "\nRounds ##{round}"
|
63
|
+
@players.each do |player|
|
64
|
+
GameTurn.take_turn(player)
|
65
|
+
|
66
|
+
#puts player
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def print_name_and_health(player)
|
72
|
+
puts "#{player.name} (#{player.health})"
|
73
|
+
end
|
74
|
+
|
75
|
+
def print_stats
|
76
|
+
strong_players, wimpy_players =
|
77
|
+
@players.partition { |player| player.strong? }
|
78
|
+
|
79
|
+
puts "Knuckleheads Statistics:"
|
80
|
+
|
81
|
+
puts "\n#{strong_players.length} strong players:"
|
82
|
+
strong_players.each do |player|
|
83
|
+
print_name_and_health(player)
|
84
|
+
end
|
85
|
+
|
86
|
+
puts "\n#{wimpy_players.length} wimpy players:"
|
87
|
+
wimpy_players.each do |player|
|
88
|
+
print_name_and_health(player)
|
89
|
+
end
|
90
|
+
|
91
|
+
@players.each do |player|
|
92
|
+
puts "\n#{player.name}'s point totals:\n#{player.points} grand total points"
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "\n#{@title} High Scores:"
|
96
|
+
@players.sort.each do |player|
|
97
|
+
puts high_score_entry(player)
|
98
|
+
end
|
99
|
+
|
100
|
+
puts "\n#{total_points} total points from treasures found"
|
101
|
+
|
102
|
+
@players.sort.each do |player|
|
103
|
+
puts "\n#{player.name}'s point totals:"
|
104
|
+
player.each_found_treasure do |treasure|
|
105
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
106
|
+
end
|
107
|
+
puts "#{player.points} grand total points"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
def total_points
|
113
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
# require_relative 'loaded_die'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
module GameTurn
|
8
|
+
def self.take_turn(player)
|
9
|
+
number_rolled = Die.new.roll
|
10
|
+
# number_rolled = LoadedDie.new.roll
|
11
|
+
|
12
|
+
case number_rolled
|
13
|
+
when 1..2
|
14
|
+
player.blam
|
15
|
+
when 3..4
|
16
|
+
puts "#{player.name} was skipped."
|
17
|
+
else
|
18
|
+
player.w00t
|
19
|
+
end
|
20
|
+
|
21
|
+
treasure = TreasureTrove.random
|
22
|
+
player.found_treasure(treasure)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|