Pythonのハングマンゲーム?
ハングマンは、参加者が時間がなくなる前にできるだけ多くの秘密の単語を推測する必要がある古典的なワードゲームです!ですから、一度に1文字ずつ、新しい単語を学ぶのは素晴らしいゲームです!
そこで、この古典的なゲーム「hangman」のPythonスクリプトを作成します。
#importing the time module
import time
#welcoming the user
name = input("What is your name? ")
print("Hello, " + name, "Time to play hangman!")
print ("")
#wait for 1 second
time.sleep(1)
print ("Start guessing...")
time.sleep(0.5)
#here we set the secret
word= ("Secret")
word = word.lower()
#creates an variable with an empty value
guesses = ''
#determine the number of turns
turns = 12
# Create a while loop
#check if the turns are more than zero
while turns > 0:
# make a counter that starts with zero
failed = 0
# for every character in secret_word
for char in word:
# see if the character is in the players guess
if char in guesses:
# print then out the character
print (char, )
else:
# if not found, print a dash
print ("_",)
# and increase the failed counter with one
failed += 1
# if failed is equal to zero
# print You Won
if failed == 0:
print ("You won" )
# exit the script
break
print
# ask the user go guess a character
guess = input("guess a character:")
# set the players guess to guesses
guesses += guess
# if the guess is not found in the secret word
if guess not in word:
# turns counter decreases with 1 (now 9)
turns -= 1
# print wrong
print ("Wrong")
# how many turns are left
print("You have", + turns, 'more guesses' )
# if the turns are equal to zero
if turns == 0:
# print "You Loose"
print ("You Loose") 出力
================== RESTART: C:\Python\Python361\hangman1.py ================== What is your name? Raj Hello, Raj Time to play hangman! Start guessing... _ _ _ _ _ _ guess a character:s s _ _ _ _ _ guess a character:h Wrong You have 11 more guesses s _ _ _ _ _ guess a character:e s e _ _ e _ guess a character:c s e c _ e _ guess a character:r s e c r e _ guess a character:e s e c r e _ guess a character:t s e c r e t You won >>>
-
Pythonを使用したコンウェイのライフゲーム?
1970年頃の英国の数学者は、彼の「ライフゲーム」を作成しました。これは基本的に、生物のコロニーの混沌とした、しかしパターン化された成長を描いた一連のルールです。 「GameofLife」は、「生きている」細胞と「死んでいる」細胞で構成される2次元グリッドです。 人生ゲームのルール 人口過多 :細胞が3つ以上の生きている細胞に囲まれている場合、細胞は死にます(オフ)。 静的 :細胞が2つまたは3つの生きている細胞に囲まれている場合、その細胞は生きています。 過少人口 :細胞が2つ未満の生きている細胞に囲まれている場合、細胞は死にます(オフになります)。 複製 :死ん
-
PythonでTkinterを使用したカラーゲーム
GUIアプリケーションの開発では、tkinterは非常に人気があり簡単です。 tkinterを使用すると、GUIゲームを簡単に開発できます。 ここでもカラーゲームの開発を試みています。このゲームでは、プレーヤーは画面に表示される単語の色を入力する必要があるため、スコアが1つ増えます。このゲームをプレイする合計時間は、30秒で、このゲームで使用される色は、赤、青、緑、ピンク、ブラック、イエロー、オレンジ、ホワイト、パープル、ブラウン。インターフェイスには、さまざまな色の名前がさまざまな色で表示されます。ゲームに勝つには、ユーザーは色を識別し、正しい色の名前を入力する必要があります。 サンプルコ