-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarubatugame.rb
78 lines (59 loc) · 1.48 KB
/
marubatugame.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
=begin
coding:utf-8
頭がつかれたのでゲームをつくったごみのようなマルバツゲーム
たぶん恥ずかしくていつか消す
遊び方:
"y x"の形式で入力してね
=end
$board = ['','',''],
['','',''],
['','','']
now = :black
next_turn = :while
maru = {:black=>'●',:while=>'○'}
$game_status = true
def finish_msg(winner)
puts "you win! : #{winner}"
$game_status = false
end
def puts_map
p $board[0]
puts '-------------'
p $board[1]
puts '-------------'
p $board[2]
end
while $game_status
puts "now player is #{now}"
input = gets.chomp.split.map(&:to_i)
y=input[0]-1
x=input[1]-1
unless $board[y][x]==''
puts 'error. try again to input'
next
end
$board[y][x] = maru[now]
#横
3.times do |y|
if $board[y] == [maru[now],maru[now],maru[now]]
finish_msg(now)
end
end
#縦
3.times do |x|
if $board[0][x] == maru[now] && $board[1][x] == maru[now] && $board[2][x] == maru[now]
finish_msg(now)
end
end
#斜め
#この判定ひどすぎワロタwwww
if ($board[0][0] == maru[now] && $board[1][1] == maru[now] && $board[2][2] = maru[now]) or ($board[0][2] == maru[now] && $board[1][1] == maru[now] && $board[2][0] = maru[now])
finish_msg(now)
end
puts_map()
#プレイヤーのスイッチングどうしたら効率いいですか?教えてエロい人
tmp = now
now = next_turn
next_turn = tmp
#温泉旅行行きたい
end