minefield 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/minefield +9 -0
- data/lib/mine_field.rb +12 -0
- data/lib/mine_field/actions.rb +57 -0
- data/lib/mine_field/map.rb +91 -0
- data/lib/mine_field/point.rb +39 -0
- data/lib/mine_field/score.rb +13 -0
- data/lib/mine_field/version.rb +3 -0
- data/mine_field.gemspec +40 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3992d76e9bab2712bf64fe158a1b5882b41fd11207d1a026bae63726e51d33ee
|
4
|
+
data.tar.gz: cee916d1851672960331e5b291a6ac9fe50d4757e42d49fa24ffc548dc2eac8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '093fb787ae54cf48dce4dbb48145262eb4295abacf034633d0a58911971e8d7c8784df39de0535dc9f3d01069d9b32c20f19db472eeb556ee2a3d84040232d87'
|
7
|
+
data.tar.gz: d85ab266bfab644daadb6424027c7dc8a7e2bc4f57b41430cacdb4273f362d926f9cc6d1d911533e9c2dc741c67d006359269c0906534e647d8fe203a5bf7613
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
minefield (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.17)
|
17
|
+
minefield!
|
18
|
+
minitest (~> 5.0)
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 MuhammetDilmac
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# MineField
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mine_field`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'minefield'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install mine_field
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mine_field.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mine_field"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/minefield
ADDED
data/lib/mine_field.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "mine_field/version"
|
2
|
+
require "mine_field/map"
|
3
|
+
require "mine_field/point"
|
4
|
+
require "mine_field/score"
|
5
|
+
require "mine_field/actions"
|
6
|
+
|
7
|
+
module MineField
|
8
|
+
MINE_CHARACTER = '*'
|
9
|
+
NORMAL_CHARACTER = '-'
|
10
|
+
NOT_OPENED_CHARACTER = 'X'
|
11
|
+
PIPE_SYMBOL = '|'
|
12
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module MineField
|
2
|
+
class Actions
|
3
|
+
def initialize
|
4
|
+
@score = Score.new
|
5
|
+
@map = Map.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def start
|
9
|
+
@map.draw
|
10
|
+
end
|
11
|
+
|
12
|
+
def entry
|
13
|
+
print "Koordinatlar(x#{PIPE_SYMBOL}y): "
|
14
|
+
coordinates = gets.chomp
|
15
|
+
x, y = coordinates.split(PIPE_SYMBOL).map(&:to_i)
|
16
|
+
|
17
|
+
if x.nil? || y.nil?
|
18
|
+
puts 'Geçersiz bir koordinat girdiniz'
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
point = @map.get_point(x, y)
|
23
|
+
|
24
|
+
if point.nil?
|
25
|
+
puts 'Geçersiz bir koordinat girdiniz'
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
if point.opened
|
30
|
+
puts 'Bu koordinat zaten açıldı!'
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
point.opened = true
|
35
|
+
|
36
|
+
if point.content == MINE_CHARACTER
|
37
|
+
@map.visible!
|
38
|
+
@map.draw
|
39
|
+
puts 'Mayınlı Bölgeye Bastınız!'
|
40
|
+
puts "Puanınız: #{@score.total}"
|
41
|
+
exit
|
42
|
+
else
|
43
|
+
@score.increment
|
44
|
+
@map.draw
|
45
|
+
end
|
46
|
+
|
47
|
+
# Alanda kalan noktalar sadece mayın mı diye kontrol et
|
48
|
+
# Eğer kalanların hepsi mayın ise oyunu başarıyla bitir
|
49
|
+
# Değil ise haritayı ekrana çiz
|
50
|
+
end
|
51
|
+
|
52
|
+
def finish
|
53
|
+
# Ekrana puanı yazdır
|
54
|
+
# Restart seçeneği olsun
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module MineField
|
2
|
+
class Map
|
3
|
+
attr_reader :size, :points
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
print 'Matrix Boyunuz: '
|
7
|
+
|
8
|
+
@size = gets.to_i - 1
|
9
|
+
@points = []
|
10
|
+
@print_size = @size.to_s.length + 1
|
11
|
+
|
12
|
+
create_points
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_points
|
16
|
+
mines_points
|
17
|
+
other_points
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw
|
21
|
+
puts `clear`
|
22
|
+
header = '| ' + ' ' * (@print_size + 3) + (0..@size).to_a.map {|i| i.to_s.ljust(@print_size)}.join + " |\n"
|
23
|
+
seperator = '-' * (header.length - 1) + "\n"
|
24
|
+
|
25
|
+
(0..@size).each do |y|
|
26
|
+
if y.zero?
|
27
|
+
print seperator
|
28
|
+
print header
|
29
|
+
print seperator
|
30
|
+
end
|
31
|
+
|
32
|
+
print "| #{y.to_s.rjust(@print_size)} | "
|
33
|
+
|
34
|
+
(0..@size).each do |x|
|
35
|
+
point = get_point(x, y)
|
36
|
+
|
37
|
+
print "#{point.to_s.ljust(@print_size)}"
|
38
|
+
print ' |' if x == @size
|
39
|
+
end
|
40
|
+
|
41
|
+
puts ''
|
42
|
+
end
|
43
|
+
|
44
|
+
puts seperator
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_point(x, y)
|
48
|
+
@points.each do |point|
|
49
|
+
return point if point.coordinate_x == x && point.coordinate_y == y
|
50
|
+
end
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def visible!
|
56
|
+
@points.select {|p| p.opened == false}.each {|p| p.opened = true}
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def mines_points
|
62
|
+
mines_count = Math.sqrt(@size + 1).ceil
|
63
|
+
|
64
|
+
loop do
|
65
|
+
x = (0..@size).to_a.sample
|
66
|
+
y = (0..@size).to_a.sample
|
67
|
+
|
68
|
+
@points.push(Point.new(self, x, y, MINE_CHARACTER)) unless exist_point?(x, y)
|
69
|
+
break if @points.size == mines_count
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def other_points
|
74
|
+
(0..@size).each do |x|
|
75
|
+
(0..@size).each do |y|
|
76
|
+
next if exist_point?(x, y)
|
77
|
+
|
78
|
+
@points.push(Point.new(self, x, y, NORMAL_CHARACTER))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def exist_point?(x, y)
|
84
|
+
@points.each do |point|
|
85
|
+
return true if point.coordinate_x == x && point.coordinate_y == y
|
86
|
+
end
|
87
|
+
|
88
|
+
false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module MineField
|
2
|
+
class Point
|
3
|
+
attr_reader :coordinate_x, :coordinate_y, :content
|
4
|
+
attr_accessor :opened
|
5
|
+
|
6
|
+
def initialize(map, x, y, content)
|
7
|
+
@coordinate_x = x
|
8
|
+
@coordinate_y = y
|
9
|
+
@content = content
|
10
|
+
@opened = false
|
11
|
+
@map = map
|
12
|
+
end
|
13
|
+
|
14
|
+
def neighbors
|
15
|
+
items = []
|
16
|
+
|
17
|
+
((@coordinate_x - 1)..(@coordinate_x + 1)).each do |x|
|
18
|
+
((@coordinate_y - 1)..(@coordinate_y + 1)).each do |y|
|
19
|
+
point = @map.get_point(x, y)
|
20
|
+
items.push(point) unless point.nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
items
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
if @opened
|
29
|
+
if @content == MINE_CHARACTER
|
30
|
+
MINE_CHARACTER
|
31
|
+
else
|
32
|
+
neighbors.select {|p| p.content == MINE_CHARACTER}.count.to_s
|
33
|
+
end
|
34
|
+
else
|
35
|
+
NOT_OPENED_CHARACTER
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/mine_field.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mine_field/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "minefield"
|
8
|
+
spec.version = MineField::VERSION
|
9
|
+
spec.authors = ["MuhammetDilmac"]
|
10
|
+
spec.email = ["iletisim@muhammetdilmac.com.tr"]
|
11
|
+
|
12
|
+
spec.summary = 'Mayın Tarlası Oyunu'
|
13
|
+
spec.description = 'Mayın Tarlası Oyunu'
|
14
|
+
spec.homepage = 'http://muhammetdilmac.com.tr'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = 'http://muhammetdilmac.com.tr'
|
22
|
+
spec.metadata["changelog_uri"] = 'http://muhammetdilmac.com.tr'
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
"public gem pushes."
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minefield
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MuhammetDilmac
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Mayın Tarlası Oyunu
|
56
|
+
email:
|
57
|
+
- iletisim@muhammetdilmac.com.tr
|
58
|
+
executables:
|
59
|
+
- minefield
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- exe/minefield
|
73
|
+
- lib/mine_field.rb
|
74
|
+
- lib/mine_field/actions.rb
|
75
|
+
- lib/mine_field/map.rb
|
76
|
+
- lib/mine_field/point.rb
|
77
|
+
- lib/mine_field/score.rb
|
78
|
+
- lib/mine_field/version.rb
|
79
|
+
- mine_field.gemspec
|
80
|
+
homepage: http://muhammetdilmac.com.tr
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
homepage_uri: http://muhammetdilmac.com.tr
|
85
|
+
source_code_uri: http://muhammetdilmac.com.tr
|
86
|
+
changelog_uri: http://muhammetdilmac.com.tr
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.7.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Mayın Tarlası Oyunu
|
107
|
+
test_files: []
|