-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperson.rb
52 lines (40 loc) · 979 Bytes
/
person.rb
1
2
3
4
5
6
7
8
9
10
11
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
class Person
attr_accessor :record, :token, :name, #:position
@@players = []
def initialize(name)
self.name = name
@record = {:wins => 0, :ties => 0, :losses => 0}
@token = ""
@@players << self
end
def self.find_or_create_by_name(name)
result = self.all.find {|player| player.name == name}
if result.nil?
Person.new(name)
else
result
end
end
def self.all
@@players
end
def token_choice
unless @token == "X" || @token == "O"
puts "Would you like to be 'X' or 'O'?"
@token = gets.upcase.chomp
end
end
def player_move
puts "Where would you like to go? (1 - 9)"
@position = gets.chomp.to_i - 1
end
##check
# def valid_move?(board)
# if (@position > 0 && @position <= 9) && board.space_occupied(@position) == false
# return true
# else
# puts "Invalid selection. Please pick another spot."
# return false
# end
# end
end