チーム2117

課題名

Audio Typing

研究者名

Hoshitaro Onishi
Sota Ogawa

概要

Audio Typingはローマ字入力形式のタイピングゲーム!!
正解すると音階が上がっていく!
2回間違えるとゲームオーバー
ゲームオーバーせずに1オクターブ演奏できるかな??

~~~~~~~出題内容~~~~~~~
[Level1] int
[Level2] swift
[Level3] python
[Level4] fortran
[Level5] swiching
[Level6] javascript
[Level7] objective
[Level8] programming

パラメータ

コメント 2021-05-18 163723.jpg
コメント 2021-05-18 163644.jpg
コメント 2021-05-18 163520.jpg
コメント 2021-05-18 163259.jpg
コメント 2021-05-18 163232.jpg
コメント 2021-05-18 163058.jpg

使用機器

Psoc基板 1
ジャンパー線 2
キーボード 1
MiniProg 1
VGAケーブル 1
スピーカー 1


ソースコード


#include <m8c.h>
#include <stdio.h>
#include <string.h>
#include "PSoCAPI.h"
#include <stdlib.h>
#pragma interrupt_handler myISR

int PW=125; // Pulse Width
int SILENT=0, D=229, L=204, M=182, F=172, S=153, R=136, C=121, DD=115; //Scale
int sec1=0; //全体の制限時間
int TC=0;
char d[9];

void myISR(void)
{
TC += 1;
 PWM16_1_WritePulseWidth(PW);
 LCD_1_Start();
 LCD_1_Position(0,0);
 LCD_1_PrCString("Start!");
 LCD_1_Position(1,0);
 if(TC==200){
   PWM16_1_WritePeriod(SILENT);
   LCD_1_Position(0,0);
   LCD_1_PrCString("Finish!");
  }
}

