SlideShare uma empresa Scribd logo
1 de 20
ソフトウェア制作実験
「脳トレしりとりゲーム」
3班 / 1W182141-0 近藤智美
作成したプログラム
の概要
概要
4文字縛り、相手の単語の最後の二文字から始まる言葉を答える
というルールのしりとりゲーム
自分側で開くmyShiritori.javaと対戦相手が実行するoppShiritori.java、そして
ゲームの機能の構成要素としてGame.java、Player.java、Judge.java、
Message.javaを作成
ひらがなのみを打ち込んで解答
相手の単語が日本語に存在しないと考えた場合、自分のターンに「審議」と入
力することで相手の単語を変えさせることができる
日本語が含まれるため、コンパイル時にUTF8でエンコードする必要がある
(javac -encoding UTF-8 ○○.java)
Messageクラス
 勝ち負けの文章をString型で返す関数
 ルール説明を表示させる関数
 ゲームのように、文章を一文字ずつ時間差で表示する関数
Judgeクラス
 引数で与えられた単語
を解析する
エラー番号をクラス変数で記憶
「審議」の時 ErrorNum = 0
4文字でないとき ErrorNum = 1
しりとりになっていない
もしくは3文字目が”ん”のとき
ErrorNum = 2
Playerクラス
 プレイヤーに関する関数
を持つクラス
 順番を決めるための乱数
生成も行う
生成した乱数を格納
自分の順番を記憶
キーボードで入力された
名前をnameに格納
一番最近自分が送った単語
もし入力が「審議」だった場合
審議の前に入力していた単語をxに
コピーしておく
Gameクラス
 ゲーム進行に必要な機
能を持つ
自分と相手のPlayerオブジェクトを格納
ゲームの状態を格納
(-1ならクライアント側の勝ち、2ならサーバー側の勝ち、
100なら審議発令中)
乱数生成と先攻後攻の決定
Gameが作成されると自分と相手のPlayerを作成し、
自分の名前を登録させる
最初の単語を”しりとり”にセット
相手の単語をJudgeクラスで解析させて、statusを更新
myShiritori.java
ープログラムの
流れー
• サーバー側としてソケッ
ト通信を行う
 順番に必要な機能を呼び
出していく
1. ソケット通信の開始
2. ゲームオブジェクトを作成(同時に名前の登録が行われる)
3. ルール説明が流れる
4. 乱数を用いて先攻後攻を決め、相手にも同じメッセージを送信
5. 最初の単語を「しりとり」に設定
6. 相手が送った単語が正しいか判定
7. ゲームステータスに応じて条件判断
8. クライアント側に今から何をするかを送信
9. 条件に応じてメッセージを送受信
10. 勝敗が決まったらエラーメッセージを表示してゲーム終了
(通信も終了する)
myShiritori.java
ープログラム前半ー
ポート番号は8080で固定
エラー文を配列に格納しておく
ゲームオブジェクトの作成
相手の名前を通信で受け取る
myShiritori.java
ープログラム後半ー
(一部)
相手の単語がルール通りかチェック
ゲームのステータスを確認
これから何をするのかを
クライアントに送る
相手の入力を登録
oppShiritori.java
ープログラムの
流れー
• クライアント側としてソ
ケット通信を行う
 ゲームに関する処理は行わ
ない
 送られたメッセージの表示
と自分の情報の送信のみ
1. サーバーに接続
2. 自分の名前を入力してサーバーに送る
3. ルール説明が流れる
4. 決定した順番や最初の文字はしりとりだという、サーバーから送
られてきたメッセージを表示
5. サーバーから次に何を行うかのメッセージを受け取る
6. メッセージに応じて条件分岐し、受け取ったメッセージを表示し
たり自分の入力を送信したりする
7. finishが送られてくると終了動作に入る
8. 最後に勝ち負けのメッセージを受信し、表示して通信を終了する
oppShiritori.java
ープログラム前半ー
(一部)
ポート番号は8080で固定
同じLAN内のPCで対戦することも可
自分の名前を登録・送信
oppShiritori.java
ープログラム後半ー
(一部)
相手のターンの場合
サーバーからの指示を待つ
自分のターンの場合
自分か相手のどちらかが間違った単語を
送信した場合
相手が「審議」を送信した場合
自分が「審議」を送信した場合
作成したプログラム
の実行
実行環境
 Windows 10 Pro バージョン 1909
 Visual Studio Code バージョン 1.45.1
 java version "14.0.1"
 ターミナルを分割して実行
順番が決定するまで
サーバー側のプログラムを実行
対戦相手の名前が表示されている
クライアント側のプログラムを実行
ルール説明が1文字ずつ時間差で現れる
どちらが先攻後攻か表示されている
入力からゲーム終了(文字数が違う)
1. サーバー側が入力(先攻)
2. サーバー側の入力が表示される
3. クライアント側が入力(後攻)
4. クライアント側の入力が表示される
5. クライアント側がおかしな単語を送信
6. サーバー側が「審議」を発令
7. 「審議」がうまく動作した旨のメッセージ
8. 相手が審議を
申し立てた旨の通知
9.新しい単語を送信
10.文字数の異なる単語を送信
11.エラー文と勝敗メッセージの表示
入力からゲーム終了(しりとりになっていない)
最後の2文字から始まらない
言葉を返してしまった
3文字目が「ん」である
言葉を返してしまった
工夫した
ところ
サーバー側でゲームを進行させ、クライアント側はopp.java
とMessage.javaだけあれば実行できるようにした
「審議」機能を実装することで、相手にずるさせないように
した
見た目を楽しく読みやすくするため、ルール説明の文章は
RPGゲームのように、一文字ずつ順に表示させるようにした
クライアント側に今から何をするかを送信することで、正常
に文字のやり取りができるようにした
ゲームオブジェクトにステータスを表す変数を持たせること
で、次に何を実行するかを末端のクラスからサーバーに伝え
るのが容易になった

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ソフトウェア制作実験「脳トレしりとりゲーム」