diff --git a/task1/.editorconfig b/task1/.editorconfig new file mode 100644 index 0000000..6145179 --- /dev/null +++ b/task1/.editorconfig @@ -0,0 +1,15 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false + +[*.md] +trim_trailing_whitespace = false diff --git a/task1/.gitignore b/task1/.gitignore new file mode 100644 index 0000000..1f5a275 --- /dev/null +++ b/task1/.gitignore @@ -0,0 +1,2 @@ +*~* +**/_backup/* \ No newline at end of file diff --git a/task1/_docs.zip b/task1/_docs.zip new file mode 100644 index 0000000..9679110 --- /dev/null +++ b/task1/_docs.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab2ce035b8295687a3e52d71807f27d02dba4c0ac3016c21c70fde85822094de +size 6976 diff --git a/task1/_docs/change_password.drawio b/task1/_docs/change_password.drawio new file mode 100644 index 0000000..2d95409 --- /dev/null +++ b/task1/_docs/change_password.drawio @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_docs/create_player.drawio b/task1/_docs/create_player.drawio new file mode 100644 index 0000000..c91cf3c --- /dev/null +++ b/task1/_docs/create_player.drawio @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_docs/delete_player.drawio b/task1/_docs/delete_player.drawio new file mode 100644 index 0000000..4a04019 --- /dev/null +++ b/task1/_docs/delete_player.drawio @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_docs/draft.md b/task1/_docs/draft.md new file mode 100644 index 0000000..d632f48 --- /dev/null +++ b/task1/_docs/draft.md @@ -0,0 +1,124 @@ +### Player VS Computer + + 1. game mode select + 2. player vs computer + 3. player login (username and password) + 4. Game run (player vs computer) + 5. Game finish + 6. Show ranking + 7. Back to start + +```mermaid +graph TD; + A[Game Mode Select] --> B[Player vs Computer]; + B --> C["Player Login (Username and Password)"]; + C --> D["Game Run (Player vs Computer)"]; + D --> E[Game Finish]; + E --> F[Show Ranking?]; + F --> H[show ranking to user]; + H --> G[Back to Start]; + F --> G[Back to Start]; +``` + +### Player VS Player + + 1. game mode select + 2. player vs computer + 3. player1 login (username and password) + 3. player2 login (username and password) + 4. Game run (player vs computer) + 5. Game finish + 6. Show ranking + 7. Back to start + +```mermaid +graph TD; + A[Start] --> B[Game Mode Select]; + B --> C[Player VS Computer]; + C --> D["Player1 Login (username and password)"]; + D --> E["Player2 Login (username and password)"]; + E --> F["Game Run (Player VS Computer)"]; + F --> G[Game Finish]; + G --> H[Show Ranking?]; + H --> J[show ranking to user]; + H --> I[Back to Start]; + J --> I; + I --> A; +``` + +### show ranking + + 1. read ranking + 2. show to user + +```mermaid +graph TD; + A[Start] --> B[Read Ranking]; + B --> C[Show Ranking to User]; + C --> D[End]; +``` + +### change password + + 1. open password file `ac.txt` + 2. read passwords + 3. find current user + 4. change password when username match + 5. save to file + +```mermaid +graph TD; + A[Start] --> B["Open Password File ac.txt"]; + B --> C[Read Passwords]; + C --> D[Find Current User]; + D -->|Username Match| E[Change Password]; + D -->|Username Not Found| F[Display Error Message]; + E --> G[Save to File]; + G --> H[End]; + F --> H[End]; +``` + + +### create player + + 1. get username and password from user + 2. check if username or password is empty + 3. show missing to user if empty + 4. username and password ok + 5. write to account file + + +```mermaid +graph TD; + A[Start] --> B[Get Username and Password from User]; + B --> C[Check if Username or Password is Empty]; + C -->|Username or Password is Empty| D[Show Missing Fields to User]; + C -->|Username and Password are Not Empty| E[Write to Account File]; + D --> F[End]; + E --> F[End]; +``` + + +### delete player + + 1. open password file `ac.txt` + 2. read username + 3. if username found in file + 4. delete user + 5. write change to file + + +```mermaid +graph TD; + A[Start] --> B["Open Password File ac.txt"]; + B --> C[Read Username]; + C --> D[Username Found in File?]; + D -->|Yes| E[Delete User]; + D -->|No| F[Display Error Message]; + E --> G[Write Changes to File]; + G --> H[End]; + F --> H[End]; + A@{ shape: circle} + H@{ shape: circle} + D@{ shape: diamond } +``` \ No newline at end of file diff --git a/task1/_docs/player_vs_computer.drawio b/task1/_docs/player_vs_computer.drawio new file mode 100644 index 0000000..9ebab6a --- /dev/null +++ b/task1/_docs/player_vs_computer.drawio @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_docs/player_vs_player.drawio b/task1/_docs/player_vs_player.drawio new file mode 100644 index 0000000..9f986fa --- /dev/null +++ b/task1/_docs/player_vs_player.drawio @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_docs/show_ranking.drawio b/task1/_docs/show_ranking.drawio new file mode 100644 index 0000000..9aa011d --- /dev/null +++ b/task1/_docs/show_ranking.drawio @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task1/_from_client/Doc1.docx b/task1/_from_client/Doc1.docx new file mode 100644 index 0000000..85cc008 Binary files /dev/null and b/task1/_from_client/Doc1.docx differ diff --git a/task1/_from_client/Sba ict check (2).docx b/task1/_from_client/Sba ict check (2).docx new file mode 100644 index 0000000..f064f08 Binary files /dev/null and b/task1/_from_client/Sba ict check (2).docx differ diff --git a/task1/_from_client/_src/2023-24_S5_SBA_v2.docx.pdf b/task1/_from_client/_src/2023-24_S5_SBA_v2.docx.pdf new file mode 100644 index 0000000..67d3ce0 Binary files /dev/null and b/task1/_from_client/_src/2023-24_S5_SBA_v2.docx.pdf differ diff --git a/task1/_from_client/_src/tic tac toe haman vs pc.py b/task1/_from_client/_src/tic tac toe haman vs pc.py new file mode 100644 index 0000000..3f071f2 --- /dev/null +++ b/task1/_from_client/_src/tic tac toe haman vs pc.py @@ -0,0 +1,138 @@ +import tkinter +import random +import time + +masu = [ + [0, 0, 0], + [0, 0, 0], + [0, 0, 0] +] +shirushi = 0 +kachi = 0 +FNT = ("Times New Roman", 60) + +def masume(): + cvs.delete("all") + for i in range(1, 3): + cvs.create_line(200*i, 0, 200*i, 600, fill="gray", width=8) + cvs.create_line(0, i*200, 600, i*200, fill="gray", width=8) + for y in range(3): + for x in range(3): + X = x * 200 + Y = y * 200 + if masu[y][x] == 1: + cvs.create_oval(X+20, Y+20, X+180, Y+180, outline="blue", width=12) + if masu[y][x] == 2: + cvs.create_line(X+20, Y+20, X+180, Y+180, fill="red", width=12) + cvs.create_line(X+180, Y+20, X+20, Y+180, fill="red", width=12) + if shirushi == 0: + cvs.create_text(300, 300, text="遊戲開始!", fill="navy", font=FNT) + cvs.update() + +def click(e): + global shirushi + if shirushi == 9: + replay() + return + if shirushi==1 or shirushi==3 or shirushi==5 or shirushi==7: + return + mx = int(e.x/200) + my = int(e.y/200) + if mx>2: mx = 2 + if my>2: my = 2 + if masu[my][mx] == 0: + masu[my][mx] = 1 + shirushi = shirushi + 1 + masume() + time.sleep(0.5) + hantei() + syouhai() + if shirushi < 9: + computer() + masume() + time.sleep(0.5) + hantei() + syouhai() + +def computer(): + global shirushi + #有沒有連成一線的符號 + for y in range(3): + for x in range(3): + if masu[y][x] == 0: + masu[y][x] = 2 + hantei() + if kachi==2: + shirushi = shirushi + 1 + return + masu[y][x] = 0 + #阻止玩家連成一線 + for y in range(3): + for x in range(3): + if masu[y][x] == 0: + masu[y][x] = 1 + hantei() + if kachi==1: + masu[y][x] = 2 + shirushi = shirushi + 1 + return + masu[y][x] = 0 + while True: + x = random.randint(0, 2) + y = random.randint(0, 2) + if masu[y][x] == 0: + masu[y][x] = 2 + shirushi = shirushi + 1 + break + +def hantei(): + global kachi + kachi = 0 + for n in range(1, 3): + #判斷垂直方向是否連成一線 + if masu[0][0]==n and masu[1][0]==n and masu[2][0]==n: + kachi = n + if masu[0][1]==n and masu[1][1]==n and masu[2][1]==n: + kachi = n + if masu[0][2]==n and masu[1][2]==n and masu[2][2]==n: + kachi = n + #判斷水平方向是否連成一線 + if masu[0][0]==n and masu[0][1]==n and masu[0][2]==n: + kachi = n + if masu[1][0]==n and masu[1][1]==n and masu[1][2]==n: + kachi = n + if masu[2][0]==n and masu[2][1]==n and masu[2][2]==n: + kachi = n + #判斷傾斜方向是否連成一線 + if masu[0][0]==n and masu[1][1]==n and masu[2][2]==n: + kachi = n + if masu[0][2]==n and masu[1][1]==n and masu[2][0]==n: + kachi = n + +def syouhai(): + global shirushi + if kachi == 1: + cvs.create_text(300, 300, text="玩家獲勝!", font=FNT, fill="cyan") + shirushi = 9 + if kachi == 2: + cvs.create_text(300, 300, text="電腦\n獲勝!", font=FNT, fill="gold") + shirushi = 9 + if kachi == 0 and shirushi == 9: + cvs.create_text(300, 300, text="平手", font=FNT, fill="lime") + +def replay(): + global shirushi + shirushi = 0 + for y in range(3): + for x in range(3): + masu[y][x] = 0 + masume() + +root = tkinter.Tk() +root.title("井字遊戲") +root.resizable(False, False) +root.bind("