예제 #1
0
        private static void KeyPress(List <Entity> entities, ScoreKeeper playerScore)
        {
            int column = 0;

            switch (System.Console.ReadKey(true).Key)
            {
            case System.ConsoleKey.UpArrow:    column = 6;  break;

            case System.ConsoleKey.DownArrow:  column = 8; break;

            case System.ConsoleKey.LeftArrow:  column = 4;  break;

            case System.ConsoleKey.RightArrow: column = 10;  break;

            default: return;
            }


            Entity lowest = null;

            foreach (Entity e in entities)
            {
                if (e is Arrow a && a.GetX() == column)
                {
                    if (lowest == null)
                    {
                        lowest = a;
                    }
                    else
                    {
                        if (a.GetY() > lowest.GetY())
                        {
                            lowest = a;
                        }
                    }
                }
            }


            if (lowest != null)
            {
                playerScore.Hit(lowest.GetY() - 20);
                lowest.Delete();
            }
        }
예제 #2
0
        public static bool PlaySong(SongData songData)
        {
            Screen screen = new Screen(50, 22);

            Song        song        = new Song(songData.filePath, (uint)songData.BPM);
            ScoreKeeper playerScore = new ScoreKeeper();

            List <Entity> entities = new List <Entity>();

            Tile[,] tiles = new Tile[0, 0];

            entities.Add(new Fretboard());

            Stopwatch noteTimer = new Stopwatch();
            Stopwatch songTimer = new Stopwatch();

            int    time        = 15000 / songData.BPM;
            string notes       = songData.notes;
            int    currentNote = 22;

            song.Start();
            noteTimer.Start();
            songTimer.Start();

            SpawnNote(currentNote++, notes, entities, songData.noteTimeSeconds);
            while (songTimer.Elapsed.TotalSeconds <= songData.duration)
            {
                List <Entity> toDelete = new List <Entity>();

                if (noteTimer.Elapsed.TotalSeconds >= songData.noteTimeSeconds)
                {
                    SpawnNote(currentNote++, notes, entities, songData.noteTimeSeconds);
                    noteTimer.Restart();
                }

                foreach (Entity e in entities)
                {
                    e.Tick(screen, tiles);
                    e.Draw(screen);

                    if (e.Deleted())
                    {
                        toDelete.Add(e);
                    }
                }

                foreach (Entity e in toDelete)
                {
                    entities.Remove(e);
                    if (e is Arrow a)
                    {
                        if (a.Missed())
                        {
                            playerScore.Miss();
                        }
                    }
                }


                screen.PutInt((int)playerScore.GetScore(), 15, 0);
                screen.PutString(string.Format("Accuracy: {0:00}%", playerScore.GetAccuracy() * 100),
                                 15, 1);

                screen.Draw();
                screen.Clear(' ');

                if (System.Console.KeyAvailable)
                {
                    KeyPress(entities, playerScore);
                }

                //System.Threading.Thread.Sleep(GlobalConstants.SLEEP_OFFSET);
            }

            return(playerScore.GetAccuracy() >= 0.6);
        }