eugame 0.0.1
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/lib/eugame.rb +23 -0
- data/lib/gamelib/gamelib.rb +8 -0
- data/lib/gamelib/ttt/colorize.rb +21 -0
- data/lib/gamelib/ttt/ttt.rb +87 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9354c877e5c90ca981489601a01f013a6d0d6c42de1f4cfac664fb18a67b4108
|
|
4
|
+
data.tar.gz: 86314bd5a48864e3354b451a6179722e3a339c492a53f8aa7001eeb405101f26
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 81ea18f2f8521697e9471504921d086296b7ce33ffc84fcf99546a9a3b5d1a440fdc57a852ab67b8112cf0689021351b40eab49ac52572a8a521a961f2891475
|
|
7
|
+
data.tar.gz: 2152964ad5ea7f9f805fab860a1e2c913843405cce36c76d878d8bf20cfacaea5e575f77f312d2ed5d417c48cc5ca66852ea1a94464e06bfaf761a9c384b9055
|
data/lib/eugame.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'gamelib/gamelib.rb'
|
|
2
|
+
require 'gamelib/ttt/ttt.rb'
|
|
3
|
+
require 'gamelib/ttt/colorize.rb'
|
|
4
|
+
|
|
5
|
+
module EUGAME
|
|
6
|
+
class EuGame
|
|
7
|
+
def start
|
|
8
|
+
while menu != 0 do end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def menu
|
|
12
|
+
puts
|
|
13
|
+
puts "------ Menu ------"
|
|
14
|
+
puts "1. PvP Tic-Tac-Toe"
|
|
15
|
+
puts "0. Exit"
|
|
16
|
+
print "> "
|
|
17
|
+
case gets.to_i
|
|
18
|
+
when 0 then return 0
|
|
19
|
+
when 1 then GameLib.tictactoe
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def color_code(code)
|
|
3
|
+
"\e[#{code}m#{self}\e0\e[39m"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def blue
|
|
7
|
+
color_code(34)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def red
|
|
11
|
+
color_code(31)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def color(str)
|
|
16
|
+
case str
|
|
17
|
+
when 'O' then str.red
|
|
18
|
+
when 'X' then str.blue
|
|
19
|
+
else str
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class TicTacToe
|
|
2
|
+
def initialize
|
|
3
|
+
system('clear')
|
|
4
|
+
@@row = @@col = 3
|
|
5
|
+
@@p_turn = '1' # which player's turn is it
|
|
6
|
+
@@players = {'1': {name: nil, mark: 'O'}, '2': {name: nil, mark: 'X'}}
|
|
7
|
+
@board = [ ['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ] # 3x3 board
|
|
8
|
+
@playing = true
|
|
9
|
+
set_players_name
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def set_players_name
|
|
13
|
+
puts "Enter player1's name: "
|
|
14
|
+
@@players[:'1'][:'name'] = gets.chomp
|
|
15
|
+
puts "Enter player2's name: "
|
|
16
|
+
@@players[:'2'][:'name'] = gets.chomp
|
|
17
|
+
system('clear');
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def play
|
|
21
|
+
while true do
|
|
22
|
+
display_board
|
|
23
|
+
turn
|
|
24
|
+
return if !@playing
|
|
25
|
+
system('clear')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def display_board
|
|
30
|
+
puts "===================================="
|
|
31
|
+
puts "%10s vs. %-10s" % [@@players[:'1'][:name], @@players[:'2'][:name]]
|
|
32
|
+
puts "===================================="
|
|
33
|
+
puts "\t %s | %s | %s" % [color(@board[0][0]), color(@board[0][1]), color(@board[0][2])]
|
|
34
|
+
puts "\t___________"
|
|
35
|
+
puts "\t %s | %s | %s" % [color(@board[1][0]), color(@board[1][1]), color(@board[1][2])]
|
|
36
|
+
puts "\t___________"
|
|
37
|
+
puts "\t %s | %s | %s" % [color(@board[2][0]), color(@board[2][1]), color(@board[2][2])]
|
|
38
|
+
puts
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def turn
|
|
42
|
+
print "#{@@players[@@p_turn.to_sym][:name]}'s turn: "
|
|
43
|
+
cell = gets.to_i - 1
|
|
44
|
+
while cell < 0 or cell > 8 do
|
|
45
|
+
print "#{@@players[@@p_turn.to_sym][:name]}'s turn: "
|
|
46
|
+
cell = gets.to_i - 1
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
row = cell / @@row
|
|
50
|
+
col = cell % @@col
|
|
51
|
+
|
|
52
|
+
while @board[row][col] == 'O' or @board[row][col] == 'X'
|
|
53
|
+
print "#{@@players[@@p_turn.to_sym][:name]}'s turn: "
|
|
54
|
+
cell = gets.to_i - 1
|
|
55
|
+
row = cell / @@row
|
|
56
|
+
col = cell % @@col
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
@board[row][col] = @@players[@@p_turn.to_sym][:mark]
|
|
60
|
+
|
|
61
|
+
validate
|
|
62
|
+
|
|
63
|
+
@@p_turn = @@p_turn == '1' ? '2' : '1'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def validate
|
|
67
|
+
# horiznotal and vertical check
|
|
68
|
+
0.upto(2) do |i|
|
|
69
|
+
if (@board[i][0] == @board[i][1] and @board[i][1] == @board[i][2]) or
|
|
70
|
+
(@board[0][i] == @board[1][i] and @board[1][i] == @board[2][i])
|
|
71
|
+
system('clear')
|
|
72
|
+
display_board
|
|
73
|
+
puts "%15s" % "#{@@players[@@p_turn.to_sym][:name]} won"
|
|
74
|
+
@playing = false;
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# diagonal
|
|
79
|
+
if (@board[0][0] == @board[1][1] and @board[1][1] == @board[2][2]) or
|
|
80
|
+
(@board[0][2] == @board[1][1] and @board[1][1] == @board[2][0])
|
|
81
|
+
system('clear')
|
|
82
|
+
display_board
|
|
83
|
+
puts "%15s" % "#{@@players[@@p_turn.to_sym][:name]} won"
|
|
84
|
+
@playing = false;
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: eugame
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jione Eu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-05-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: " EuGame is a gem that supports various TUI 2d games.\n"
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/eugame.rb
|
|
20
|
+
- lib/gamelib/gamelib.rb
|
|
21
|
+
- lib/gamelib/ttt/colorize.rb
|
|
22
|
+
- lib/gamelib/ttt/ttt.rb
|
|
23
|
+
homepage:
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata:
|
|
27
|
+
documentation_uri: https://github.com/jioneeu/eugame
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubygems_version: 3.1.2
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: EuGame is a gem that supports various TUI 2d games.
|
|
47
|
+
test_files: []
|