typeking 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/lib/typeking/game_controller.rb +9 -10
- data/lib/typeking/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb37c928cbf328adbb5dff7f054a35df51ea603f2db5ccbba2beea1294d26d04
|
4
|
+
data.tar.gz: 866a6988b093c121aea0dc84c20741ed23d4bcdbf7aae034609df59239879bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b51ed0c2557667ad206d6b86649863b9ec7cd99c616a6f07ae019b43c15cbe517da58af2eb3e0fe1f3c543474d9d3d4d06b9a54bcaa847a3a164894cb3719ab6
|
7
|
+
data.tar.gz: 813d8e46d63ab1f0dc20df7756119ad26d2d9f5052ffaa4743b97f890e2ab9867e48d95d5761b1537a7323dea082adf6d1002321d16a3608cf89cdd662173104
|
data/README.md
CHANGED
@@ -19,9 +19,22 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
Typeking::GameController.new()
|
22
|
+
Typeking::GameController.new() #starts the application
|
23
23
|
```
|
24
24
|
|
25
|
+
1. Install the gem
|
26
|
+
2. Open IRB by typing 'irb' in the terminal
|
27
|
+
3. Type 'require 'typeking'' and press enter
|
28
|
+
4. Type Typeking::GameController.new() and press enter
|
29
|
+
5. Use the keyboard to navigation to 'Register' and press enter
|
30
|
+
6. Login using the registered name (case-sensitive)
|
31
|
+
7. Press enter on the 'Play' option
|
32
|
+
8. Enter how many words you want to type (enter a number from 5-500)
|
33
|
+
9. Type the words that appear in the terminal
|
34
|
+
10. See results when typing is finished
|
35
|
+
11. Play again or log out to check if you have made the leaderboards!
|
36
|
+
|
37
|
+
|
25
38
|
|
26
39
|
## Development
|
27
40
|
|
@@ -14,7 +14,6 @@ module Typeking
|
|
14
14
|
@userHashes = {} #stores indexes for all users
|
15
15
|
@currentUserData = {} #stores current stats
|
16
16
|
@currentUid = 0 #current user id
|
17
|
-
@leaderboardArr = []
|
18
17
|
setup_application
|
19
18
|
end
|
20
19
|
|
@@ -91,31 +90,31 @@ module Typeking
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def attempt_login(username)
|
94
|
-
|
93
|
+
begin
|
95
94
|
@currentUid = @userHashes[username] #update current user id to the username from the userhashes directory
|
96
95
|
@currentUserData = @userData[currentUid] #user data hash becomes hash from database
|
97
96
|
return "Hello #{@currentUserData[:name]}!" #user_login will puts this to terminal
|
98
|
-
|
97
|
+
rescue
|
99
98
|
return "You have not registered yet, please register first." #user_login will puts this to terminal
|
100
99
|
end
|
101
100
|
end
|
102
101
|
|
103
102
|
|
104
|
-
def display_leaders(leaderCount)
|
103
|
+
def display_leaders(leaderCount,leaderboardArr)
|
105
104
|
leaders = 0 #current number of users displayed on leaderboard
|
106
105
|
while leaders < leaderCount #loop while displayed leaders is less than actual users
|
107
|
-
leaderHash =
|
106
|
+
leaderHash = leaderboardArr[leaders] #creates new hash using leaders as the index as the highest score would start from index 0
|
108
107
|
puts "#{leaders+1}. #{leaderHash[:name]} - WPM: #{leaderHash[:high_score]}, Accuracy: #{leaderHash[:accuracy]}%, Worst Character: #{leaderHash[:worst_character]}" #uses hash to output leaderboards
|
109
108
|
leaders += 1 #increment leaders
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
113
112
|
def show_leaderboards
|
114
|
-
|
115
|
-
puts "No entries yet!" unless
|
116
|
-
|
117
|
-
|
118
|
-
leaderCount =
|
113
|
+
leaderboardArr = @userData.dup #creates a new duplicate array of all user data
|
114
|
+
puts "No entries yet!" unless leaderboardArr.count > 0 #output when no users in data
|
115
|
+
leaderboardArr.sort_by!{|w| w[:high_score]} #sort by ascending order
|
116
|
+
leaderboardArr = leaderboardArr.reverse #reverse order to descending
|
117
|
+
leaderCount = leaderboardArr.count #checks how many users are in the array
|
119
118
|
display_leaders(leaderCount) #calls method based on number of users
|
120
119
|
start_screen #return to starting screen
|
121
120
|
end
|
data/lib/typeking/version.rb
CHANGED