void main(void){
  int count = 0; //ステージ数のカウント用
  char temp[20]; //文字判別時に用いる
  char *strPtr; 
  char *p;
  char tmp;
  char *sec;
  UART_CmdReset(); // Initialize receiver/cmd buffer
   UART_IntCntl(UART_ENABLE_RX_INT); // Enable RX interrupts
   Counter8_WritePeriod(155); // Set up baud rate generator
   Counter8_WriteCompareValue(77);
   Counter8_Start(); // Turn on baud rate generator
   UART_Start(UART_PARITY_NONE); // Enable UART
   M8C_EnableGInt ; // Turn on interrupts
   PWM16_1_Start();
   Timer16_1_EnableInt();
   Timer16_1_Start();
   UART_CPutString("\r\nPSoC Typing Game V2.0 \r\n");
  UART_CPutString("\r\nLv.1 [int]\r\n");
  
  
  
   while(1) {
       if(UART_bCmdCheck()) { // Wait for command
          if(TC>1){
              PWM16_1_WritePeriod(SILENT);
              UART_CPutString("\r\nGAME OVER\r\n");
           }
          if(strPtr = UART_szGetParam()) { // More than delimiter?
              int i;
              p = strPtr;
              for(i = 0; i < 20; i++){
                   temp[i] = *p;
                   p++;
               }        
              UART_PutString(strPtr); // Print out command
              if (temp[0]=='i' && temp[1]=='n' && temp[2]=='t' && temp[3]==NULL && count == 0){
                  PWM16_1_WritePeriod(D);
                  count++;
                  UART_CPutString("\r\nLv.2 [swift]\r\n");
              }
              else if(temp[0]=='s' && temp[1]=='w' && temp[2]=='i' && temp[3]=='f' && temp[4]=='t' && temp[5]==NULL && count == 1){
                  PWM16_1_WritePeriod(L);
                  count++;
                  UART_CPutString("\r\nLv.3 [python]\r\n");
              }
              else if(temp[0]=='p' && temp[1]=='y' && temp[2]=='t' && temp[3]=='h' && temp[4]=='o' && temp[5]=='n' && temp[6]==NULL && count == 2){
                  PWM16_1_WritePeriod(M);
                  count++;
                  UART_CPutString("\r\nLv.4 [fortran]\r\n");
              }
              else if(temp[0]=='f' && temp[1]=='o' && temp[2]=='r' && temp[3]=='t' && temp[4]=='r' && temp[5]=='a' && temp[6]=='n'
&& temp[7]==NULL && count == 3){
                 PWM16_1_WritePeriod(F);
                  count++;
                  UART_CPutString("\r\nLv.5 [swiching]\r\n");
              }
              else if(temp[0]=='s' && temp[1]=='w' && temp[2]=='i' && temp[3]=='c' && temp[4]=='h' && temp[5]=='i' && temp[6]=='n'
&& temp[7]=='g' && count == 4){
                 PWM16_1_WritePeriod(S);
                  count++;
                  UART_CPutString("\r\nLv.6 [javascript]\r\n");
              }
              else if(temp[0]=='j' && temp[1]=='a' && temp[2]=='v' && temp[3]=='a' && temp[4]=='s' && temp[5]=='c' && temp[6]=='r'
&& temp[7]=='i' && temp[8]=='p' && temp[9]=='t' && temp[10]==NULL && count == 5){
                 PWM16_1_WritePeriod(R);
                  count++;
                  UART_CPutString("\r\nLv.7 [objective]\r\n");
              }
              else if(temp[0]=='o' && temp[1]=='b' && temp[2]=='j' && temp[3]=='e' && temp[4]=='c' && temp[5]=='t' && temp[6]=='i'
&& temp[7]=='v' && temp[8]=='e' && temp[9]==NULL && count == 6){
                 PWM16_1_WritePeriod(C);
                  count++;
                  UART_CPutString("\r\nLv.Max [programming]\r\n");
              }
              else if(temp[0]=='p' && temp[1]=='r' && temp[2]=='o' && temp[3]=='g' && temp[4]=='r' && temp[5]=='a' && temp[6]=='m'
&& temp[7]=='m' && temp[8]=='i' && temp[9]=='n' && temp[10]=='g' && temp[11]==NULL && count == 7){
                 PWM16_1_WritePeriod(DD);
                  count++;
                  UART_CPutString("\r\nCongratulatios!!!");
                  UART_CPutString("\r\nPlease push Reset.\r\n");
              }
               else if (*strPtr=='Q'){
                  PWM16_1_WritePeriod(SILENT);
              }
              else{
                  UART_CPutString("\r\nMiss!!!!\r\n");
                  TC += 1;
              }
          }
           UART_CmdReset(); // Reset command buffer
       }
   }
}

考察

チーム1932とチーム2062、pwm_uart2を参考に制作した。

初めはチーム1932の拡張機能として制限時間&ゲームオーバー機能付きのタイピングゲームを作成しようとしてチーム2062を参考にして秒数を表示させるコードをソースコード内に追加したが、プロパティの設定違いか原因はわからないが何かしらのミスでTera Term上に秒数を表示させる変数sec1の表示が上手くいかなかった。TAにも相談したが解決できなかった。だが痕跡を残すためにコードは残しておいた。

そのため今回はチーム1932のタイムアタック形式のタイピングゲームに拡張機能として間違えた回数を記録する変数を設けて、ある一定数を超えたときにゲームオーバーとなる機能を付けた。それとゲームオーバー時にGAME OVERという文字を表示させ強制的に演奏を終了するような機能も追加させた。

それとチーム1932の方では入力した文字列をchar型の配列に格納し、それと正解の文字列を一文字ずつ比較していたが、最後の文字のあとに続く文字が一致しているかの確認がないため、正解判定が少し甘かった。そのため今回char型の配列での正解判定の際に最後の文字の後ろにif文でNULLを用いて一言一句、文字列が一致していないと正解にならないように機能をアップデートさせた。

  • 最終更新:2021-05-18 16:16:16

このWIKIを編集するにはパスワード入力が必要です

認証パスワード