TAILIEUCHUNG - ActionScript 3.0 Game Programming University, Second Edition phần 7

Khi lớp học bắt đầu, nó tạo ra một bản sao của cụm từ bằng cách chạy nó thông qua chức năng thay thế bằng một biểu thức chính quy. Các biểu thức / [A-Za-z] / g phù hợp bất kỳ ký tự chữ cái (A đến Z và một z, trên toàn cầu). Nó thay thế những trận đấu bằng một gạch dưới: | Hangman Í331 package import . import . import . public class Hangman extends Sprite private var textDisplay TextField private var phrase String Imagination is more important than knowledge. - Albert Einstein private var shown String private var numWrong int When the class starts it creates a copy of the phrase by running it through the replace function with a regular expression. The expression A-Za-z g matches any letter character A to Z and a to z globally . It replaces these matches with an underscore public function Hangman create a copy of text with _ for each letter shown A-Za-z g _ numWrong 0 The text field we ll set up will use a simple text format for Courier font 30 point. It will set the width and height so that the text will not interfere with the hangman graphic to the right. NOTE The reason I chose Courier is that it is a monospaced font. This means that each letter has the same width. Other fonts have different widths for different letters for example l and w . By using a monospaced font the text characters will not change positions as we substitute letters for the underscores. set up the visible text field textDisplay new TextField new TextFormat Courier 30 400 200 true false shown addChild textDisplay The pressKey function will be assigned to the KEY_UP event for the stage listen for key presses pressKey Wow eBook 332 Chapter 9 Word Games Hangman and Word Search When the player presses a key we ll use the returned to get the letter pressed public function pressKey event KeyboardEvent get letter pressed var charPressed String After the letter is known the phrase is searched for any matches. We re careful to use toLowerCase so that the key pressed will match both upper- .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.