/// <summary> /// Plays the note using the current <see cref="IPlayer"/> for <see cref="Duration"/>ms /// </summary> public void PlayNote() { if (DesiredOctave > Frequencies.Count() - 1) { var error = new ArgumentException($"{DesiredOctave} is too high of an Octave to play {Key}", nameof(DesiredOctave)); Error?.Invoke(this, error); } else { try { string[] desiredChord = null; switch (ChordType) { case ChordType.Note: desiredChord = new string[] { Key }; break; case ChordType.Power: desiredChord = PowerChord; break; case ChordType.MinorThird: desiredChord = MinorChord3; break; case ChordType.MajorThird: desiredChord = MajorChord3; break; case ChordType.MinorSeventh: desiredChord = MinorChord7; break; case ChordType.MajorSeventh: desiredChord = MajorChord7; break; } PlayingNote?.Invoke(this, new EventArgs()); var musicNotes = desiredChord.Select(sn => MusicNote.Create(sn)); var frequencies = musicNotes.Select(mn => new FrequencyDuration(mn.Key, mn.DesiredOctave, mn.Frequencies[DesiredOctave], Duration)); NotePlayer?.Play(frequencies, Instrument); } catch (Exception ex) { Error?.Invoke(this, ex); } } }
public void ResetLevel(int level) { powerups.Clear(); Internals.Slot.Save("slot" + Program.Game.SaveSlotID + ".slt", Program.Game.SaveSlot); NotePlayer.PlayTuneSec(winTune); padPosition = 23; ballPosition = new Vector2(padPosition + (20 / padSize) / 2 - 1, 21); lastPosition = ballPosition; ballVelocity = new Vector2(2, -1); glue = false; padSize = 2; int ysize = level; int stlch = level; int emtch = 10 - level; if (level < 3) { ysize = 3; } if (level > 8) { ysize = 8; } if (emtch < 0) { emtch = 0; } if (stlch > 7) { stlch = 7; } for (int y = 0; y < 10; y++) { for (int x = 0; x < 15; x++) { if (y < ysize) { //brickMap[x, y] = Internals.Brick.Build(Internals.Brick.TYPES.GOLD); brickMap[x, y] = Internals.Brick.BuildRandom(emtch, stlch); } else { brickMap[x, y] = Internals.Brick.Build(Internals.Brick.TYPES.EMPTY); } } } }
private static void Main(string[] args) { Renderer.Init(); Renderer.WindowSize = new Vector2(80, 25); NotePlayer.Init(); App = new App(); App.Init(); _keyThread = new Thread(ConsoleKeyboard.CheckKey); _render = new Thread(RenderDraw); _keyThread.Start(); _render.Start(); while (Running) { Thread.Sleep(33); App.Update(); App.Draw(); } NotePlayer.Stop = true; _keyThread.Abort(); _render.Abort(); }
/// <summary> /// Plays the sequence of notes in <see cref="NoteSequence"/> /// </summary> public void Play() { if ((CompositeNotes?.Count() ?? 0) == 0) { PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent() { EventType = PlayableEventType.Error, EventDetails = "There are no notes to play" }); return; } var repeat = Repeat ?? 1; var message = $"Playing sequence of {CompositeNotes?.Count() ?? 0} notes {repeat} time(s)."; PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent() { EventType = PlayableEventType.StartSequence, EventDetails = message }); for (var counter = repeat; counter > 0; counter--) { foreach (var songNoteDuration in CompositeNotes) { try { NotePlayer.Play(songNoteDuration.Notes, InstrumentType); } catch (Exception ex) { PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent() { EventType = PlayableEventType.Error, EventDetails = $"{ex}" }); } } } PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent() { EventType = PlayableEventType.StopSequence, EventDetails = $"Finished playing {CompositeNotes.Count()} notes." }); }
private static void Main(string[] args) { Console.Clear(); Renderer.Init(); Renderer.WindowSize = new ConsoleGameUtilities.Vector2(54, 25); NotePlayer.Init(); game = new Game(); game.Init(); keyThread = new Thread(ConsoleKeyboard.CheckKey); render = new Thread(RenderDraw); keyThread.Start(); render.Start(); while (Running) { Thread.Sleep(33); game.Update(); game.Draw(); } NotePlayer.Stop = true; keyThread.Abort(); render.Abort(); }
public void PlayMusic() { NotePlayer.PlayTune(new Tunes.EndTune()); }
public static Player Start() { Player player = null; bool flag = true; int tryCounter; while (flag) { foreach (Player playerF in _Players) { switch (playerF.Type) { case "Обычный": IGame regularPlayer = new RegularPlayer(playerF.Name); _result = regularPlayer.Play(); _regularPlayerStats.Add(_result); player = playerF; break; case "Игрок-блокнот": IGame notePlayer = new NotePlayer(playerF.Name); _result = notePlayer.Play(); _notePlayerStats.Add(_result); player = playerF; break; case "Убер-игрок": IGame uberPlayer = new UberPlayer(playerF.Name); _result = uberPlayer.Play(); _uberPlayerStats.Add(_result); player = playerF; break; case "Читер": IGame cheaterPlayer = new CheaterPlayer(playerF.Name); _result = cheaterPlayer.Play(); _cheaterPlayerStats.Add(_result); player = playerF; break; case "Убер-читер": IGame uberCheaterPlayer = new UberCheaterPlayer(playerF.Name); _result = uberCheaterPlayer.Play(); _uberCheaterPlayerStats.Add(_result); player = playerF; break; } _tryCounter++; if (_tryCounter >= 100) { flag = false; player = null; break; } if (_result == _bucketWeight) { flag = false; break; } } } return(player); }
public void Update() { if (!_linePause) { int tempMax = (int)_timerMax; if (ConsoleKeyboard.KeyAvailable) { ConsoleKey key = ConsoleKeyboard.PressedKey; switch (key) { case ConsoleKey.W: case ConsoleKey.UpArrow: case ConsoleKey.Spacebar: RotateCheck(); break; case ConsoleKey.A: case ConsoleKey.LeftArrow: CheckMoveHorizontal(-1); break; case ConsoleKey.D: case ConsoleKey.RightArrow: CheckMoveHorizontal(+1); break; case ConsoleKey.S: case ConsoleKey.DownArrow: tempMax = 4; break; default: break; } } _timer++; if (_timer >= (int)((tempMax - _level) / 5)) { _timer = 0; if (CheckMoveVertical(1)) { _fails++; } else { Program.game.Score += 10; } if (_fails == 3) { _fails = 0; PlaceIntoMap(_currentBlock, _currentPos); GetNextCurrent(); GenerateNextBlock(); } } linesToRemove = new List <int>(); for (int y = 0; y < 20; y++) { bool mapLine = true; for (int x = 0; x < 10; x++) { if (!_map[x, y].Exists) { mapLine = false; } } if (mapLine) { linesToRemove.Add(y); _linePause = true; for (int x = 0; x < 10; x++) { _map[x, y].Color = Block.ColorToColor(Block.RandomColor()); _map[x, y].Special = true; _timer = 0; } } } } else { if (!played) { NotePlayer.PlayTuneSec(new Tunes.LineTune()); played = true; } ConsoleColor c = Block.ColorToColor(Block.RandomColor()); _timer++; foreach (int y in linesToRemove) { for (int x = 0; x < 10; x++) { _map[x, y].Color = c; } } if (_timer == 20) { _linePause = false; _level += (uint)linesToRemove.Count; Program.game.Score += 1000 * (ulong)Math.Pow(2, linesToRemove.Count); foreach (int y in linesToRemove) { for (int ry = y; ry >= 1; ry--) { for (int x = 0; x < 10; x++) { _map[x, ry] = new Cetris.Bit() { Color = _map[x, ry - 1].Color, Exists = _map[x, ry - 1].Exists, Special = _map[x, ry - 1].Special }; } } } played = false; linesToRemove.Clear(); } } }
static void Main(string[] args) { int size; string input; var rand = new Random(); var bucketWeight = rand.Next(40, 140); Console.WriteLine("Bucket weight: " + bucketWeight); do { Console.Write("1) Play \n2) Exit \n\nYour choice: "); input = Console.ReadLine(); int cases; Int_Digits_check(input, out cases); switch (cases) { case 1: Console.WriteLine("Starting"); Console.WriteLine("Enter the amount of players"); input = Console.ReadLine(); Borders(2, 8, input, out size); Player[] playersList = new Player[size]; for (int i = 0; i < size; i++) { Console.Write("Enter the type of player:\n 1) Simple player \n2) Note player \n3) Uber-player \n4) Cheater \n5) Uber-cheater \n6 Exit \n\nYour choice: "); input = Console.ReadLine(); Int_Digits_check(input, out cases); switch (cases) { case 1: Console.WriteLine("Simple player. Give him a name."); playersList[i] = new SimplePlayer(Console.ReadLine()); break; case 2: Console.WriteLine("Note player. Give him a name. "); playersList[i] = new NotePlayer(Console.ReadLine()); break; case 3: Console.WriteLine("Uber-player. Give him a name. "); playersList[i] = new UberPlayer(Console.ReadLine()); break; case 4: Console.WriteLine("Cheater. Give him a name. "); playersList[i] = new Cheater(Console.ReadLine()); break; case 5: Console.WriteLine("Uber-cheater. Give him a name. "); playersList[i] = new UberCheater(Console.ReadLine()); break; case 6: Console.WriteLine("Exit"); return; default: Console.WriteLine("Error. Choose the menu item again."); break; } } for (int i = 0; i < 100; i++) { foreach (Player s in playersList) { s.Guess(bucketWeight); } } int nearestValue = playersList[size - 1].niceTry; foreach (Player s in playersList) { if (Math.Abs(nearestValue - bucketWeight) > Math.Abs(s.niceTry - bucketWeight)) { nearestValue = s.niceTry; } } for (int i = 0; i < size; i++) { if (playersList[i].niceTry == nearestValue) { Console.WriteLine($"{playersList[i].Name} has won the game!"); } } break; case 2: Console.WriteLine("Exit"); return; default: Console.WriteLine("Error. Choose the menu item again."); break; } } while (true); }
public void PlayMusic() { NotePlayer.PlayTune(mainTune); }
public void Update() { bool dead = false; if (!_started) { ballPosition = new Vector2(padPosition + (20 / padSize) / 2 - 1, 21); } Console.Title = "Lives: " + Program.Game.SaveSlot.Lives; Console.Title += ", Level: " + Program.Game.SaveSlot.Level; Console.Title += ", Score: " + Program.Game.SaveSlot.Score; if (ConsoleKeyboard.KeyAvailable) { switch (ConsoleKeyboard.PressedKey) { case ConsoleKey.A: case ConsoleKey.LeftArrow: padPosition -= 2; if (padPosition <= 1) { padPosition = 1; } break; case ConsoleKey.D: case ConsoleKey.RightArrow: padPosition += 2; if (padPosition >= 54 - (20 / padSize)) { padPosition = 54 - (20 / padSize); } break; case ConsoleKey.Spacebar: if (!_started) { _started = true; } break; case ConsoleKey.Escape: Program.Game.SwitchScene(Game.SceneNames.PAUSE); break; } } if (_started) { timer++; if (timer == timerMax) { if ((ballPosition.X <= 1) && (ballVelocity.X < 0)) { ballVelocity.X *= -1; ballPosition.X = 1; } else if ((ballPosition.X >= 51) && (ballVelocity.X > 0)) { ballPosition.X = 51; ballVelocity.X *= -1; } if ((ballPosition.Y <= 1) && (ballVelocity.Y < 0)) { ballVelocity.Y *= -1; ballPosition.Y = 1; } else if ((ballPosition.Y >= 24) && (ballVelocity.Y > 0)) { //ballPosition.Y = 24; //ballVelocity.Y *= -1; dead = true; } Rectangle fakeRectangleBall = new Rectangle(ballPosition, 2, 2); Rectangle padFakeRectangleLeft = new Rectangle(padPosition, 23, (20 / padSize / 2), 1); Rectangle padFakeRectangleRight = new Rectangle(padPosition + (20 / padSize / 2), 23, (20 / padSize / 2), 1); int r = 0; if (fakeRectangleBall.Intersects(padFakeRectangleLeft)) { if (ballVelocity.X > 0) { ballVelocity.X *= -1; } ballVelocity.Y *= -1; r++; if (glue) { _started = false; } } if (fakeRectangleBall.Intersects(padFakeRectangleRight)) { r++; if (ballVelocity.X < 0) { ballVelocity.X *= -1; } if (r != 2) { ballVelocity.Y *= -1; } if (glue) { _started = false; } } for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { if (!brickMap[x, y].Empty) { Rectangle fakeRectangleBrick = new Rectangle(3 + x * 5, 2 + y * 2, 4, 1); if (fakeRectangleBall.Intersects(fakeRectangleBrick)) { Program.Game.SaveSlot.Score += 10; bool dst = brickMap[x, y].DoDemage(); if (dst) { brickMap[x, y].Empty = true; Program.Game.SaveSlot.Score += 90; NotePlayer.PlayTuneSec(brickDestTune); int chn = Program.Random.Next(0, 4); if (chn == 1) { Internals.Powerup pu = Internals.Powerup.BuildRandom(); pu.pos = new Vector2(x, y * 2); powerups.Add(pu); } } else { if (brickMap[x, y].MaxHP == -1) { NotePlayer.PlayTuneSec(brickSteelTune); } else { NotePlayer.PlayTuneSec(brickNormTune); } } if ((!dst || (brickMap[x, y].DestroyBehavior != Internals.Brick.DESTBEH.NONE))) { Rectangle fakeRectangleBallHorOnl = new Rectangle(new Vector2(ballPosition.X, lastPosition.Y), 2, 2); if (fakeRectangleBallHorOnl.Intersects(fakeRectangleBrick)) { ballVelocity.X *= -1; } else { ballVelocity.Y *= -1; } } } } } } lastPosition = new Vector2(ballPosition.X, ballPosition.Y); ballPosition += ballVelocity; foreach (Internals.Powerup pu in powerups) { if (pu.pos.Y < 30) { pu.half += 0.4f; if (pu.half > 1) { pu.pos.Y++; pu.half = 0; } Rectangle padFakeRectangle = new Rectangle(padPosition, 23, 20 / padSize, 1); Rectangle powerupRectangle = new Rectangle(3 + pu.pos.X * 5, 2 + pu.pos.Y, 4, 1); if (padFakeRectangle.Intersects(powerupRectangle)) { switch (pu.type) { case Internals.Powerup.TYPES.BIGGER: padSize = 1; break; case Internals.Powerup.TYPES.GLUE: glue = true; break; case Internals.Powerup.TYPES.LIVEDOWN: dead = true; break; case Internals.Powerup.TYPES.LIVEUP: Program.Game.SaveSlot.Lives++; break; case Internals.Powerup.TYPES.SMALLER: padSize = 3; break; } pu.pos.Y += 30; } } } if (dead) { Program.Game.SaveSlot.Lives--; if (Program.Game.SaveSlot.Lives < 1) { NotePlayer.PlayTuneSec(endTune); while (NotePlayer.Paused) { ; } Program.Game.ReturnInf = Program.Game.SaveSlot.Score; Program.Game.Return = 0; Program.Game.SwitchScene(Game.SceneNames.HIGHSCORE); } else { ResetLevel(Program.Game.SaveSlot.Level); } } timer = 0; bool empty = true; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { if ((brickMap[x, y].Empty) || (brickMap[x, y].MaxHP == -1)) { ; } else { empty = false; } } } if (empty) { Program.Game.SaveSlot.Level++; ResetLevel(Program.Game.SaveSlot.Level + 1); } } } }
public void PlayMusic() { NotePlayer.PlayTune(mini); }
// Start is called before the first frame update IEnumerator Start() { notePlayer = FindObjectOfType <NotePlayer>(); playerHealth = FindObjectOfType <PlayerController>().GetComponent <Health>(); gameMessageLine1.text = ""; //round = defaultRound; //yield return new WaitForSeconds(1); SetupRoundData(); print("Game Started"); while (!gameIsOver) { print("=== START OF THE ROUND ==="); playerHasAnswered = false; roundNumber++; roundsRemainingUI.text = "(" + roundNumber + "/" + totalNumberOfRounds + ")"; // Wait Entry time yield return(new WaitForSeconds(roundEnterTime)); // Play Note PianoKey.Note note = PlayRandomNote(); print("Random note: " + note); // Wait for input... yield return(new WaitUntil(() => playerHasAnswered == true)); // Check to see if input matches the note bool correctGuess = false; correctGuess = (note == playerGuess) ? true : false; // If the guess is incorrect, player takes damage if (correctGuess) { FindObjectOfType <PlayerController>().Boost(); } else { TakeDamage(wrongGuessDamage); } // Check if the player is dead if (playerHealth.IsDead()) { gameIsOver = true; gameMessageLine1.text = "LOSE!"; } // Check if we have played all the rounds if (roundNumber >= totalNumberOfRounds) { gameIsOver = true; gameMessageLine1.text = "WIN!"; } print("=== END OF THE ROUND ==="); yield return(new WaitForSeconds(roundLeaveTime)); } }
public void Setup() { _player = new NotePlayer(); }
public void PlayMusic() { NotePlayer.PlayTune(new Tunes.ScoreTune()); }