Class: MineField::Actions

Inherits:
Object
  • Object
show all
Defined in:
lib/mine_field/actions.rb

Instance Method Summary collapse

Constructor Details

#initializeActions

Returns a new instance of Actions.



3
4
5
6
# File 'lib/mine_field/actions.rb', line 3

def initialize
  @score = Score.new
  @map = Map.new
end

Instance Method Details

#entryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mine_field/actions.rb', line 12

def entry
  print "Koordinatlar(x#{PIPE_SYMBOL}y): "
  coordinates = gets.chomp
  x, y = coordinates.split(PIPE_SYMBOL).map(&:to_i)

  if x.nil? || y.nil?
    puts 'Geçersiz bir koordinat girdiniz'
    return
  end

  point = @map.get_point(x, y)

  if point.nil?
    puts 'Geçersiz bir koordinat girdiniz'
    return
  end

  if point.opened
    puts 'Bu koordinat zaten açıldı!'
    return
  end

  point.opened = true

  if point.content == MINE_CHARACTER
    @map.visible!
    @map.draw
    puts 'Mayınlı Bölgeye Bastınız!'
    puts "Puanınız: #{@score.total}"
    exit
  else
    @score.increment
    @map.draw
  end

  # Alanda kalan noktalar sadece mayın mı diye kontrol et
  # Eğer kalanların hepsi mayın ise oyunu başarıyla bitir
  # Değil ise haritayı ekrana çiz
end

#finishObject



52
53
54
55
# File 'lib/mine_field/actions.rb', line 52

def finish
  # Ekrana puanı yazdır
  # Restart seçeneği olsun
end

#startObject



8
9
10
# File 'lib/mine_field/actions.rb', line 8

def start
  @map.draw
end