lxxyan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ```python= import random import keyboard import time resources_list = ['stone', 'metal', 'crystal', 'food', 'water', 'energy'] class Monster: def __init__(self, hp, dmg): self.resource = random.choice(resources_list) self.resource_count = random.randint(1, 5) self.hp = hp self.maxHP = hp self.dmg = dmg def monster_death(self): print('你擊敗了怪物!') class Player: def __init__(self, name, hp, dmg): self.isAlive = True self.round = 0 self.time = 0 self.name = name self.ship = 0 self.maxhp=hp self.hp = hp self.dmg = dmg self.base_dmg = dmg self.resources = {} for resource in resources_list: self.resources[resource] = 0 print(f'name = {self.name}, hp = {self.hp}, dmg = {self.dmg}') def get_dmg(self): self.dmg = self.base_dmg * (1.25 ** self.ship) def add_resource(self, resource, amount): self.resources[resource] += amount print(f"你獲得了 {resource} {amount}個!現在共有{self.resources[resource]}個") def explore_planet(self): print("\n正在尋找星球...") time.sleep(2) rand = random.random() ch = listen_keyboard(['w', 's', 'a', 'd', 'f']) if ch == 'f': self.display_resources() # self.add_resource("food", -5) # self.add_resource("water", -5) if rand < 0.2: #mob base = 5 + 5 * self.round mob_hp, mob_dmg = random.randint(2 * base, 4 * base), random.randint(base, 2 * base) print(f"遇見了一隻大型怪物...\n血量:{mob_hp}, 攻擊力:{mob_dmg}") self.space_battle(Monster(mob_hp, mob_dmg)) elif rand < 0.35: #light print("在路邊發現了一些亮點...要去看看嗎?\n (w: 前進, s: 回頭, a/d: 繞過去)") ch = listen_keyboard(['w', 's', 'a', 'd', 'f']) if ch == 'w': rand_num = random.random() if rand_num < 0.7: print("發現了一些資源!") time.sleep(0.5) count = random.randint(1, 3) resources = random.sample(resources_list, count) for resource in resources: self.add_resource(resource, random.randint(1, 5)) elif rand_num < 0.8: print("發現了怪物的便便") time.sleep(0.5) # elif rand_num <1: else: dhp = random.randint(10, self.maxhp // 5) self.hp -= dhp if self.hp <= 0: self.hp = 0 print(f"被打了!\n扣除{dhp}點血量!(你的血量剩下{self.hp})") time.sleep(0.5) if self.hp <= 0: self.player_death() elif ch == 's': print("你逃跑了,繼續探索星球") time.sleep(0.5) elif ch == 'a' or ch == 'd': print("你逃跑了,繼續探索星球") time.sleep(0.5) elif rand < 0.55: #cave print("你來到了一個星球,前方是一個洞窟,你要進去看看嗎?\n(w: 進入, s: 回頭, a/d: 繞過去)") ch = listen_keyboard(['w', 's', 'a', 'd']) if ch == 'w': print("你進入了洞窟,發現了一些資源!") self.add_resource("stone", random.randint(4, 8)) time.sleep(0.5) self.add_resource("metal", random.randint(2, 4)) time.sleep(0.5) self.add_resource("crystal", random.randint(1, 2)) time.sleep(0.5) elif ch == 's': print("你回頭離開了洞窟,繼續探索星球") time.sleep(0.5) elif ch == 'a' or ch == 'd': print("你繞過了洞窟,繼續探索星球") time.sleep(0.5) elif rand < 0.85: #trade print("遇到了商人,你要跟它交易嗎?") print("按下w交易,按下s離開") ch= listen_keyboard(['w','s']) if ch== 's': print("你選擇不要交易") pass if ch== 'w': print("你選擇繼續交易") if self.resources['stone'] > 10 and self.resources['metal'] > 10 : print("你要用10個石頭和10個金屬交易一個盾牌嗎\n,按下w:要,按下s:不要") time.sleep(0.2) ch = listen_keyboard(['w', 's']) if ch== 'w': print("血量上限增加100") self.maxhp+=100 self.hp += 100 print("當前生命上限為:", self.maxhp) print("當前生命值為:", self.hp) self.resources['stone'] -= 4 self.resources['metal'] -= 4 print("交易成功") if ch== 's': print("你選擇不要交易") elif self.resources['food'] > 10 and self.resources['water'] > 10: print("你需要增加攻擊力嗎\n","按下w:要,按下s:不要") time.sleep(0.2) ch = listen_keyboard(['w', 's']) if ch== 'w': print("攻擊力增加50") self.base_dmg +=50 self.get_dmg() print("當前攻擊力為:", self.dmg) self.resouces['food'] -= 3 self.add_resource('water', -3) # self.ship += 1 if ch== 's': print("你選擇不要交易") elif self.resources['energy'] <= 5 and self.resources['crystal'] <= 5 and self.resources['food'] >= 5 and self.resources['water'] >= 5: print("你要用5個水和5個食物來交換10個能量和5個水晶嗎)\n按下w:要,按下s:不要") time.sleep(0.2) ch = listen_keyboard(['w', 's']) if ch == 'w': print("增加10個能量和5個水晶") set("按下w交易,按下s離開") else: print("商人看你可憐,決定施捨你一些物品") for resource in random.sample(resources_list,random.randint(2,5)): self.add_resource(resource, random.randint(1, 3)) # elif self.resources['metal'] <= 9: # print("你需要增加5個金屬嗎?\n按下w:要,按下s:不要") # ch = listen_keyboard(['w', 's']) # if ch== 'w': # print("增加5個金屬") # self.add_resource('metal', 5) # elif ch == 's': # print("你選擇不要交易") # else: # print("你沒有足夠的材料") else: print("你什麼都沒發現...") time.sleep(0.5) self.time += 1 if self.time == 5: self.round += 1 self.time = 0 print(f"星球被探索完了,即將前往個星球!\n你現在擁有的資源:\n") time.sleep(0.5) self.display_resources() print(f"你現在的血量:{self.hp}") time.sleep(0.5) print(f"你現在的攻擊力:{self.dmg}") time.sleep(0.5) print("") if self.resources['crystal'] >= 20 and self.resources['metal'] > 15 and self.resources['energy'] >= 15: print("你想要消耗20水晶+15金屬+15能量來造一艘太空船嗎?\n按下w:要,按下s:不要)") ch = listen_keyboard(['w', 's', 'esc']) if ch == 'w': self.build_ship() # elif ch == 's' or ch == 'esc': # passp self.explore_planet() def space_battle(self, monster : Monster): print("你正在與怪物戰鬥...(space/w: 攻擊, esc: 逃跑)") time.sleep(0.5) while True: ch = listen_keyboard([' ', 'w', 'space', 'esc']) if ch == ' ' or ch == 'w' or ch == 'space': # print('你攻擊了怪物!') monster.hp -= self.dmg if monster.hp <= 0: monster.monster_death() self.resources[monster.resource] += monster.resource_count print(f"你獲得了 {monster.resource} {monster.resource_count}個!現在共有{self.resources[monster.resource]}個") return else: print(f"你對怪物造成了 {self.dmg}點傷害!怪物血量剩下 {monster.hp}點") self.hp -= monster.dmg if self.hp <= 0: self.hp = 0 print(f"怪物對你造成了 {monster.dmg}點傷害!你的血量剩下 {self.hp}點") if self.hp == 0: self.player_death() return elif ch == 'esc': if random.random() < 0.2: dhp = random.randint(monster.dmg // 10, monster.dmg // 2) self.hp -= dhp if self.hp <= 0: self.hp = 0 print(f'你嘗試逃跑,但很不幸的你被怪物追上了!\n他對你造成了{dhp}點傷害!(你的血量剩下{self.hp})') time.sleep(0.5) if self.hp <= 0: self.player_death() else: self.space_battle(monster) else: print("你成功逃跑了!") time.sleep(0.5) return else: print("請輸入有效指令!") time.sleep(0.1) time.sleep(0.2) def player_atk(self, monster : Monster): monster.hp -= self.dmg if monster.hp <= 0: monster.monster_death() self.resources[monster.resource] += monster.resource_count print(f"你獲得了 {monster.resource} {monster.resource_count}個!現在共有{self.resources[monster.resource]}個") else: print(f"你對怪物造成了 {self.dmg}點傷害!怪物血量剩下 {monster.hp}點") self.hp -= monster.dmg if self.hp <= 0: self.hp = 0 print(f"怪物對你造成了 {monster.dmg}點傷害!你的血量剩下 {self.hp}點") if self.hp == 0: self.player_death() def build_ship(self): # ch = listen_keyboard(['f']) self.minus_resource("crystal", 20) self.minus_resource("stone", 15) self.minus_resource("energy", 15) print("開始建造太空船...") self.ship += 1 print("你成功建造了一艘太空船!", "接下來的每次攻擊都有太空船的火力支援," "你的攻擊力上升了25%\n", sep='\n') self.get_dmg() print("當前攻擊力為:",self.dmg) # def trade(self): # n = random.randint(0, 4) # if n == 1: # print("你遇到商人了,要使用10個石頭和10個金屬交換5瓶水嗎") # if self.resources['stone'] > 10 and self.resoueces['metal'] > 10 : # elif n == 2: # def communicate(self, ): # random.choice(trade_communicate_list) def player_atk(self, monster : Monster): monster.hp -= self.dmg if monster.hp == 0: # re, re_c = monster.death self.resources[monster.resource] += monster.resource_count def add_resource(self, resource, amount): self.resources[resource] += amount print(f"你獲得了 {resource} {amount}個!現在共有{self.resources[resource]}個") def display_resources(self): print(f"\n-----玩家 {self.name} 的資源-----") for resource, amount in self.resources.items(): print(f'{resource}: {amount}') print("---------------------------\n") # time.sleep(1) # def on_key_press(event): # pass def player_death(self): print("很抱歉你死了!") exit() def listen_keyboard(listen_list): # listen_list = ['w', 'a', 's', 'd', 'space', 'esc'] while True: for ch in listen_list: if keyboard.is_pressed(ch): return ch print("歡迎來到太空生存遊戲!") # 創建玩家 name1=input("請輸入你的名字:") # print(name1) player1 = Player(name = name1, hp=500, dmg=50) print(f"已取名叫{player1.name}") time.sleep(0.5) print("這個遊戲的目標為盡量的存活下去,建造一艘太空船,探索星球並進行交易") time.sleep(0.5) print("你的初始資源為:") player1.display_resources() print(f"你的初始血量為:{player1.hp}") time.sleep(0.5) print(f"你的初始攻擊力為:{player1.dmg}\n") print( "你可以使用的指令有:", "w : 繼續移動", "s : 回頭/逃跑", "f : 顯示資源", "a/d : 向別處移動", "space : 進行互動", "esc : 離開交互\n", sep='\n' ) player1.explore_planet() # print("按下w繼續前進") # while True: # ch=listen_keyboard(['w','a','s','d']) # if ch == 'w': # print("繼續前進") # break # else : # print("沒差阿都不要走") ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully