public override GameElement Create(string element) { ElementType type; if (!Enum.TryParse(element.ToUpper().Replace(' ', '_'), out type)) { return(null); } GameElement gameElement = null; switch (type) { case ElementType.BUTTON: gameElement = Instantiate(m_ButtonTemplate).GetComponent <GameButton>(); break; case ElementType.TEXT_FIELD: gameElement = Instantiate(m_FieldTemplate).GetComponent <GameTextField>(); break; case ElementType.IMAGE: gameElement = Instantiate(m_ImageTemplate).GetComponent <GameImage>(); break; } gameElement.Type = type; GameElements.Add(gameElement); return(gameElement); }
private IEnumerator ActivateBackground() { TextController.ActivateCanvas(false); yield return(new WaitForSecondsRealtime(1)); GameElements.GetComponent <SpriteRenderer>().enabled = true; }
public MainMenuState(GameWindow owner, GameFiniteStateMachine parent) : base(owner, parent) { var startButton = new TextElement(owner, "start", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.4f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; startButton.Clicked += args => { if (Transitioning) { return; } TransitionOut("start"); }; var settingsButton = new TextElement(owner, "settings", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.15f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; settingsButton.Clicked += args => { if (Transitioning) { return; } TransitionOut("settings"); }; var exitButton = new TextElement(owner, "exit", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, 0.1f), Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 50f } }, MouseOverColor = Color4.White }; exitButton.Clicked += args => StateMachine.Transition("exit"); GameElements.Add(new TextElement(owner, "Apoplexy", ".\\fonts\\toxica.ttf", 72f) { NormalColor = Color4.DarkRed, Behaviours = { { GameTriggers.MouseMove, FloatBehavior } }, AttachedProperties = { { FLOATINESS_PROP, 25f } }, Position = new Vector2(0f, -0.75f) }); GameElements.Add(startButton); GameElements.Add(exitButton); GameElements.Add(settingsButton); }
public static string GetMenuCommand() { bool isTrue = true; while (isTrue) { Console.Write($" Press key: "); switch (Console.ReadKey(true).Key) { case ConsoleKey.Escape: return("EXIT"); case ConsoleKey.Spacebar: return("PLAY"); case ConsoleKey.I: return("INSTRUCTIONS"); case ConsoleKey.S: return("STATISTICS"); default: Console.WriteLine(GameElements.GetInvalidMessage()); break; } } return(null); }
public override void Load() { World = World.Load("world.dat"); _countries = World.Countries.Where(o => o.Cities.Count >= 2).ToList(); _cities = _countries.SelectMany(o => o.Cities).ToArray(); _points = _cities.Select(GenBufferElement).ToArray(); Scaling(out _scale, out _add, out _bounds); TransformPoints(_scale, _add); _highways = GenHighways(_scale, _add); Action prep = () => { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.VertexPointer(2, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0)); GL.ColorPointer(4, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector2.SizeInBytes)); }; _pathBufferElement = new VboElement <BufferElement>(Owner, null, PrimitiveType.Lines); GameElements.Add(_pathBufferElement); GameElements.Add(new VboElement <BufferElement>(Owner, new VertexBuffer <BufferElement>(_highways, prep), PrimitiveType.Lines)); _citiesVboElement = new VboElement <BufferElement>(Owner, new VertexBuffer <BufferElement>(_points, prep), PrimitiveType.Points); GameElements.Add(_citiesVboElement); GameElements.Add(_debugText); GameElements.Add(_pathText); base.Load(); _debugText.Font.Options.Monospacing = QFontMonospacing.Yes; SetViewport(); Scheduler.TickItems.Add(new TickItem(UpdatePath, new TimeSpan(0, 0, 0, 0, 250), true)); Scheduler.TickItems.Add(new TickItem(UpdateVbos, new TimeSpan(0, 0, 0, 0, 1000 / 30))); }
public SettingMenuState(GameWindow owner, GameFiniteStateMachine parent) : base(owner, parent) { var uiElementBehavior = new Behaviour <UiElementBase>(o => { var floatPos = BehaviorHelpers.EaseMouse(o.MousePosition); o.PositionAdd = floatPos / ((float)o.AttachedProperties["floatiness"]); }); var exitButton = new TextElement(owner, "return", ".\\fonts\\toxica.ttf", 40f) { NormalColor = Color4.Gray, Position = new Vector2(0f, -0.15f), Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 50f } }, MouseOverColor = Color4.White, }; exitButton.Clicked += args => TransitionOut("return"); GameElements.Add(new TextElement(owner, "Settings", ".\\fonts\\toxica.ttf", 72f) { NormalColor = Color4.DarkRed, Behaviours = { { GameTriggers.MouseMove, uiElementBehavior } }, AttachedProperties = { { "floatiness", 25f } }, Position = new Vector2(0f, -0.75f) }); GameElements.Add(new TextElement(owner, "alpha 0.1", ".\\fonts\\pixelmix.ttf", 12f) { Position = new Vector2(0.8f, 0.9f), Alignment = QFontAlignment.Left }); GameElements.Add(exitButton); }
public void AddElements <T>(GameElements <T> collection) where T : BasePlacement, new() { var cells = collection.GetPlacements(Field); foreach (var cell in cells) { Field.GetCell(cell.IndexRow, cell.IndexColumn).AddGameElement(collection.Element); } }
protected override void Start() { base.Start(); GameElements.SetActive(true); DisableCameraAndMovement(); GameElements.SetActive(false); StartCoroutine(PlayOpeningCutscene(4, 3)); StartCoroutine(EnableCameraAndMovementAfterDelay()); }
public void KeyUp(KeyboardKeyEventArgs e) { GameElements.OfType <IKeyboardInput>().ForEach(o => o.KeyUp(e)); if (e.Key == Key.Escape) { StateMachine.Transition("pause"); } }
public virtual void KeyDown(KeyboardKeyEventArgs e) { GameElements.OfType <IKeyboardInput>().ForEach(o => o.KeyDown(e)); if (e.Key == Key.Escape) { TransitionOut("return"); } }
/// <summary> /// löscht ein Element /// </summary> public void DeleteElement(int id) { //wenn noch nichts geladen wurde darf auch nichts verändert werden if (!loadingComplete) { return; } GameElements.Remove(id); deleteElementEvent(id); }
protected override void Start() { base.Start(); GameElements.SetActive(true); DisableCameraAndMovement(); GameElements.SetActive(false); spawnedSpiders = new List <GameObject>(); StartCoroutine(PlayOpeningCutScene()); dani.OnNextPhase += ChangeFightPhase; }
private IEnumerator SwordRoomCutscene() { GameElements.GetComponent <SpriteRenderer>().sprite = SwordRoom; yield return(ActivateBackground()); Stars.enabled = true; Dani.SetActive(true); Girls.SetActive(true); yield return(new WaitForSecondsRealtime(2.8f)); }
/// <summary> /// Gets the top most element of the list of game elements. /// </summary> /// <returns>The top most GameElement.</returns> public GameElement GetTopElement() { if (GameElements.Count > 0) { return(GameElements.First()); } else { return(null); } }
public static void PlayIntro() { Thread.Sleep(1000); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Thread.Sleep(1000); Console.WriteLine(GameElements.GetMenu()); Thread.Sleep(1000); }
/// <summary> /// setzt X-Position eines GameElements, wird beim Laden aufgerufen /// </summary> public void SetPosX(int id, float posX) { if (GameElements.ContainsKey(id)) { GameElements[id].PosX = posX; } else { GameElements[id] = new GameElement { PosX = posX }; } }
/// <summary> /// setzt Y-Position eines GameElements, wird beim Laden aufgerufen /// </summary> public void SetPosY(int id, float posY) { if (GameElements.ContainsKey(id)) { GameElements[id].PosY = posY; } else { GameElements[id] = new GameElement { PosY = posY }; } }
/// <summary> /// Sets all cards same face. /// </summary> /// <param name="faceUp">if set to <c>true</c> [face up].</param> public void SetAllCardsSameFace(bool faceUp) { if (GameElements.First() is Card) { foreach (Card card in GameElements) { if (card.FaceUp != faceUp) { card.Flip(); } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); GameElements.LoadContent(Content, Window); mapEditor = new LevelObjects.LevelEditor(); // Load the textures into the texture handler textures = new The_scroll_of_NOPE.Content.TextureHandler(Content); #region Jonatan, load map // FOR DEBUG PUSPOSES tmpTexture = Content.Load<Texture2D>("images/ANKA/ANKA"); try { // Load the default map levelLayout = mapEditor.LoadMap("defaultMap"); // If it could not load because there probably was no defaultMap if (levelLayout == null) { // Create new map and save it to a file levelLayout = new LevelObjects.LevelLayout(Content); mapEditor.SaveMap(levelLayout, "defaultMap"); } } // Textures probably did not load properly // TODO: Fix the deserialization and serialization of textures catch { levelLayout = new LevelObjects.LevelLayout(Content); } #endregion anka = new BaseClasses.Players.ANKA(1, Content.Load<Texture2D>("images/ANKA/SpriteTest"/*SpriteTest skall vara ANKA*/), new Vector2(50, 50), 5, 10000); testStudent = new Student1(Content.Load<Texture2D>("images/Students/PlayerTemp"), new Vector2(0, 0), 7, Content, new Vector2(5, 5)); // TODO: use this.Content to load your game content here collidables.Add(anka); collidables.Add(levelLayout); collidables.Add(testStudent); // For drawing text font = Content.Load<SpriteFont>("Text/Score"); winFont = Content.Load<SpriteFont>("Text/Win"); // for drawing whatever }
/// <summary> /// setzt Typ eines GameElements, wird beim Laden aufgerufen, abhängig davon wird später das Bild geladen /// </summary> public void SetType(int id, string type) { ElementType elementType = (ElementType)Enum.Parse(typeof(ElementType), type); if (GameElements.ContainsKey(id)) { GameElements[id].Type = elementType; } else { GameElements[id] = new GameElement { Type = elementType }; } }
private static void PrintGameplayUI(Player player, Player opponent, int stage) { Console.Clear(); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Console.WriteLine($" Opponent:"); Console.WriteLine(player.OpponentBattlefield.ToString()); Console.WriteLine($" You:"); Console.WriteLine(player.PlayerBattlefield.ToString()); //Console.WriteLine($" What Opponent sees:"); //Console.WriteLine(opponent.OpponentBattlefield.ToString()); Console.WriteLine(GameElements.GetLegend()); Console.WriteLine(GameElements.GetLineSolid()); Console.WriteLine(GameElements.GetCredits()); Console.WriteLine($"\n Stage {stage}"); }
public void Shuffle() { List <GameElement> sortingList = new List <GameElement>(); var rnd = new Random(); foreach (var gameElement in GameElements) { sortingList.Insert(rnd.Next(sortingList.Count + 1), gameElement); } GameElements.Clear(); foreach (var gameElement in sortingList) { GameElements.Add(gameElement); } }
public static void ShowStatistics() { Console.Clear(); Thread.Sleep(1000); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Thread.Sleep(1000); Console.WriteLine(GameElements.GetStatistics()); Thread.Sleep(3000); Console.WriteLine(GameElements.GetPressKeyMessage()); Console.ReadKey(); Console.Clear(); }
/// <summary> /// setzt Y-Position eines GameElements, wird beim Laden aufgerufen /// </summary> public void SetPosY(int id, float posY) { //wenn schon geladen wurde verarbeite keine weitere Ladenachricht if (loadingComplete) { return; } if (GameElements.ContainsKey(id)) { GameElements[id].PosY = posY; } else { GameElements[id] = new GameElement { PosY = posY }; } }
/// <summary> /// setzt Typ eines GameElements, wird beim Laden aufgerufen, abhängig davon wird später das Bild geladen /// </summary> public void SetType(int id, string type) { //wenn schon geladen wurde verarbeite keine weitere Ladenachricht if (loadingComplete) { return; } ElementType elementType = (ElementType)Enum.Parse(typeof(ElementType), type); if (GameElements.ContainsKey(id)) { GameElements[id].Type = elementType; } else { GameElements[id] = new GameElement { Type = elementType }; } }
/// <summary> /// CTOR /// </summary> /// <param name="PlayField_Width"></param> /// <param name="PlayField_Height"></param> public GameField(int PlayField_Width, int PlayField_Height, GameElements[,] playField = null, int x_ballposition = 1, int y_ballposition = 1) { // Save dimensions and create PLAYFIELD Width = PlayField_Width; Height = PlayField_Height; // Reset BALL position BallPosition_X_W = x_ballposition; BallPosition_Y_H = y_ballposition; // Create NEW game or Load with given if (playField == null) { PlayField = new GameElements[PlayField_Width, PlayField_Height]; return; } else { PlayField = playField; } // Reset all fields to Empty blocks for (int w = 0; w < Width; w++) { for (int h = 0; h < Height; h++) { // if it is a BORDER if ((w == 0) || (h == 0) || (w == Width - 1) || (h == Height - 1)) { PlayField[w, h] = GameElements.Border; } else { PlayField[w, h] = GameElements.Empty; } } } }
//clears everything and starts a new game (reinitialize) public void StartGame() { Components.Clear(); // game objective objDetermine = Random.Next(3); switch (objDetermine) { case 0: gameObj = Objective.Scientist; break; case 1: gameObj = Objective.Bomb; break; default: gameObj = Objective.Elimination; break; } objTimer = 0; objShow = true; objRoom = Random.Next(10, 18); objRoom2 = Random.Next(18); while (objRoom2 == objRoom) { objRoom2 = Random.Next(18); } objEliminate = 40; heliRoom = Random.Next(0, 9); player = new PlayerSprite(this, "Images//playerWalk", new Vector2(GlobalClass.ScreenWidth / 2, GlobalClass.ScreenHeight / 2), 2, 6, this); gridNumbers = new List <int>(Enumerable.Range(0, 9)); Shuffle(gridNumbers); street0 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.White, 0); street1 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightBlue, 1); street2 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightCoral, 2); street3 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGoldenrodYellow, 3); street4 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGreen, 4); street5 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGray, 5); street6 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightPink, 6); street7 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightSteelBlue, 7); street8 = new Room(this, "Images//Maps//External//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightSeaGreen, 8); room0 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.White, 9); room1 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightBlue, 10); room2 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightCoral, 11); room3 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGoldenrodYellow, 12); room4 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGreen, 13); room5 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightGray, 14); room6 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightPink, 15); room7 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightSteelBlue, 16); room8 = new Room(this, "Images//Maps//Internal//test01", new Vector2(100, 100), 1, 1, false, false, player, Color.LightSeaGreen, 17); //add rooms to game Components.Add(street0); Components.Add(player); //Add game components Components.Add(new Enemy(this, "Images//enemyWalk", new Vector2(200, 200), 2, 5)); elements = new GameElements(this, player); elements.Initialize(); camera = new Camera(this); //Splashscreen component splashScreen = new SplashScreen(this); menuScreen = new MenuScreen(this); pauseScreen = new PauseScreen(this); endScreen = new EndScreen(this); tutScreen = new TutScreen(this); Components.Add(splashScreen); Components.Add(menuScreen); Components.Add(pauseScreen); Components.Add(endScreen); Components.Add(tutScreen); }
public static void ShowInstructions() { Console.Clear(); Thread.Sleep(1000); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Battlefield instructionsBattlefield = BattlefieldGenerator.GenerateNewBattlefield(); Thread.Sleep(1000); Console.WriteLine($" Instructions:"); Thread.Sleep(1000); Console.WriteLine(instructionsBattlefield.ToString()); Thread.Sleep(1000); Console.WriteLine(GameElements.GetLegend()); Thread.Sleep(3000); Console.WriteLine(" Both opponents should place"); Thread.Sleep(750); Console.WriteLine(" - 1 tanker (TTTT),"); Thread.Sleep(750); Console.WriteLine(" - 2 submarines (SSS),"); Thread.Sleep(750); Console.WriteLine(" - 3 carriers (CC),"); Thread.Sleep(750); Console.WriteLine(" - 4 boats (B) on their field."); Thread.Sleep(1500); Console.WriteLine("\n The 4 boats (B) can be placed "); Thread.Sleep(750); Console.WriteLine(" anywhere."); Thread.Sleep(750); Console.WriteLine(" The other vessels should be"); Thread.Sleep(750); Console.WriteLine(" placed in such a way that"); Thread.Sleep(750); Console.WriteLine(" 0 or 1 of its modules lay on"); Thread.Sleep(750); Console.WriteLine(" the sides/edges of the field."); Thread.Sleep(5000); Console.Clear(); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Console.WriteLine($" Instructions:"); Console.WriteLine($" ╔═══╦═════════════════════╗"); Console.WriteLine($" ║ ║ A B C D E F G H I J ║"); Console.WriteLine($" ╠═══╬═════════════════════╣"); for (int row = 0; row < 10; row++) { Console.Write($" ║ {row} ║ "); for (int col = 0; col < 10; col++) { if ((row == 2 && col == 0) || (row == 2 && col == 1) || (row == 2 && col == 2) || (row == 2 && col == 3)) // DRAW CORRECT TANKER (TTTT) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("T "); } else if ((row == 0 && col == 9)) // DRAW CORRECT BOAT (B) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("B "); } else if ((row == 9 && col == 5) || (row == 9 && col == 6) || (row == 9 && col == 7)) // DRAW INCORRECT SUBMARINE (SSS) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("S "); } else if ((row == 8 && col == 0) || (row == 9 && col == 0)) // DRAW INCORRECT CARRIER (CC) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("C "); } else // DRAW EMPTY SLOT { Console.Write(" "); } Console.ForegroundColor = ConsoleColor.Cyan; } Console.Write("║\n"); } Console.WriteLine($" ╚═══╩═════════════════════╝"); Console.WriteLine(GameElements.GetLegend()); Thread.Sleep(1000); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\n CORRECT."); Thread.Sleep(1000); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"\n NOT CORRECT!!!"); Console.ForegroundColor = ConsoleColor.Cyan; Thread.Sleep(5000); Console.WriteLine(GameElements.GetPressKeyMessage()); Console.ReadKey(); Console.Clear(); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Console.WriteLine($" Instructions:"); Console.WriteLine(instructionsBattlefield.ToString()); Console.WriteLine(GameElements.GetLegend()); Thread.Sleep(3000); Console.WriteLine(" There should be at least 1 "); Thread.Sleep(750); Console.WriteLine(" empty slot between 2 vessels "); Thread.Sleep(750); Console.WriteLine(" placed on the field."); Thread.Sleep(1500); Console.WriteLine("\n In other words, 2 vessels "); Thread.Sleep(750); Console.WriteLine(" cannot \"touch\"."); Thread.Sleep(5000); Console.Clear(); Console.WriteLine(GameElements.GetTitle()); Console.WriteLine(GameElements.GetLineSolid()); Console.WriteLine($" Instructions:"); Console.WriteLine($" ╔═══╦═════════════════════╗"); Console.WriteLine($" ║ ║ A B C D E F G H I J ║"); Console.WriteLine($" ╠═══╬═════════════════════╣"); for (int row = 0; row < 10; row++) { Console.Write($" ║ {row} ║ "); for (int col = 0; col < 10; col++) { if ((row == 2 && col == 3) || (row == 2 && col == 4) || (row == 2 && col == 5) || (row == 2 && col == 6)) // DRAW INCORRECT TANKER (TTTT) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("K "); } else if ((row == 4 && col == 1) || (row == 4 && col == 2) || (row == 4 && col == 3)) // DRAW CORRECT SUBMARINE (SSS) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("S "); } else if ((row == 3 && col == 7) || (row == 4 && col == 7) || (row == 5 && col == 7)) // DRAW INCORRECT SUBMARINE (SSS) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("S "); } else if ((row == 2 && col == 1)) // DRAW CORRECT BOAT (B) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("B "); } else if ((row == 9 && col == 2)) // DRAW INCORRECT BOAT (B) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("B "); } else if ((row == 8 && col == 3) || (row == 9 && col == 3)) // DRAW INCORRECT CARRIER (CC) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("C "); } else if ((row == 6 && col == 1) || (row == 7 && col == 1)) // DRAW CORRECT CARRIER (CC) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("C "); } else // DRAW EMPTY SLOT { Console.Write(" "); } Console.ForegroundColor = ConsoleColor.Cyan; } Console.Write("║\n"); } Console.WriteLine($" ╚═══╩═════════════════════╝"); Console.WriteLine(GameElements.GetLegend()); Thread.Sleep(1000); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\n CORRECT.\n"); Thread.Sleep(1000); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($" NOT CORRECT!!!"); Console.ForegroundColor = ConsoleColor.Cyan; Thread.Sleep(5000); Console.WriteLine(GameElements.GetPressKeyMessage()); Console.ReadKey(); Console.Clear(); }
public static void PlayGame() { int stage = 1; Player player = new Player(); Player opponent = new Player(); while (true) { while (true) { PrintGameplayUI(player, opponent, stage); Random myRandom = new Random(); int rowRandom; int colRandom; while (true) { rowRandom = myRandom.Next(0, 10); colRandom = myRandom.Next(0, 10); if (opponent.OpponentBattlefield.Field[rowRandom, colRandom] == BattlefieldElements.slotHidden) { break; } } string playerAttackedSlotResult = player.GetAttacked(rowRandom, colRandom); opponent.BotAttack(rowRandom, colRandom, playerAttackedSlotResult); Console.WriteLine($" Opponent" + opponent.GetAttackMessage(playerAttackedSlotResult)); Thread.Sleep(1000); if (opponent.CheckIfWinner()) { break; } if (BattlefieldElements.slotsVessels.Contains(playerAttackedSlotResult)) { if (BattlefieldValidator.CheckIfSlotIsOnEdge(rowRandom, colRandom)) { player.MarkShipOnEdgeAsDestroyed(rowRandom, colRandom, playerAttackedSlotResult); } continue; } else { break; } } // OPPONENT ATTACKS, PLAYER GETS ATTACKED if (opponent.CheckIfWinner()) { break; } //GAME ENDS - YOU WIN while (true) { PrintGameplayUI(player, opponent, stage); int row = -1; int col = -1; while (true) { Console.Write($" Attack (i.e. A0/a0): "); string command = Console.ReadLine(); if (command.Length != 2) { Console.WriteLine(GameElements.GetInvalidMessage()); continue; } else { char colChar = command[0]; if (colChar >= 'A' && colChar <= 'J') { col = colChar - 'A'; } else if (colChar >= 'a' && colChar <= 'j') { col = colChar - 'a'; } else { Console.WriteLine(GameElements.GetInvalidMessage()); continue; } char rowChar = command[1]; if (rowChar - '0' >= 0 && rowChar - '0' <= 9) { row = rowChar - '0'; } else { Console.WriteLine(GameElements.GetInvalidMessage()); continue; } break; } } // GET CORRECT INPUT string opponentAttackedSlotResult = opponent.GetAttacked(row, col); player.Attack(row, col, opponentAttackedSlotResult); Console.WriteLine($" You" + player.GetAttackMessage(opponentAttackedSlotResult)); Thread.Sleep(1000); if (player.CheckIfWinner()) { break; } if (BattlefieldElements.slotsVessels.Contains(opponentAttackedSlotResult)) { continue; } else { break; } } // PLAYER ATTACKS, OPPONENT GETS ATTACKED if (player.CheckIfWinner()) { break; } stage++; // END OF STAGE } PrintGameplayUI(player, opponent, stage); bool isWinner = false; if (player.CheckIfWinner()) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n ~CONGRATULATIONS! YOU WON!~"); isWinner = true; } // YOU WON else if (opponent.CheckIfWinner()) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\n ~CONDOLENCES... YOU LOST!~"); } // YOU LOST Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"\n The game took {stage} stages."); Thread.Sleep(5000); Console.Clear(); UpdateDatabaseStatistics(isWinner); }
public virtual void MouseUp(MouseButtonEventArgs e) { GameElements.OfType <IMouseInput>().ForEach(o => o.MouseUp(e)); }