Provide immediate feedback for each mistyped sentence.
To do so, modify the Test class’s present_test method so that it
informs the player a mistake has been made, then display the
challenge sentence followed by the player’s sentence so the player
can determine where the error lies.
#--------------------------------------------------------------------------
#
# Script Name: TypingChallenge.rb
# Version: 1.0
# Author: Jerry Lee Ford, Jr.
# Date: March 2010
#
# Description: This Ruby script demonstrates how to apply
conditional logic
#
in order to analyze user input and control script
execution
#
through the development of a computer typing test that
#
evaluates the player's typing skills.
#
#--------------------------------------------------------------------------
# Define custom classes ---------------------------------------------------
#Define a class representing the console window
class Screen
def cls #Define a method that clears the
display area
puts ("\n" * 25) #Scroll the screen 25
times
puts "\a" #Make a little noise to get the
player's attention
end
def pause #Define a method that pauses the
display area
STDIN.gets #Execute the STDIN class's gets
method to pause script
#execution until the player presses the Enter key
end
end
#Define a class representing the typing test
class Test
#This method displays the 8-ball greeting
message
def display_greeting
Console_Screen.cls #Clear the display
area
#Display a welcome screen
print "\t\t Welcome to the Ruby Typing
Challenge game!" +
"\n\n\n\n\n\n\n\n\n\n\n\n\nPress Enter to "
+
"continue. \n\n: "
Console_Screen.pause
#Pause the game
end
#Define a method to be used to present test
instructions
def display_instructions
Console_Screen.cls #Clear the
display area
puts "\t\t\tInstructions:\n\n" #Display a
heading
#Display the game's
instructions
puts %Q{ This test consists of
a series of 5 typing challenges.
The challenge sentences are presented one at a
time. To respond
correctly, you must retype each sentence exactly
as shown and press
the Enter key. Your grade will be displayed at
the end of the test.
\n\n\n\n\n\n\n\n\n
Press Enter to continue.\n\n}
Console_Screen.pause #Pause the
game
end
#Define a method to be used to present typing
challenges
def present_test(challenge)
Console_Screen.cls #Clear the
display area
print challenge + "\n\n: " #Display the
challenge sentence
result = STDIN.gets #Collect the player's
input
result.chop!
#Remove the end of line marker
#Analyze the player input and see if it is
correct
if challenge == result then
#Keep track of the number of
correctly retyped challenge sentences
$noRight += 1
Console_Screen.cls #Clear the
display area
#Keep the player informed
print "Correct!\n\nPress Enter to
continue."
Console_Screen.pause #Pause the
game
else
Console_Screen.cls #Clear the
display area
#Keep the player informed
print "Incorrect!\n\nPress Enter to
continue."
Console_Screen.pause #Clear the
game
end
end
#Define a method to be used to display test
results
def determine_grade
Console_Screen.cls #Clear the
display area
#To pass the test the player must correctly
retype 3 sentences
if $noRight >= 3 then
#Inform the player of the good
news
print "You retyped " + $noRight.to_s
+ " sentence(s) correctly. "
puts "You have passed the typing
test!\n\nPress Enter to continue."
else #The player has failed the test
#Inform the player of the bad
news
print "You retyped " + $noRight.to_s
+ " sentence(s) correctly. "
puts "You have failed the typing
test!\n\nPress Enter to continue."
end
end
end
# Main Script Logic -------------------------------------------------------
#Initialize global variable that will be used to keep
track of the number
#of correctly retyped sentences
$noRight = 0
Console_Screen = Screen.new #Instantiate a new
Screen object
Typing_Test = Test.new
#Instantiate a new Test object
#Execute the Test object's display_greeting
method
Typing_Test.display_greeting
#Execute the Screen object's cls method in order to
clear the screen
Console_Screen.cls
#Prompt the player for permission to begin the
test
print "Would you like to test your typing skills? (y/n)\n\n: "
answer = STDIN.gets #Collect the player's
response
answer.chop! #Remove any extra characters appended to the
string
#Loop until the player enters y or n and do not accept any other
input.
until answer == "y" || answer == "n"
Console_Screen.cls #Clear the display area
#Prompt the player for permission to begin the test
class Screen
def cls
puts ("\n" * 30)
puts "\a"
end
def pause
STDIN.gets
end
end
class Test
def display_greeting
Console_Screen.cls
print "\t\t Welcome to the Ruby Typing Challenge
Game!" +
"\n\n\n\n\n\n\n\n\n Press
Enter to " +
"continue. \n\n: "
Console_Screen.pause
end
def display_instruction
Console_Screen.cls
puts "\t\t\t\tInstruction: \n\n"
puts %Q{This test has 5 typing challenges.
Type exactly same as sentences. Your grade will be shown at the end
of the test. \n\n\
press Enter to continue. \n\n }
Console_Screen.pause
end
def present_test(challenge)
Console_Screen.cls
print challenge + "\n\n: "
result = STDIN.gets
result.chop!
if challenge == result then
$noRight += 1
Console_Screen.cls
print "Corrcet!\n\n
Press Enter to continue."
Console_Screen.pause
else
Console_Screen.cls
print "Incorrect!\n\n
Press Enter to continue."
Console_Screen.pause
end
end
def determine_grade
Console_Screen.cls
if $noRight >= 3 then
print "You retyped " + $noRight.to_s + " sentence(s)
correctly. "
puts "You have passed the typing test!\n\n Press Enter
to continue."
else
print "You retyped " + $noRight.to_s + " sentence(s)
correctly. "
puts "You have failed the typing test!\n\nPress enter
to continue."
end
end
$noRight = 0
Console_Screen = Screen.new
Typing_Test = Test.new
Typing_Test.display_greeting
Console_Screen.cls
print "Would you like to test your typing skills? (y/n) \n\n: "
answer = STDIN.gets
answer.chop!
until answer =="y" || answer == "n"
Console_Screen.cls
print "Would you like to test your typing skills? (y/n) \n\n:
"
answer = STDIN.gets
answer.chop!
end
if answer == "n"
Console_Screen.cls
puts "Okay, perhaps another time.\n\n"
else
Typing_Test.display_instruction
Typing_Test.present_test "In the end there can be only one."
Typing_Test.present_test "hello there."
Typing_Test.present_test "how are you?"
Typing_Test.present_test "Chicago is awesome!!"
Typing_Test.determine_grade
Console_Screen.pause
Console_Screen.cls
puts "Thank you for playing Ruby Typing Challenge game.\n\n"
end
end
Provide immediate feedback for each mistyped sentence. To do so, modify the Test class’s present_test method...
Currently, the game allows players to play as many times as they wish. It does not provide any feedback on how the players are doing, however. Modify the game so that it keeps track of the number of games played as well as the average number of guesses made per game. To implement this change, add the following list of global variables to the beginning of the script’s Main Script Logic section. Assign each variable an initial value of zero....
The game lets players know whether they have won, lost, or tied a particular game. Modify the game so the players are told the number of games they have won, lost or tied since the start of game play. Implement this change by adding three variables named $wins, $lost, and $ties to the program's Main Script Logic section, assigning each an initial value of 0. Next, modify the analyze_results method by adding programming logic that increments the values of $wins,...
I need help finishing this excerise this is what I have: I get this output for an error: RPS_ExerciseE1.rb:171:in `+': no implicit conversion of nil into String (TypeError) from RPS_ExerciseE1.rb:171:in `display_results' from RPS_ExerciseE1.rb:89:in `play_game' from RPS_ExerciseE1.rb:240:in `block in <main>' from RPS_ExerciseE1.rb:237:in `loop' from RPS_ExerciseE1.rb:237:in `<main>' Currently, the Game class’s get_player_move method uses a regular expression to validate the player’s moves of Rock, Paper, or Scissors, rejecting any input other than one of these words. Making the player enter entire words...
Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...
Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...
Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...
Missing multiple labeled functions. Card matching game in C. Shouldn't need any more functions. I am lost on how to complete the main function (play_card_match) without the sub functions complete. The program runs fine as is, but does not actually have a working turn system. It should display question marks on unflipped cards when the player is taking a turn and should also clear the screen so the player can't scroll up to cheat. Thank you #include "cardMatch.h" //main function /*...
C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...
please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...
C#: Implement a multiplayer Battleship game with AI The rules are the same as before. The game is played on an NxN grid. Each player will place a specified collection of ships: The ships will vary in length (size) from 2 to 5; There can be any number or any size ship. There may be no ships of a particular size; EXCEPT the battleship – which there will always be 1 and only 1. Player order will be random but...