internal void Replace(string idToUpdate, Rock rock) { if (rock == null) { throw new ArgumentNullException("rock"); } int index = IndexOf(idToUpdate); if (index == -1) { throw new ArgumentException("Supplied ID not found in collection."); } //Remove the rock from the collection. Rocks.RemoveAt(index); //Verify the (possibly changed) ID not in collection already if (IndexOf(rock.UniqueId) != -1) { throw new ArgumentException("A rock with the specified ID already exists in the collection."); } //Insert the new rock at the same place. Rocks.Insert(index, rock); }
public override void LoadContent() { //We are using StateManager to manage the States of the game, which operates like a stack spriteBatch = new SpriteBatch(StateManager.GraphicsDevice); playerShip1 = new PlayerShip(StateManager.Game); playerShip1.Initialize(); activeLasers = new LinkedList <Laser>(); activeRocks = new LinkedList <Rocks>(); Rocks rock1 = new Rocks(StateManager.Game, 600, 50, (float)(Math.PI / 180), 1, 3); rock1.Initialize(); activeRocks.AddLast(rock1); //Rocks rock2 = new Rocks(StateManager.Game, 300, 300, (float)(135 * Math.PI / 180), 1, 3); //rock2.Initialize(); //activeRocks.AddLast(rock2); //Rocks rock3 = new Rocks(StateManager.Game, 0, 0, (float)(90 * Math.PI / 180), 1, 3); //rock3.Initialize(); //activeRocks.AddLast(rock3); //Rocks rock4= new Rocks(StateManager.Game, 400, 400, (float)(300* Math.PI / 180), 1, 3); //rock4.Initialize(); //activeRocks.AddLast(rock4); //Rocks rock5 = new Rocks(StateManager.Game, 10, 600, (float)(200 * Math.PI / 180), 1, 3); //rock5.Initialize(); //activeRocks.AddLast(rock5); activeEnemyShips = new LinkedList <EnemyShip>(); }
public bool CollideswithElements(Snake snake, Rocks rock) { bool flag = false; for (int i = 0; i < snake.SnakeBody.Count; i++) { if (this.AppleCoords.EqualCoords(snake.SnakeBody[i])) { flag = true; break; } } if (flag == false) { for (int i = 0; i < rock.AllRocks.Count; i++) { if (this.AppleCoords.EqualCoords(rock.AllRocks[i])) { flag = true; break; } } } this.Exists = true; return(flag); }
static void Main() { Console.CursorVisible = false; Console.BufferWidth = Console.WindowWidth = 50; Console.BufferHeight = Console.WindowHeight = 30; Coords direction = new Coords(0, -1); Apple apple = new Apple(); Rocks rock = new Rocks(); Snake snake = new Snake(); WelcomeMessage(); DrawBoarder(); // Game Loop while (!isGameOver) { ResetWindowSize(); Console.ForegroundColor = ConsoleColor.Black; // just so you cant write in the console Input(direction); rock.Update(snake, apple); apple.Update(snake, rock); snake.Update(direction, apple, rock); apple.Draw(); rock.Draw(); snake.Draw(direction); speed = ChangeSpeed(score, speed); Thread.Sleep(speed); snake.Delete(); apple.Delete(); } Console.Clear(); Console.SetCursorPosition(20, 6); Console.WriteLine("GAME OVER!"); Console.SetCursorPosition(18, 8); Console.WriteLine("Your Score: " + score); // for replay Console.SetCursorPosition(17, 10); Console.WriteLine("Replay ? (Y / N)"); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) { direction = new Coords(0, -1); apple = new Apple(); snake = new Snake(); isGameOver = false; score = 0; speed = 100; GC.Collect(); Console.Clear(); Main(); } else { return; } }
public object Clone() { Rocks clonedItem = new Rocks(null, this.Name, this.ItemValue); clonedItem.Type = Type; clonedItem.SortingLayer = SortingLayer; clonedItem.Count = Count; return(clonedItem); }
internal int IndexOf(string selectedID) { Rock r = Rocks.FirstOrDefault((a) => a.UniqueId == selectedID); if (r == null) { return(-1); } return(Rocks.IndexOf(r)); }
public void Update(Snake snake, Rocks rock) { if (this.timeSinceLastSpawn + this.respawnTime < Environment.TickCount) { do { this.AppleCoords.x = rng.Next(2, Console.WindowWidth - 2); this.AppleCoords.y = rng.Next(2, Console.WindowHeight - 2); }while (this.CollideswithElements(snake, rock)); this.timeSinceLastSpawn = Environment.TickCount; } }
public void CmdBuildRock(GameObject tile) { GameObject bsObj = Instantiate(Resources.Load <GameObject>("NetworkPrefabs/Rocks"), tile.transform.position, Quaternion.identity); Rocks bS = bsObj.GetComponent <Rocks>(); NetworkServer.Spawn(bsObj); bS.parentId = tile.GetComponent <NetworkIdentity>().netId; bsObj.transform.parent = tile.transform; //bsObj.transform.Translate(Vector3.back); bS.OnBuild(); Cmds.i.RpcBuild(tile, bsObj); }
private void SetupRocks() => Enumerable.Range(0, Settings.RockCount) .ToList() .ForEach(_ => { var rock = Instantiate( Resources.Load("Rocks/" + Settings.MapType.ToString() + "/Large_" + UnityEngine.Random.Range(1, 5)), GetFixedPosition(GetValidPosition(), -1.0f), Quaternion.Euler(-90, UnityEngine.Random.Range(0, 360), 0)) as GameObject; rock.transform.parent = RocksParentGameObject; rock.transform.localScale = new Vector3(UnityEngine.Random.Range(1, 4), UnityEngine.Random.Range(1, 4), UnityEngine.Random.Range(1, 4)); Rocks.Add(rock.transform); });
static void InitiallyAddingRocks() { // Add a few rocks for (int i = 0; i < rnd.Next(15, 30); i++) { Rocks newRock; do { newRock = new Rocks(rnd.Next(1, Console.WindowWidth - 1), rnd.Next(0, 5)); }while (rocks.Contains(newRock)); rocks.Add(newRock); } }
public void SortRockSpawnTime(PlayerNEnemyPrefabData data) { // Put all rocks into a List, regardless of rock type. for (int i = 0; i < data.s1RockSpawnList.Count; i++) { Rocks currRock = data.s1RockSpawnList[i]; mAllRockList.Add(currRock); } // Put earliest-latest spawn time rock into new List. List <Rocks> spawnFirstList = new List <Rocks>(); while (mAllRockList.Count != 0) { Rocks minSpawnTimeRock = mAllRockList[0]; // TODO: Hard-coded start stage delay. To be changed. if (data.startStageDelay.Count != 0) { mDelay = data.startStageDelay[0]; } float minSpwTime = minSpawnTimeRock.spawnTime + mDelay; int index = 0; for (int i = 1; i < mAllRockList.Count; i++) { Rocks currRock = mAllRockList[i]; if (currRock.spawnTime + mDelay < minSpwTime) { index = i; minSpwTime = currRock.spawnTime + mDelay; minSpawnTimeRock = currRock; } } mAllRockList.RemoveAt(index); spawnFirstList.Add(minSpawnTimeRock); } // Put spawnFirstList back into mAllRockList. mAllRockList = spawnFirstList; // Testing purposes. // for (int i = 0; i < mAllRockList.Count; i++) // { // Debug.Log(mAllRockList[i].spawnTime); // } }
public void WriteToStreamTest() { Rocks target = new Rocks(); using (StreamReader sr = new StreamReader(@"C:\Jacob\Udvikling\NewT2voc\Models\Centrifuge\co2buble.txt")) { sr.ReadLine(); sr.ReadLine(); target.ReadFromStream(sr); } using (StreamWriter sr = new StreamWriter(@"C:\Jacob\Udvikling\NewT2voc\Models\Centrifuge\temp.txt")) { sr.Write(target.ToString()); } }
/// <summary> /// Kontruktor der Klasse Game, nimmt die SpaceInvaderForm entgegen /// </summary> /// <param name="container"></param> public Game(SpaceInvadersForm container) { _container = container; _gameTimer = new Timer(); _gameTimer.Interval = 1; _gameTimer.Tick += Play; _rocks = new Rocks(this); _ship = new SpaceShip(this); _infobar = new Infobar(this); _invaders = new Invaders(this); _bulletItem = new BulletItem(this); _movespeedItem = new MovespeedItem(this); _itemWatch = new Stopwatch(); }
public GameLogic(Lights lights, Player player1, Player player2, RockSpawner rRockSpawner) { this.rRockSpawner = rRockSpawner; this.rocks = new Rocks(); this.player2 = player2; this.player1 = player1; this.lights = lights; player1OutputEvent = new PlayerOutputEventHandler(); player2OutputEvent = new PlayerOutputEventHandler(); player1OutputEvent.moveLeft = () => MoveLeft(player1, otherPlayer: player2, lights: lights); player2OutputEvent.moveLeft = () => MoveLeft(player2, otherPlayer: player1, lights: lights); player1OutputEvent.moveRight = () => MoveRight(player1, otherPlayer: player2, lights: lights); player2OutputEvent.moveRight = () => MoveRight(player2, otherPlayer: player1, lights: lights); player1OutputEvent.shoot = () => Shoot(player1, rocks, onShootSuccess: ScoreUpAction(player1.color), playerInput: player1Input); player2OutputEvent.shoot = () => Shoot(player2, rocks, onShootSuccess: ScoreUpAction(player2.color), playerInput: player2Input); }
private static void RockFallCreation() { //initialize instances of Rocks class for (int i = 0; i < level; i++) { Rocks rock = new Rocks(' ', 0, 0, 0); rock.RockInitialCol = randomGenerator.Next(0, Console.WindowWidth); rock.RockInitialRow = 0; rock.RockType = rockCharType[randomGenerator.Next(0, 12)]; rock.RockColorIndex = randomGenerator.Next(0, 15); QueueOfRocks.Enqueue(rock); } //dispose of instances that went out of screen while (QueueOfRocks.Count > levelNumOfRocksOnScreen) { QueueOfRocks.Dequeue(); } }
public static void Main() { ConsoleKeyInfo key; bool finished = false; Fishes myFish = new Fishes(); Environment myEnv = new Environment(); Coral myCoral = new Coral(); SeaWeed myWeed = new SeaWeed(); Rocks myRock = new Rocks(); Bubbles myBubble = new Bubbles(); while (!finished) { Console.Clear(); myFish.Draw(); myFish.Move(); myEnv.Draw(); myCoral.Draw(); myWeed.Draw(); myRock.Draw(); myBubble.Draw(); Thread.Sleep(100); if (Console.KeyAvailable) { key = Console.ReadKey(); if (key.Key == ConsoleKey.Escape) { finished = true; } } } Console.Clear(); Console.SetCursorPosition(35, 12); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Bye Bye!"); Console.ReadKey(); }
private static void Shoot(Player pPlayer, Rocks rRocks, Action onShootSuccess, PlayerInput playerInput) { var pos = pPlayer.currentLight.positionIndex; Rock rock = rRocks.FindNearest(pos); if (rock == null) { return; } if (pPlayer.color != rock.color) { playerInput.ShowUU(); return; } rock.Boom(); onShootSuccess(); Debug.Log("Shoot"); }
/// <summary> /// Deletes the rock with the selected ID and returns the previous element in the collection (or null if there are no more elements in the collection to edit). /// </summary> /// <param name="selectedID">The Unique ID of the rock to delete.</param> /// <returns>The next rock to be deleted (or 0 is no more rocks).</returns> internal Rock Delete(string selectedID) { if (selectedID == null) { throw new ArgumentNullException("selectedID"); } int index = this.IndexOf(selectedID); if (index < 0) { throw new ArgumentException("specified item not found in collection."); } Rocks.RemoveAt(index); int nextID = Math.Min(Rocks.Count - 1, index); //if the count is 0, this will be -1, we want to return that there is no "Next" rock. return(nextID < 0 ? null : Rocks[nextID]); }
// Use this for initialization void Start() { Rocks newRocks = new Rocks(); newRocks.startPos = start; newRocks.endPos = end; newRocks.Prefab = Rock; float ys = newRocks.startPos.y; float xs = newRocks.startPos.x; float ye = newRocks.endPos.y; float xe = newRocks.endPos.x; for (float i = ys; i <= ye; i++) { for (float a = xs; a <= xe; a++) { newRocks.place(a, i); } } }
private void MoveRock(CellType currentType, Point current, Point destination, CellType[,] newState) { newState.Set(current, CellType.Empty); Rocks.Remove(current); IsChanged = true; if (currentType.IsHoRock() && !Cell.At(destination.Down()).IsEmpty()) { newState.Set(destination, CellType.Lambda); Lambdas.Add(destination); HoRocks.Remove(current); } else { newState.Set(destination, currentType); Rocks.Add(destination); } if (Cell.At(destination.Down()).IsRobot()) { State = MapState.Killed; } }
private void CreateRecipes() { Recipes = new Recipe[10]; Item[] items = new Item[9]; Item[] _rTMP = { null, null, null, null, new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null, null, null }; Recipes[0] = new Recipe(_rTMP, "NAAAME", 100, new Item[] { new Gems(null, "Red gem", "A blood red gem", ItemValues.RedGem), null, null }); Recipes[0].isKnown = true; Recipes[0].InventorySprite = _rTMP[4].InventorySprite; Item[] _rTMP2 = { null, null, null, null, new Gems(null, "Red gem", "a blood red gem", ItemValues.RedGem), null, null, null, null }; Recipes[1] = new Recipe(_rTMP2, "BWAA", 100, new Item[] { new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null }); Recipes[1].isKnown = true; Recipes[1].InventorySprite = _rTMP2[4].InventorySprite; Item[] _rTMP3 = { null, null, null, null, new Gems(null, "Yellow gem", "A yellow gem", ItemValues.YellowGem), null, null, null, null }; Recipes[2] = new Recipe(_rTMP3, "TOTO", 100, new Item[] { new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null }); Recipes[2].InventorySprite = _rTMP3[4].InventorySprite; #region Rocks for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.BasaltName, ItemValues.RockBasalt); } Recipes[3] = new Recipe(items, RockBlocks.BasaltName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.BasaltName, ItemValues.BlocBasalt), null }); Recipes[3].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.DioriteName, ItemValues.RockDiorite); } Recipes[4] = new Recipe(items, RockBlocks.DioriteName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.DioriteName, ItemValues.BlocDiorite), null }); Recipes[4].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.GabbroName, ItemValues.RockGabbro); } Recipes[4] = new Recipe(items, RockBlocks.GabbroName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.GabbroName, ItemValues.BlocGabbro), null }); Recipes[4].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.GranitName, ItemValues.RockGranit); } Recipes[5] = new Recipe(items, RockBlocks.GranitName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.GranitName, ItemValues.BlocGranit), null }); Recipes[5].InventorySprite = ResourcesManager.instance.IN_Bloc; #endregion for (int i = 0; i < 9; i++) { if (i == 4) { items[i] = new RawGems(null); } else { items[i] = null; } } Recipes[6] = new Recipe(items, "Raw gem", 50, null, true, new Item[] { new Gems(null, "Red gem", "A blood red gem", ItemValues.RedGem), new Gems(null, "White gem", "A shiny white gem", ItemValues.WhiteGem), new Gems(null, "Yellow gem", "A yellow gem", ItemValues.YellowGem) }, 1); Recipes[6].InventorySprite = ResourcesManager.instance.IN_RawGem; }
static void Main() { int playfiledwidth = 61; int score = 0; int lives = 5; Console.BufferHeight = Console.WindowHeight = 20; Console.BufferWidth = Console.WindowWidth = 61; Rocks dwarf = new Rocks(); dwarf.x = 30; dwarf.y = Console.WindowHeight - 1; dwarf.ch = "(.)Y(.)"; dwarf.color = ConsoleColor.Magenta; List<Rocks> rock = new List<Rocks>(); Random randomGenerator = new Random(); while (true) { { int chance = randomGenerator.Next(1, 100); Rocks newRock = new Rocks(); Rocks newHeal = new Rocks(); switch (randomGenerator.Next(1, 11)) { case 0: newRock.color = ConsoleColor.DarkRed; break; case 1: newRock.color = ConsoleColor.Gray; break; case 2: newRock.color = ConsoleColor.Green; break; case 3: newRock.color = ConsoleColor.Yellow; break; case 4: newRock.color = ConsoleColor.DarkGray; break; case 5: newRock.color = ConsoleColor.Blue; break; case 6: newRock.color = ConsoleColor.DarkBlue; break; case 7: newRock.color = ConsoleColor.DarkGreen; break; case 8: newRock.color = ConsoleColor.DarkRed; break; case 9: newRock.color = ConsoleColor.White; break; case 10: newRock.color = ConsoleColor.DarkCyan; break; } newRock.x = randomGenerator.Next(0, playfiledwidth); newRock.y = 2; switch (randomGenerator.Next(1, 12)) { case 0: newRock.ch = "^"; break; case 1: newRock.ch = "@"; break; case 2: newRock.ch = "*"; break; case 3: newRock.ch = "&"; break; case 4: newRock.ch = "+"; break; case 5: newRock.ch = "%"; break; case 6: newRock.ch = "$"; break; case 7: newRock.ch = "#"; break; case 8: newRock.ch = "!"; break; case 9: newRock.ch = "."; break; case 10: newRock.ch = ";"; break; case 11: if (chance > 80) newRock.ch = "xXx"; break; } rock.Add(newRock); } //--------------------------------------------------- if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(); } if (pressedKey.Key == ConsoleKey.LeftArrow) { if (dwarf.x >= 1) { dwarf.x = dwarf.x - 1; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (dwarf.x <= 59 - dwarf.ch.Length) { dwarf.x = dwarf.x + 1; } } } List<Rocks> newList = new List<Rocks>(); for (int i = 0; i < rock.Count; i++) { Rocks oldRocks = rock[i]; Rocks newRocks = new Rocks(); newRocks.x = oldRocks.x; newRocks.y = oldRocks.y + 1; newRocks.ch = oldRocks.ch; newRocks.color = oldRocks.color; if (newRocks.ch == "xXx" && newRocks.y == dwarf.y && newRocks.x + 1 == dwarf.x + 3) { lives += 1; } if (newRocks.ch != "xXx" && newRocks.y == dwarf.y && newRocks.x == dwarf.x + 3) { Position(dwarf.x + 2, dwarf.y, "_!_", ConsoleColor.Red); lives--; if (lives <= 0) { Console.Clear(); StringPosition(1, 2, "Game Over!!", ConsoleColor.Red); StringPosition(1, 3, "Play Again ? Y/N ", ConsoleColor.Red); ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(); } if (pressedKey.Key == ConsoleKey.Y) { lives = 5; score = 0; break; } else if (pressedKey.Key == ConsoleKey.N) { Console.WriteLine(); return; } } } if (newRocks.y < Console.WindowHeight) { newList.Add(newRocks); } } rock = newList; Console.Clear(); Position(dwarf.x, dwarf.y, dwarf.ch, dwarf.color); foreach (var rocks in rock) { Position(rocks.x, rocks.y, rocks.ch, rocks.color); } StringPosition(1, 1, "Score:" + score, ConsoleColor.Gray); StringPosition(1, 2, "Lives:" + lives, ConsoleColor.Gray); Thread.Sleep(150); score++; } }
private void MoveRobotTo(RobotCommand direction, Point destPos) { CellType destType = Cell.At(destPos); if (!destType.IsTraversible()) { throw new InvalidMoveException(RobotPosition, destPos); } if (!destType.IsEmpty()) { IsChanged = true; } if (destType.IsRock()) { if (direction == RobotCommand.Left && Cell.At(destPos.Left()).IsEmpty()) { Cell.Set(destPos.Left(), destType); Rocks.Remove(destPos); Rocks.Add(destPos.Left()); if (destType.IsHoRock()) { HoRocks.Remove(destPos); HoRocks.Add(destPos.Left()); } } else if (direction == RobotCommand.Right && Cell.At(destPos.Right()).IsEmpty()) { Cell.Set(destPos.Right(), destType); Rocks.Remove(destPos); Rocks.Add(destPos.Right()); if (destType.IsHoRock()) { HoRocks.Remove(destPos); HoRocks.Add(destPos.Right()); } } else { throw new InvalidMoveException(RobotPosition, destPos); } } if (destType.IsLambda()) { Lambdas.Remove(destPos); Score += 25; LambdasCollected++; } if (destType.IsOpenLift()) { State = MapState.Won; Score += LambdasCollected * 50 - 1; // minus one point for the final move } if (destType.IsTrampoline()) { Cell.Set(destPos, CellType.Empty); destPos = Trampolines[destPos]; // remove all trampolines that have the same target var remove = new List <Point>(); foreach (var trampoline in Trampolines) { if (trampoline.Value == destPos) { Cell.Set(trampoline.Key, CellType.Empty); remove.Add(trampoline.Key); } } foreach (Point point in remove) { Trampolines.Remove(point); } } if (destType.IsRazor()) { RazorCount++; Razors.Remove(destPos); } Cell.Set(RobotPosition, CellType.Empty); Cell.Set(destPos, CellType.Robot); RobotPosition = destPos; }
static void Main() { Console.BufferWidth = Console.WindowWidth = 50; Console.BufferHeight = Console.WindowHeight = 35; Rocks dwarf = new Rocks(); dwarf.x = playField / 2; dwarf.y = Console.WindowHeight - 1; dwarf.str = dwarfSigns; dwarf.color = ConsoleColor.White; Random randomGenerator = new Random(); List<Rocks> rocks = new List<Rocks>(); while (true) { bool hitted = false; Rocks newRocks = new Rocks(); newRocks.color = ConsoleColor.White; newRocks.x = randomGenerator.Next(0, playField + 3); newRocks.y = 0; newRocks.symbol = symbols[randomGenerator.Next(0, 12)]; rocks.Add(newRocks); if (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); while (Console.KeyAvailable) Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.LeftArrow) { if (dwarf.x > 0) { dwarf.x = dwarf.x - 1; } } if (keyInfo.Key == ConsoleKey.RightArrow) { if (dwarf.x < playField) { dwarf.x = dwarf.x + 1; } } } List<Rocks> newList = new List<Rocks>(); for (int i = 0; i < rocks.Count; i++) { Rocks oldRocks = rocks[i]; Rocks updateRocks = new Rocks(); updateRocks.x = oldRocks.x; updateRocks.y = oldRocks.y + 1; updateRocks.symbol = oldRocks.symbol; updateRocks.color = oldRocks.color; if ((updateRocks.y == dwarf.y && updateRocks.x == dwarf.x) || (updateRocks.y == dwarf.y && updateRocks.x == dwarf.x + 1) || (updateRocks.y == dwarf.y && updateRocks.x == dwarf.x + 2)) { lives--; hitted = true; if (updateRocks.y == dwarf.y && updateRocks.x == dwarf.x) { PrintAtPosition(updateRocks.x, updateRocks.y, "X", ConsoleColor.Red); Thread.Sleep(500); } if (updateRocks.y == dwarf.y && updateRocks.x == dwarf.x + 1) { PrintAtPosition(updateRocks.x, updateRocks.y, "X", ConsoleColor.Red); Thread.Sleep(500); } if (updateRocks.y == dwarf.y && updateRocks.x == dwarf.x + 2) { PrintAtPosition(updateRocks.x, updateRocks.y, "X", ConsoleColor.Red); Thread.Sleep(500); } if (lives <= 0) { PrintAtPosition(12, 15, "GAME OVER!", ConsoleColor.Red); Console.ReadLine(); Environment.Exit(0); } } else { if (updateRocks.y == Console.WindowHeight - 1) { score++; } } if (updateRocks.y < Console.WindowHeight - 1) { newList.Add(updateRocks); } } rocks = newList; Console.Clear(); if (hitted) { rocks.Clear(); } else { PrintAtPosition(dwarf.x, dwarf.y, dwarf.str, dwarf.color); } foreach (Rocks printRocks in rocks) { PrintAtPositionRocks(printRocks.x, printRocks.y, printRocks.symbol, printRocks.color); } PrintAtPosition(35, 7, "Lives: " + lives, ConsoleColor.Red); PrintAtPosition(35, 8, "Score: " + score, ConsoleColor.Red); Thread.Sleep(150); } }
static void Main() { int score = 0; int playfieldWidth = 30; int lifesCount = 5; Console.BufferHeight = Console.WindowHeight=15; Console.BufferWidth = Console.WindowWidth = 45; Rocks myShip = new Rocks(); myShip.x = Console.WindowWidth / 3; myShip.y = Console.WindowHeight - 1; myShip.s = '0'; myShip.color = ConsoleColor.White; Random randomGenerator = new Random(); List<Rocks> objects = new List<Rocks>(); char[] symbols = new char[]{ '^', '@', '*', '&', '+', '%', '$', '#', '!', '.', ';' }; ConsoleColor[] colors = new ConsoleColor[]{ ConsoleColor.Cyan, ConsoleColor.Blue, ConsoleColor.DarkYellow, ConsoleColor.DarkGray, ConsoleColor.White }; while (true) { score++; bool hitted = false; { Rocks newObjectOne = new Rocks(); newObjectOne.color = colors[randomGenerator.Next(colors.Length)]; newObjectOne.s = symbols[randomGenerator.Next(symbols.Length)]; newObjectOne.x = randomGenerator.Next(0, playfieldWidth); newObjectOne.y = 0; objects.Add(newObjectOne); } if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(); } if (pressedKey.Key == ConsoleKey.LeftArrow) { if (myShip.x - 1 >= 0) { myShip.x--; } } else if(pressedKey.Key==ConsoleKey.RightArrow) { if (myShip.x +1< playfieldWidth) { myShip.x++; } } } List<Rocks> newList = new List<Rocks>(); for (int i = 0; i < objects.Count; i++) { Rocks oldShip = objects[i]; Rocks newShip = new Rocks(); newShip.x = oldShip.x; newShip.y = oldShip.y +1; newShip.s = oldShip.s; newShip.color = oldShip.color; if (newShip.y == myShip.y && newShip.x == myShip.x) { lifesCount--; hitted = true; if (lifesCount <= 0) { PrintStringOnPossition(35, 7, "Game over!", ConsoleColor.Red); Console.ReadLine(); return; } } if (newShip.y < Console.WindowHeight) { newList.Add(newShip); } } objects = newList; Console.Clear(); foreach (Rocks ship in objects) { PrintOnPossition(ship.x, ship.y, ship.s, ship.color); } if (hitted) { Console.Beep(); objects.Clear(); PrintOnPossition(myShip.x, myShip.y, 'X', ConsoleColor.Red); score = 0; } else { PrintOnPossition(myShip.x, myShip.y, myShip.s, myShip.color); } PrintStringOnPossition(36, 3, "Score" + score); PrintStringOnPossition(36,5,"Lifes :"+lifesCount); Thread.Sleep(350); } }
static void Main() { //-----Here i initialize two variables, one for playground width and one for game score int playgroundWidth = 50; int score = 0; int livesCount = 5; double speedFall = 100.0; //Here I set the width and height of the game screen Console.BufferWidth = Console.WindowWidth = 70; Console.BufferHeight = Console.WindowHeight = 35; //----Here i create the Dwarf Object-------- Rocks Dwarf = new Rocks(); Dwarf.x = playgroundWidth / 2; Dwarf.y = Console.WindowHeight - 1; Dwarf.symbol = "O-O"; Dwarf.color = ConsoleColor.Magenta; //------Here I create one list with rocks obj. and one random generator. List <Rocks> Rock = new List <Rocks>(); Random randGen = new Random(); //------start of the main while loop------ while (true) { speedFall++; if (speedFall > 400) { speedFall = 400; } bool hit = false; { //------Here I create the falling rock objects------- Rocks newRock = new Rocks(); newRock.x = randGen.Next(0, playgroundWidth); newRock.y = 0; //------Switch Loop to generate diferent symbols and colors for the rocks switch (randGen.Next(0, 10)) { case 0: newRock.symbol = "^^^"; newRock.color = ConsoleColor.Green; break; case 1: newRock.symbol = "@@@"; newRock.color = ConsoleColor.White; break; case 2: newRock.symbol = "***"; newRock.color = ConsoleColor.Red; break; case 3: newRock.symbol = "&&&"; newRock.color = ConsoleColor.White; break; case 4: newRock.symbol = "+++"; newRock.color = ConsoleColor.Cyan; break; case 5: newRock.symbol = "%%%"; newRock.color = ConsoleColor.White; break; case 6: newRock.symbol = "$$$"; newRock.color = ConsoleColor.White; break; case 7: newRock.symbol = "###"; newRock.color = ConsoleColor.White; break; case 8: newRock.symbol = "!!!"; newRock.color = ConsoleColor.White; break; case 9: newRock.symbol = "..."; newRock.color = ConsoleColor.Yellow; break; case 10: newRock.symbol = ";;;"; newRock.color = ConsoleColor.White; break; default: break; } Rock.Add(newRock); } //------Here I check if user is press any key from the keyboard if (Console.KeyAvailable) { ConsoleKeyInfo keyPressed = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(); } if (keyPressed.Key == ConsoleKey.LeftArrow) { if (Dwarf.x - 1 >= 0) { Dwarf.x = Dwarf.x - 1; } } else if (keyPressed.Key == ConsoleKey.RightArrow) { if (Dwarf.x + 1 <= playgroundWidth) { Dwarf.x = Dwarf.x + 1; } } } //-------here is the for loop for moving the rocks through the screen-------- List <Rocks> newListRocks = new List <Rocks>(); for (int i = 0; i < Rock.Count; i++) { Rocks oldRocks = Rock[i]; Rocks newRock = new Rocks(); newRock.x = oldRocks.x; newRock.y = oldRocks.y + 1; newRock.symbol = oldRocks.symbol; newRock.color = oldRocks.color; //----here I check if my Dwarf is hit by rock and what color is the rock if (newRock.x == Dwarf.x && newRock.y == Dwarf.y && newRock.color == ConsoleColor.White) { hit = true; livesCount--; if (livesCount <= 0) { writeInfo(55, 10, "GAME OVER!", ConsoleColor.Red); writeInfo(55, 12, "Press [ENTER]", ConsoleColor.Red); writeInfo(55, 13, "to exit!", ConsoleColor.Red); Console.ReadLine(); Environment.Exit(0); } } //-----scoring and bonus system--------- if (newRock.x == Dwarf.x && newRock.y == Dwarf.y && newRock.color != ConsoleColor.White) { switch (newRock.symbol) { case "^^^": score = score + 10; break; case "***": score = score + 50; break; case "+++": livesCount++; break; case "...": speedFall--; break; default: break; } } if (newRock.y < Console.WindowHeight) { newListRocks.Add(newRock); } } Rock = newListRocks; Console.Clear(); if (hit) { newListRocks.Clear(); drawObject(Dwarf.x, Dwarf.y, "XXX", ConsoleColor.DarkRed); } else { drawObject(Dwarf.x, Dwarf.y, Dwarf.symbol, Dwarf.color); } //-----here I draw the rocks with foreach loop------- foreach (Rocks rocks in Rock) { drawObject(rocks.x, rocks.y, rocks.symbol, rocks.color); } writeInfo(55, 2, "LIVES: " + livesCount, ConsoleColor.Red); writeInfo(55, 3, "SCORE: " + score, ConsoleColor.DarkGreen); System.Threading.Thread.Sleep((int)(600 - speedFall)); } }
public object Clone() { Rocks clonedItem = new Rocks(null, this.Name, this.ItemValue); clonedItem.Type = Type; clonedItem.SortingLayer = SortingLayer; clonedItem.Count = Count; return clonedItem; }
public void CheckCollisionRocks(LinkedList <Line2D> land) { #region New Collision LinkedList <Line2D> rockCollision = new LinkedList <Line2D>(); LinkedList <Line2D> enemyShipCollision = new LinkedList <Line2D>(); LinkedList <Line2D> laserCollision = new LinkedList <Line2D>(); //Check Collision between EnemyShip and Player foreach (EnemyShip e in activeEnemyShips) { //enemyShipCollision = e.ConvertEnemyShipLine2D(); foreach (Line2D l1 in enemyShipCollision) { foreach (Line2D l2 in playerShip1List) { if (Line2D.Intersects(l1, l2)) { playerShip1.CrashShip(); return; } } } } foreach (Laser l in activeLasers) { if (l.CheckLaser() == true) //Make a check in Laser so that the laser can only run for 5 seconds. { activeLasers.Remove(l); l.Dispose(); return; //remove l from activeLasers //return/break; (Break from the loop) } laserCollision = l.ConvertLaserLine2D(); foreach (EnemyShip e in activeEnemyShips) { //enemyShipCollision = e.ConvertEnemyShipLine2D(); foreach (Line2D l1 in laserCollision) { foreach (Line2D l2 in enemyShipCollision) { if (Line2D.Intersects(l1, l2) && l.playerLaser) { //e.DestroyShip(); //Remove e from activeEnemyShips LinkedList activeEnemyShips.Remove(e); //return; } } } } Rocks[] activeRocksArray = activeRocks.ToArray(); for (int i = 0; i < activeRocksArray.Count(); i++) { Random rand = new Random(); rockCollision = activeRocksArray[i].RocksSquareCollision(); float angle1 = 0f; float angle2 = 0f; int location = 0; int index = 1; //Console.WriteLine($"Rock Rotation{activeRocksArray[i].rotation}"); foreach (Line2D l1 in laserCollision) { foreach (Line2D l2 in rockCollision) { if (Keyboard.GetState().IsKeyDown(Keys.LeftShift)) { Console.WriteLine($"Laser Collision: l1.StartX ({l1.StartX}) l1.StartY ({l1.StartY}) l1.EndX ({l1.EndX}) l1.EndY ({l1.EndY})"); Console.WriteLine($"Rock Collision: l2.StartX ({l2.StartX}) l2.StartY ({l2.StartY}) l2.EndX ({l2.EndX}) l2.EndY ({l2.EndY})"); } if (Line2D.Intersects(l1, l2) && l.playerLaser) { CheckAngle(activeRocksArray[i].rotation, out location, out angle1, out angle2); playerShip1.AddScore(activeRocksArray[i].score); if (activeRocksArray[i].size > 1) { Console.WriteLine($"Before Collision Check: {activeRocks.Count}"); Rocks newRock1 = new Rocks(angle2, activeRocksArray[i].size - 1, activeRocksArray[i].position.X, activeRocksArray[i].position.Y, activeRocksArray[i].typeOfRock, StateManager.Game); newRock1.Initialize(); activeRocks.AddLast(newRock1); newRock1.MAX_THRUST_POWER = 1f; Rocks newRock2 = new Rocks(angle1, activeRocksArray[i].size - 1, activeRocksArray[i].position.X, activeRocksArray[i].position.Y, activeRocksArray[i].typeOfRock, StateManager.Game); newRock2.Initialize(); activeRocks.AddLast(newRock2); newRock2.MAX_THRUST_POWER = 1f; activeRocks.Remove(activeRocksArray[i]); activeRocksArray[i].Dispose(); Console.WriteLine($"After Collision Check: {activeRocks.Count}"); } else { activeRocks.Remove(activeRocksArray[i]); activeRocksArray[i].Dispose(); Console.WriteLine($"activeRocks Count{activeRocks.Count}"); } activeLasers.Remove(l); l.Dispose(); } } } } foreach (Line2D l1 in laserCollision) { foreach (Line2D l2 in playerShip1List) { if (Line2D.Intersects(l1, l2) && !l.playerLaser) { playerShip1.CrashShip(); } } } return; #endregion } foreach (Rocks r in activeRocks) { rockCollision = r.RocksSquareCollision(); foreach (Line2D l1 in rockCollision) { foreach (Line2D l2 in playerShip1List) { if (Line2D.Intersects(l1, l2)) { playerShip1.CrashShip(); return; } } } } }
private void ActiveRocksRemove(Rocks r) { activeRocks.Remove(r); }
static void Main() { int playFieldWidth = Console.WindowWidth - 50; int passedRocks = 1; int playerPosition = playFieldWidth / 2; Random randomGenerator = new Random(); int lives = 3; RemoveConsoleBuffer(); PrintPlayer(playerPosition, '0'); List<Rocks> rocks = new List<Rocks>(); List<Rocks> moreRocks = new List<Rocks>(); Rocks rock = new Rocks(); Rocks moreRock = new Rocks(); bool alive = true; int level = 1; while (alive) { if (passedRocks%10==0) { level++; } int points = passedRocks/10; if (passedRocks%1000==0) { lives=lives+1; } string[] chars = { "^", "@", "*", "&", "+", "%", "$", "#", "!", ".", ";" }; rock.col = randomGenerator.Next(0, playFieldWidth); rock.row = 0; rock.color = ConsoleColor.Cyan; rock.c = chars[randomGenerator.Next(0,chars.Length)]; if (rock.c=="^"||rock.c=="!"||rock.c=="&") { rock.color = ConsoleColor.Green; } else if (rock.c=="@"||rock.c==".") { rock.color = ConsoleColor.DarkYellow; } else if (rock.c=="*"||rock.c==";") { rock.color = ConsoleColor.Magenta; } else if (rock.c=="+"||rock.c=="%") { rock.color = ConsoleColor.White; } else if (rock.c=="$"||rock.c=="#") { rock.color = ConsoleColor.Cyan; } rocks.Add(rock); moreRock.c = rock.c; moreRock.color = rock.color; moreRock.row = rock.row; moreRock.col = randomGenerator.Next(0, playFieldWidth); moreRocks.Add(moreRock); PrintPlayer(playerPosition, '0'); foreach (var roc in rocks) { PrintAtPosition(roc.col, roc.row, roc.c, roc.color); } foreach (var roc in moreRocks) { PrintAtPosition(roc.col, roc.row, roc.c, roc.color); } for (int i = 0; i < Console.WindowHeight; i++) { PrintAtPosition(playFieldWidth, i, "|"); } PrintAtPosition(playFieldWidth + 2, 1,"Points:" + Convert.ToString(points)); PrintAtPosition(playFieldWidth + 2, 3, "Lives:" + Convert.ToString(lives)); PrintAtPosition(playFieldWidth + 2, 5, "Level:" + Convert.ToString(level)); PrintAtPosition(playFieldWidth + 2, Console.WindowHeight-5, "Falling Rocks by Nikola Galabov"); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(true); } if (key.Key == ConsoleKey.LeftArrow) { if (playerPosition > 0) { playerPosition--; PrintPlayer(playerPosition + 1, ' '); PrintPlayer(playerPosition, '0'); } } else if (key.Key == ConsoleKey.RightArrow) { if (playerPosition<playFieldWidth-1) { playerPosition++; PrintPlayer(playerPosition - 1, ' '); PrintPlayer(playerPosition, '0'); } } } List<Rocks> newlist = new List<Rocks>(); for (int i = 0; i < rocks.Count; i++) { Rocks oldRock = rocks[i]; Rocks newRock = oldRock; newRock.c = oldRock.c; newRock.color = oldRock.color; newRock.col = oldRock.col; newRock.row = oldRock.row + 1; if (newRock.col==playerPosition&&newRock.row==Console.WindowHeight-1) { newRock.color = ConsoleColor.Red; newRock.c = "x"; lives--; rocks.Clear(); moreRocks.Clear(); } if (newRock.row<Console.WindowHeight) { newlist.Add(newRock); } else { passedRocks++; } } rocks = newlist; List<Rocks> newMore = new List<Rocks>(); for (int i = 0; i < moreRocks.Count; i++) { Rocks oldRock = moreRocks[i]; Rocks newRock = oldRock; newRock.c = oldRock.c; newRock.color = oldRock.color; newRock.col = oldRock.col; newRock.row = oldRock.row + 1; if (newRock.col == playerPosition && newRock.row == Console.WindowHeight - 1) { newRock.color = ConsoleColor.Red; newRock.c = "x"; lives--; moreRocks.Clear(); rocks.Clear(); } if (newRock.row < Console.WindowHeight) { newMore.Add(newRock); } else { passedRocks++; } } moreRocks = newMore; Thread.Sleep(153-3*level); Console.Beep(randomGenerator.Next(37,32766),100); Console.Clear(); foreach (var roc in rocks) { PrintAtPosition(roc.col, roc.row, roc.c, roc.color); } if (lives <= 0) { Console.Clear(); alive = false; PrintAtPosition(Console.WindowWidth / 2-9, Console.WindowHeight / 2, "Game over!", ConsoleColor.DarkRed); PrintAtPosition(Console.WindowWidth / 2 - 9, Console.WindowHeight / 2+1, "Your points:" + Convert.ToString(points), ConsoleColor.DarkRed); PrintAtPosition(Console.WindowWidth / 2 - 9, Console.WindowHeight / 2+2, "Press any key to exit...", ConsoleColor.DarkRed); Console.ReadLine(); return; } } }
static void Main() { int playfieldWidth = 80; int playfieldHeight = 40; Console.BufferHeight = Console.WindowHeight = playfieldHeight; Console.BufferWidth = Console.WindowWidth = playfieldWidth + 2; int lives = 3; Rocks user = new Rocks(); user.col = playfieldWidth / 2; user.row = Console.WindowHeight - 1; user.symbolString = "(0)"; user.color = ConsoleColor.White; Random randomGenerator = new Random(); List<Rocks> objects = new List<Rocks>(); while (true) { bool collision = false; { int chance = randomGenerator.Next(0, 120); // ^, @, *, &, +, %, $, #, !, ., ;, if (chance < 10) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Blue; newObject.symbol = '^'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 20) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Cyan; newObject.symbol = '@'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 30) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkCyan; newObject.symbol = '*'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 40) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Green; newObject.symbol = '&'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 50) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Magenta; newObject.symbol = '&'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 60) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Yellow; newObject.symbol = '+'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 70) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.Red; newObject.symbol = '%'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 80) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkMagenta; newObject.symbol = '$'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 90) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkGreen; newObject.symbol = '#'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 100) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkYellow; newObject.symbol = '!'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else if (chance < 110) { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkBlue; newObject.symbol = '.'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } else { Rocks newObject = new Rocks(); newObject.color = ConsoleColor.DarkRed; newObject.symbol = ';'; newObject.col = randomGenerator.Next(0, playfieldWidth); newObject.row = 0; objects.Add(newObject); } } while (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); if (pressedKey.Key == ConsoleKey.LeftArrow) { if (user.col - 1 >= 0) { user.col = user.col - 1; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (user.col + 1 < playfieldWidth) { user.col = user.col + 1; } } } List<Rocks> newList = new List<Rocks>(); for (int i = 0; i < objects.Count; i++) { Rocks oldRocks = objects[i]; Rocks newObject = new Rocks(); newObject.col = oldRocks.col; newObject.row = oldRocks.row + 1; newObject.symbol = oldRocks.symbol; newObject.color = oldRocks.color; if ((newObject.row == (user.row - 1)) && newObject.col >= user.col && (newObject.col <= user.col + 2)) { lives--; collision = true; if (lives <= 0) { PrintStringOnPosition(playfieldWidth / 2, playfieldHeight / 2, "GAME OVER!!!", ConsoleColor.Red); Console.ReadLine(); Environment.Exit(0); } } if (newObject.row < Console.WindowHeight) { newList.Add(newObject); } } objects = newList; Console.Clear(); if (collision) { objects.Clear(); PrintStringOnPosition(user.col, user.row, "(x)", ConsoleColor.Red); } else { PrintStringOnPosition(user.col, user.row, user.symbolString, user.color); } foreach (Rocks element in objects) { PrintOnPosition(element.col, element.row, element.symbol, element.color); } // Draw info //PrintStringOnPosition(0, 0, "user.col: " + user.col, ConsoleColor.White); Thread.Sleep(50); } }
//-------------------------------------Static Void Method --------------------------\\ static void Main() { int score = 0; //player starts with 0 score int leveL = 1; //First level ConsoleColor damageColor = ConsoleColor.White; Console.CursorVisible = false; // Disable console crusor - it's better Line(); // That's is some method drawing a vertical line in x= 52 - int playfield = 50; // Playground width int damage = 0; // Starts with 0 damage if it's =>100 - Game over Console.BufferHeight = Console.WindowHeight = 40; // Disable scrollbar at right Console.BufferWidth = Console.WindowWidth = 100; // same Rocks player = new Rocks(); // creating player with atributes player.x = 25 - (3 / 2); // x position player.y = Console.WindowHeight - 1; // y position (bottom) player.text = "<O>"; // My dwarf is <0> player.color = ConsoleColor.DarkGreen; // PLayer Color Random generator = new Random(); // Variable generator witch will contains random numbers List<Rocks> fallingRocks = new List<Rocks>(); // Collection for "###" this objects List<Rocks> symbols = new List<Rocks>(); // Other symbols. with two collection can make a more object to display at one line Rocks crusor = new Rocks(); // This will use for Menu cursor crusor.x = 3; // Position of cursor for x crusor.y = 10; // Position of cursor for y crusor.color = ConsoleColor.Green; // Color crusor.text = ">"; // Vision Rocks bad = new Rocks(); // new object that will hide old position of cursor, bad.x = 3; bad.y = 13; bad.text = " "; // That's the empty space that will hide bad.color = ConsoleColor.DarkBlue; // sensless - no matter for color int temp = 0; while (true) // Here starts Menu { if (Console.KeyAvailable) //That is some condition if we pressing a key { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(true); } if (pressedKey.Key == ConsoleKey.UpArrow) // exchanging positions of cursor and 'bad' variable { temp = crusor.y; crusor.y = bad.y; bad.y = temp; } if (pressedKey.Key == ConsoleKey.DownArrow) { temp = crusor.y; crusor.y = bad.y; bad.y = temp; //-============================================ yes beeeee } if (pressedKey.Key == ConsoleKey.Enter && crusor.y == 10) // Must press enter on 'Start game ' to exit from this menu and start play { break; } else if (pressedKey.Key == ConsoleKey.Enter && crusor.y == 13) // Or exit from game { Console.WriteLine(); return; } } PrintPosition(crusor.x, crusor.y, crusor.text, crusor.color); // Printing cursor PrintPosition(bad.x, bad.y, bad.text, bad.color); PrintPosition(5, 10, "Start game", ConsoleColor.White); PrintPosition(5, 13, "Exit", ConsoleColor.White); } while (true) { bool hitbonus = false; // Bool for if player takes bonus (dollar symbol) bool hitted = false; // If player hitted by other object bool gameOver = false; // If damage is above or equal to 100 int chance = generator.Next(0, 110); // Generating a random number from 0 to 100 int lenght = generator.Next(1,11); // Another random from 1 to 11 uses for level 5 for objects lengt if (chance < 30) // Creating objects depends on chance value { Rocks rock = new Rocks(); rock.color = ConsoleColor.DarkMagenta; rock.x = generator.Next(0, playfield); rock.y = 0; rock.text = "###"; fallingRocks.Add(rock); // Adding new object to collection } if (chance > 10 && chance < 20) // Symbol Objects { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Yellow; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "^"; if (leveL >= 5) // After level 5 it's get harder { symbol.text = new string('^', lenght); } symbols.Add(symbol); } else if (chance > 20 && chance < 30) // If some object is created other statements will not checked (beacuse of "if else...") { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Blue; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "@"; if (leveL >= 5) { symbol.text = new string('@', lenght); } symbols.Add(symbol); } else if (chance > 30 && chance < 40) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Cyan; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "*"; if (leveL >= 5) { symbol.text = new string('*', lenght); } symbols.Add(symbol); } else if (chance > 40 && chance < 50) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Red; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "&"; if (leveL >= 5) { symbol.text = new string('&', lenght); } symbols.Add(symbol); } else if (chance > 50 && chance < 60) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Magenta; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "+"; if (leveL >= 5) { symbol.text = new string('+', lenght); } symbols.Add(symbol); } else if (chance > 60 && chance < 70) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.DarkRed; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "%"; if (leveL >= 5) { symbol.text = new string('%', lenght); } symbols.Add(symbol); } else if (chance > 70 && chance < 80) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Gray; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = ","; if (leveL >= 5) { symbol.text = new string(',', lenght); } symbols.Add(symbol); } else if (chance > 80 && chance < 90) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.DarkYellow; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "."; if (leveL >= 5) { symbol.text = new string('.', lenght); } symbols.Add(symbol); } else if (chance > 90 && chance < 100) { Rocks symbol = new Rocks(); symbol.color = ConsoleColor.Green; symbol.x = generator.Next(0, playfield); symbol.y = 0; symbol.text = "$"; symbols.Add(symbol); } if (Console.KeyAvailable) // Was player pressed a key? { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(true); } if (pressedKey.Key == ConsoleKey.LeftArrow) { if (player.x - 1 >= 0) // Left movement { player.x = player.x - 1; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (player.x + 1 < playfield) // Right movement { player.x = player.x + 1; } } } List<Rocks> newList = new List<Rocks>(); // Using new collection to transfer old properties to new object for (int i = 0; i < fallingRocks.Count; i++) // Moving rock down { Rocks oldRcok = fallingRocks[i]; Rocks newRock = new Rocks(); newRock.x = oldRcok.x; newRock.y = oldRcok.y + 1; newRock.text = oldRcok.text; newRock.color = oldRcok.color; if (newRock.y == player.y && (Math.Abs(player.x - newRock.x) < newRock.text.Length)) // Checks for rock on player - hit { hitted = true; if (player.x - newRock.x == newRock.text.Length -3 ) { damage += 30; // Adding 30 damage. Depends on how many part form object are hited. if (damage >= 100) // If damage reachs 100 the game will over. { gameOver = true; } } else if (Math.Abs(player.x - newRock.x) < newRock.text.Length - 1) // Gets 20 damage { damage += 20; if (damage >= 100) { gameOver = true; } } else // 10 Damage { damage += 10; if (damage >= 100) { gameOver = true; // Bewol is my old logic that was not working well. But the new is better } } } /*if (newRock.y == player.y && ((newRock.x == player.x + 2 || newRock.x == player.x - 2) && newRock.text.Length == 3))//by10 { hitted = true; damage += 10; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } } if (newRock.y == player.y && ((newRock.x == player.x + 1 || newRock.x == player.x - 1) && newRock.text.Length == 3))//by 20 { hitted = true; damage += 20; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } } if (newRock.y == player.y && newRock.x == player.x && newRock.text.Length == 3)//by 30 { hitted = true; damage += 30; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } }*/ if (newRock.y < Console.WindowHeight) // Adding to newlist. Only if a object is on play field { newList.Add(newRock); } }//End loop "for" List<Rocks> nListSymbols = new List<Rocks>(); // Some method like before if (leveL >= 2) // Only on level 2 { for (int i = 0; i < symbols.Count; i++) { Rocks oldSymbol = symbols[i]; Rocks newSymbol = new Rocks(); newSymbol.x = oldSymbol.x; newSymbol.y = oldSymbol.y + 1; newSymbol.text = oldSymbol.text; newSymbol.color = oldSymbol.color; if(newSymbol.x + newSymbol.text.Length-1 >= 52) // This checks if object text gets out from playfield { newSymbol.x -= (newSymbol.x + newSymbol.text.Length - 1) - 51; // And then fix it } //da maxna out of playfield objects if (newSymbol.text != "$" && newSymbol.y == player.y && (player.x == newSymbol.x + newSymbol.text.Length - 1 || newSymbol.x == player.x + 2)) // Check if rock is over player with different symbol than dollar ($) { hitted = true; damage += 10; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } } else if (newSymbol.text != "$" && newSymbol.y == player.y && (player.x == newSymbol.x + newSymbol.text.Length - 2 || newSymbol.x == player.x + 1)) // If symbol with Lenght = 1 falls on the midlle of player { hitted = true; if (newSymbol.text.Length == 1) { damage += 10; if (damage >= 100) { gameOver = true; } } else { damage += 20; if (damage >= 100) { gameOver = true; } } } else if (newSymbol.text != "$" && newSymbol.y == player.y && ((player.x >= newSymbol.x && player.x <= newSymbol.x + newSymbol.text.Length - 3))) { hitted = true; damage += 30; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } } /*} //some old logics Skip it if (newSymbol.text != "$" && newSymbol.y == player.y && (newSymbol.x == player.x || newSymbol.x == player.x + 1 || newSymbol.x == player.x + 2))//crash { hitted = true; if (leveL >= 5) { } else { damage += 10; if (damage >= 100) //if damage reachs 100 the game will over { gameOver = true; } } } */ if (newSymbol.text == "$" && newSymbol.y == player.y && (newSymbol.x == player.x || newSymbol.x == player.x + 1 || newSymbol.x == player.x + 2)) // Getting bonus { hitbonus = true; score += 50; } if (newSymbol.y < Console.WindowHeight) //Adding symbols { nListSymbols.Add(newSymbol); } } } fallingRocks = newList; // Adding changed objects to old collection symbols = nListSymbols; // For symbols Console.Clear(); // Clears whole Console Line(); foreach (Rocks sex in symbols) // Printing rocks from first collection { PrintPosition(sex.x, sex.y, sex.text, sex.color); if (sex.y == player.y)//Console.WindowHeigh // And get score +1 for each passed rock { score += 1; } } foreach (Rocks rack in fallingRocks) // This show faling rocks from second collection { PrintPosition(rack.x, rack.y, rack.text, rack.color); if (rack.y == player.y) { score += 1; } } if (hitted) // Crash { PrintPosition(player.x, player.y, "XXX", ConsoleColor.Red); // Player changes text with red color and three XXX Console.Beep(130, 260); fallingRocks.Clear(); // After hit play field is cleared Clears objects in collection symbols.Clear(); // same } else if (hitbonus) // get bonus { PrintPosition(player.x, player.y, "+++", ConsoleColor.Green); // PLayer changes with green pluses "+++" } else { PrintPosition(player.x, player.y, player.text, player.color); // Just prints player } if (damage >= 20 && damage <= 40) // Depends how bad is contition of player damage shows in right in different colors { damageColor = ConsoleColor.Green; } if (damage > 40 && damage <= 60) { damageColor = ConsoleColor.Yellow; } if (damage > 60) { damageColor = ConsoleColor.DarkYellow; } PrintInfo(62, 4, "Level: " + leveL, ConsoleColor.White); // Shows info PrintInfo(62, 5, "Score: " + score, ConsoleColor.White); PrintInfo(62, 6, "Damage: " + damage, damageColor); if (fallingRocks.Count < 5) //-----shows witch level starts //and when player dies it shows up again { if (symbols.Count < 10) PrintPosition(23, 20, "Level: " + leveL, ConsoleColor.White); } if (score >= 250) // Level up above 250 score { leveL++; score = 0; fallingRocks.Clear(); symbols.Clear(); } if (leveL == 11) // You Win here :) { Console.Clear(); Line(); PrintPosition(player.x, player.y, player.text, player.color); PrintInfo(62, 4, "Level: " + leveL, ConsoleColor.White); PrintInfo(62, 5, "Score: " + score, ConsoleColor.White); PrintInfo(62, 6, "Damage: " + damage, damageColor); PrintInfo(62, 7, "-=YOU WIN=-", ConsoleColor.Green); PrintInfo(23, 20, "-=YOU WIN=-", ConsoleColor.Green); Console.ReadLine(); PrintInfo(63, 8, "One Beer!", ConsoleColor.Yellow); PrintInfo(24, 21, "One Beer!", ConsoleColor.Yellow); PrintInfo(62, 9, "Press any key to exit.", ConsoleColor.White); Console.WriteLine(); Console.ReadLine(); return; } if (gameOver) // Game over and exitiong from game :( { PrintInfo(62, 6, "Damage: " + damage, ConsoleColor.Red); PrintInfo(62, 7, "***GAME OVER***", ConsoleColor.Red); PrintInfo(62, 8, "Press any key to exit.", ConsoleColor.White); Console.ReadLine(); Console.Write(" "); return; } // Console.Beep(13000, 150);Program moves faster without sound Thread.Sleep(150); } }
private void CreateRecipes() { Recipes = new Recipe[10]; Item[] items = new Item[9]; Item[] _rTMP = { null, null, null, null, new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null, null, null }; Recipes[0] = new Recipe(_rTMP, "NAAAME", 100, new Item[] { new Gems(null, "Red gem", "A blood red gem", ItemValues.RedGem), null, null }); Recipes[0].isKnown = true; Recipes[0].InventorySprite = _rTMP[4].InventorySprite; Item[] _rTMP2 = { null, null, null, null, new Gems(null, "Red gem", "a blood red gem", ItemValues.RedGem), null, null, null, null }; Recipes[1] = new Recipe(_rTMP2, "BWAA", 100, new Item[] { new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null }); Recipes[1].isKnown = true; Recipes[1].InventorySprite = _rTMP2[4].InventorySprite; Item[] _rTMP3 = { null, null, null, null, new Gems(null, "Yellow gem", "A yellow gem", ItemValues.YellowGem), null, null, null, null }; Recipes[2] = new Recipe(_rTMP3, "TOTO", 100, new Item[] { new Gems(null, "White gem", "A white gem", ItemValues.WhiteGem), null, null }); Recipes[2].InventorySprite = _rTMP3[4].InventorySprite; #region Rocks for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.BasaltName, ItemValues.RockBasalt); } Recipes[3] = new Recipe(items, RockBlocks.BasaltName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.BasaltName, ItemValues.BlocBasalt), null }); Recipes[3].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.DioriteName, ItemValues.RockDiorite); } Recipes[4] = new Recipe(items, RockBlocks.DioriteName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.DioriteName, ItemValues.BlocDiorite), null }); Recipes[4].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.GabbroName, ItemValues.RockGabbro); } Recipes[4] = new Recipe(items, RockBlocks.GabbroName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.GabbroName, ItemValues.BlocGabbro), null }); Recipes[4].InventorySprite = ResourcesManager.instance.IN_Bloc; //--------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------- for (int i = 0; i < 9; i++) { items[i] = new Rocks(null, Rocks.GranitName, ItemValues.RockGranit); } Recipes[5] = new Recipe(items, RockBlocks.GranitName, 100, new Item[] { null, new RockBlocks(null, RockBlocks.GranitName, ItemValues.BlocGranit), null }); Recipes[5].InventorySprite = ResourcesManager.instance.IN_Bloc; #endregion for (int i = 0; i < 9; i++) { if (i == 4) items[i] = new RawGems(null); else items[i] = null; } Recipes[6] = new Recipe(items, "Raw gem", 50, null, true, new Item[] { new Gems(null, "Red gem", "A blood red gem", ItemValues.RedGem), new Gems(null, "White gem", "A shiny white gem", ItemValues.WhiteGem), new Gems(null, "Yellow gem", "A yellow gem", ItemValues.YellowGem)}, 1); Recipes[6].InventorySprite = ResourcesManager.instance.IN_RawGem; }
static void Main() { ConsoleOptions(); // Console window's options int level = ChooseLevel(); // User can choose level rocks = new List <Rocks>(); player = new PlayerPosition(Console.WindowHeight - 1, Console.WindowWidth / 2 - 3); // Set player's start position score = 0; rockFallSpeed = 200; playerMoveSteps = 2; InitiallyAddingRocks(); // Add a few rocks at the beginning do { Console.Clear(); while (Console.KeyAvailable) { ConsoleKeyInfo userKey = Console.ReadKey(true); if (userKey.Key == ConsoleKey.LeftArrow && player.y > 1) { player = new PlayerPosition(player.x, player.y - (playerMoveSteps == 2 && player.y >= 1 ? playerMoveSteps - 1 : playerMoveSteps)); } else if (userKey.Key == ConsoleKey.RightArrow && player.y + 4 < Console.WindowWidth) { player = new PlayerPosition(player.x, player.y + (playerMoveSteps == 2 && player.y + 6 < Console.WindowWidth ? playerMoveSteps - 1 : playerMoveSteps)); } else if (userKey.Key == ConsoleKey.W) // CHEAT - Key 'W' { rockFallSpeed--; if (rockFallSpeed < 50) { rockFallSpeed = 50; } } else if (userKey.Key == ConsoleKey.S) // CHEAT - Key 'S' { rockFallSpeed++; if (rockFallSpeed > 250) { rockFallSpeed = 250; } } else if (userKey.Key == ConsoleKey.Q) // CHEAT - Key 'Q' { playerMoveSteps = 2; } else if (userKey.Key == ConsoleKey.A) // CHEAT - Key 'A' { playerMoveSteps = 1; } } // Printing all rocks for (int i = rocks.Count - 1; i >= 0; i--) { rocks[i].y++; if (rocks[i].y > Console.WindowHeight - 1) { rocks[i] = new Rocks(rnd.Next(1, Console.WindowWidth - 1), 0); } if (rocks[i].x == player.y && rocks[i].y == player.x || rocks[i].x == player.y + 1 && rocks[i].y == player.x || rocks[i].x == player.y + 2 && rocks[i].y == player.x) { Entrance(); return; } score++; rocks[i].PrintRock(); // ADD NEW ROCK if (score % level == 0) { rocks.Add(new Rocks(rnd.Next(1, Console.WindowWidth - 1), 0)); } } Console.SetCursorPosition(player.y, player.x); Console.Write("(0)"); Thread.Sleep(rockFallSpeed); }while (true); }
static void Main() { int playground = 11; byte life = 3; Console.BufferHeight = Console.WindowHeight = 20; Console.BufferWidth = Console.WindowWidth = 50; Object dwarf = new Object(); dwarf.x = 4; dwarf.y = Console.WindowHeight - 1; dwarf.color = ConsoleColor.White; dwarf.d = "(0)"; Random generator = new Random(); List<Rocks> rocks = new List<Rocks>(); List<string> typer = new List<string> { "^", "@", "*", "&", "+", "%", "$", "#", "!", ".", ";" }; Random typer_rand = new Random(); int index = typer_rand.Next(0, 10); string value = typer[index]; List<ConsoleColor> color = new List<ConsoleColor> {ConsoleColor.Red, ConsoleColor.Yellow, ConsoleColor.Cyan, ConsoleColor.Green, ConsoleColor.Magenta }; Random color_rand = new Random(); int indexColor = typer_rand.Next(0, 4); ConsoleColor rockColor = color[indexColor]; while (true) { bool hit = false; { Rocks newRock = new Rocks(); newRock.color = rockColor; newRock.x = generator.Next(0, playground); newRock.y = 0; newRock.r = value; rocks.Add(newRock); } if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) Console.ReadKey();//clear other buttons for smooth moving(not neccessary) if (pressedKey.Key == ConsoleKey.LeftArrow) { if (dwarf.x - 1 >= 0) { dwarf.x = dwarf.x - 1; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (dwarf.x + 1 < playground) { dwarf.x = dwarf.x + 1; } } } List<Rocks> newList = new List<Rocks>(); for (int i = 0; i < rocks.Count; i++) { Rocks oldRock = rocks[i]; Rocks newRock = new Rocks(); newRock.x = oldRock.x; newRock.y = oldRock.y + 1; newRock.r = oldRock.r; newRock.color = oldRock.color; if (newRock.y == dwarf.y && newRock.x == dwarf.x) { life--; hit = true; if (life <= 0) { PrintInfo(20, 8, "WASTED", ConsoleColor.DarkRed); Console.ReadLine(); return; } } if (newRock.y < Console.WindowHeight) { newList.Add(newRock); } } rocks = newList; Console.Clear(); foreach (Rocks rock in rocks) { PrintOnPosition(rock.x, rock.y, rock.r, rock.color); } if (hit) { PrintOnPosition(dwarf.x, dwarf.y, "XXX", ConsoleColor.Red); } else { PrintOnPosition(dwarf.x, dwarf.y, dwarf.d, dwarf.color); } PrintInfo(15, 5, "Lifes: " + life, ConsoleColor.White); PrintInfo(15, 5, "Lifes: " + life, ConsoleColor.White); Thread.Sleep(150); } }
static void Main() { //Declare general signs, dimensions etc. char[] rocksSymbols = { '@', '*', '&', '+', '%', '$', '#', '!', '.', ';' }; ConsoleColor[] colors = { ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.Cyan, ConsoleColor.White, ConsoleColor.Yellow }; Console.BufferHeight = Console.WindowHeight = 30; Console.BufferWidth = Console.WindowWidth = 50; int life = 3; int score = 0; int speed = 0; int level = 1; //Declare dwarf Rocks dwarf = new Rocks(); dwarf.x = Console.WindowWidth / 2; dwarf.y = Console.WindowHeight - 2; dwarf.sign = "(0)"; dwarf.color = ConsoleColor.White; //Random generator Random randomGenerator = new Random(); //Declare list of rocks on line0 List<Rocks> listOfFallingRocks = new List<Rocks>(); while (true) { //Print dwarf on the last row Console.SetCursorPosition(dwarf.x, dwarf.y); Console.ForegroundColor = dwarf.color; Console.Write(dwarf.sign); Console.ForegroundColor = ConsoleColor.Gray; //Generate rocks and print them on line 0 for (int i = 0; i < randomGenerator.Next(0, 4); i++) { Rocks fallingRocks = new Rocks(); fallingRocks.x = randomGenerator.Next(0, Console.WindowWidth); fallingRocks.y = 0; fallingRocks.c = rocksSymbols[randomGenerator.Next(0, 10)]; fallingRocks.color = colors[randomGenerator.Next(0, 7)]; listOfFallingRocks.Add(fallingRocks); Console.SetCursorPosition(fallingRocks.x, fallingRocks.y); Console.ForegroundColor = fallingRocks.color; Console.Write(fallingRocks.c); Console.ForegroundColor = ConsoleColor.Gray; } //User's imput if (Console.KeyAvailable) { ConsoleKeyInfo dwarfMovement = Console.ReadKey(); //Smooth dwarf movement while (Console.KeyAvailable) Console.ReadKey(); { } if (dwarfMovement.Key == ConsoleKey.LeftArrow) { if (dwarf.x - 1 >= 0) { dwarf.x--; } } if (dwarfMovement.Key == ConsoleKey.RightArrow) { if (dwarf.x + 1 < Console.WindowWidth - 2) { dwarf.x++; } } } Thread.Sleep(150 - speed); Console.Clear(); //Move rocks one line down List<Rocks> listOfRocksDown = new List<Rocks>(); for (int j = 0; j < listOfFallingRocks.Count; j++) { Rocks oldRock = listOfFallingRocks[j]; Rocks newRock = new Rocks(); newRock.x = oldRock.x; newRock.y = oldRock.y + 1; newRock.c = oldRock.c; newRock.color = oldRock.color; if ((newRock.x == dwarf.x && newRock.y == dwarf.y) || (newRock.x == dwarf.x + 1 && newRock.y == dwarf.y) || (newRock.x == dwarf.x + 2 && newRock.y == dwarf.y)) { life--; Console.SetCursorPosition(dwarf.x, dwarf.y); Console.ForegroundColor = ConsoleColor.Red; listOfFallingRocks.Clear(); Console.Beep(); Console.Write("X"); Thread.Sleep(300); Console.ForegroundColor = ConsoleColor.Gray; } if (life == 0) { Console.SetCursorPosition(0, Console.WindowHeight - 1); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Game over!Score->{0}.Lev->{1} ", score, level); Console.SetCursorPosition(28, Console.WindowHeight - 1); Console.Write("Press [enter] to exit"); Console.ReadLine(); Environment.Exit(0); } if (newRock.y < Console.WindowHeight - 1) { listOfRocksDown.Add(newRock); } } //Print rocks on lines1+ listOfFallingRocks = listOfRocksDown; foreach (Rocks rock1 in listOfFallingRocks) { Console.SetCursorPosition(rock1.x, rock1.y); Console.ForegroundColor = rock1.color; Console.Write(rock1.c); } Console.ForegroundColor = ConsoleColor.Gray; //Print additional info Console.SetCursorPosition(1, Console.WindowHeight - 1); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Life -->{0} Score-->{1} Level-->{2}, Speed-->{3}", life, score, level, 150 + speed); Console.ForegroundColor = ConsoleColor.Gray; score++; if (score / 200 != (score - 1) / 200) { level = level + 1; } speed = 10 * (score / 200); } }
static void Main() { int playfiledwidth = 60; int score = 0; Console.BufferHeight = Console.WindowHeight = 20; Console.BufferWidth = Console.WindowWidth = 60; Rocks dwarf = new Rocks(); dwarf.x = 30; dwarf.y = Console.WindowHeight - 1; dwarf.ch = "(.)Y(.)"; dwarf.color = ConsoleColor.Magenta; List <Rocks> rock = new List <Rocks>(); Random randomGenerator = new Random(); while (true) { { Rocks newRock = new Rocks(); switch (randomGenerator.Next(1, 11)) { case 0: newRock.color = ConsoleColor.DarkRed; break; case 1: newRock.color = ConsoleColor.Gray; break; case 2: newRock.color = ConsoleColor.Green; break; case 3: newRock.color = ConsoleColor.Yellow; break; case 4: newRock.color = ConsoleColor.DarkGray; break; case 5: newRock.color = ConsoleColor.Blue; break; case 6: newRock.color = ConsoleColor.DarkBlue; break; case 7: newRock.color = ConsoleColor.DarkGreen; break; case 8: newRock.color = ConsoleColor.DarkRed; break; case 9: newRock.color = ConsoleColor.White; break; case 10: newRock.color = ConsoleColor.DarkCyan; break; } newRock.x = randomGenerator.Next(0, playfiledwidth); newRock.y = 2; switch (randomGenerator.Next(1, 11)) { case 0: newRock.ch = "^"; break; case 1: newRock.ch = "@"; break; case 2: newRock.ch = "*"; break; case 3: newRock.ch = "&"; break; case 4: newRock.ch = "+"; break; case 5: newRock.ch = "%"; break; case 6: newRock.ch = "$"; break; case 7: newRock.ch = "#"; break; case 8: newRock.ch = "!"; break; case 9: newRock.ch = "."; break; case 10: newRock.ch = ";"; break; } rock.Add(newRock); } if (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(); } if (pressedKey.Key == ConsoleKey.LeftArrow) { if (dwarf.x - 1 >= 0) { dwarf.x = dwarf.x - 1; } } else if (pressedKey.Key == ConsoleKey.RightArrow) { if (dwarf.x - 1 <= 60) { dwarf.x = dwarf.x + 1; } } } List <Rocks> newList = new List <Rocks>(); for (int i = 0; i < rock.Count; i++) { Rocks oldRocks = rock[i]; Rocks newRocks = new Rocks(); newRocks.x = oldRocks.x; newRocks.y = oldRocks.y + 1; newRocks.ch = oldRocks.ch; newRocks.color = oldRocks.color; if (newRocks.y == dwarf.y && newRocks.x == dwarf.x + 3) { Position(dwarf.x + 2, dwarf.y, "_!_", ConsoleColor.Red); StringPosition(1, 2, "Game Over!!", ConsoleColor.Red); Console.WriteLine(); return; } if (newRocks.y < Console.WindowHeight) { newList.Add(newRocks); } } rock = newList; Console.Clear(); Position(dwarf.x, dwarf.y, dwarf.ch, dwarf.color); foreach (var rocks in rock) { Position(rocks.x, rocks.y, rocks.ch, rocks.color); } StringPosition(1, 1, "Score:" + score, ConsoleColor.Gray); Thread.Sleep(150); score++; } }
static void Main() { ConsoleOptions(); int level = ChooseLevel(); rocks = new List<Rocks>(); player = new PlayerPosition(Console.WindowHeight - 1, Console.WindowWidth / 2 - 3); score = 0; rockFallSpeed = 200; playerMoveSteps = 2; InitiallyAddingRocks(); do { Console.Clear(); while (Console.KeyAvailable) { ConsoleKeyInfo userKey = Console.ReadKey(true); if (userKey.Key == ConsoleKey.LeftArrow && player.y > 1) { player = new PlayerPosition(player.x, player.y - (playerMoveSteps == 2 && player.y >= 1 ? playerMoveSteps - 1 : playerMoveSteps)); } else if (userKey.Key == ConsoleKey.RightArrow && player.y + 4 < Console.WindowWidth) { player = new PlayerPosition(player.x, player.y + (playerMoveSteps == 2 && player.y + 6 < Console.WindowWidth ? playerMoveSteps - 1 : playerMoveSteps)); } else if (userKey.Key == ConsoleKey.W) { rockFallSpeed--; if (rockFallSpeed < 50) rockFallSpeed = 50; } else if (userKey.Key == ConsoleKey.S) { rockFallSpeed++; if (rockFallSpeed > 250) rockFallSpeed = 250; } else if (userKey.Key == ConsoleKey.Q) { playerMoveSteps = 2; } else if (userKey.Key == ConsoleKey.A) { playerMoveSteps = 1; } } // Printing all rocks for (int i = rocks.Count - 1; i >= 0; i--) { rocks[i].y++; if (rocks[i].y > Console.WindowHeight - 1) { rocks[i] = new Rocks(random.Next(1, Console.WindowWidth - 1), 0); } if (rocks[i].x == player.y && rocks[i].y == player.x || rocks[i].x == player.y + 1 && rocks[i].y == player.x || rocks[i].x == player.y + 2 && rocks[i].y == player.x) { Entrance(); return; } score++; rocks[i].PrintRock(); // Add new rock if (score % level == 0) rocks.Add(new Rocks(random.Next(1, Console.WindowWidth - 1), 0)); } Console.SetCursorPosition(player.y, player.x); Console.Write("(0)"); Thread.Sleep(rockFallSpeed); } while (true); }
static void InitiallyAddingRocks() { // Add few rocks for (int i = 0; i < random.Next(15, 30); i++) { Rocks newRock; do { newRock = new Rocks(random.Next(1, Console.WindowWidth - 1), random.Next(0, 5)); } while (rocks.Contains(newRock)); rocks.Add(newRock); } }
public static IEnumerable <Rock> RocksOnWall(string wallId) { return(Rocks.Where(x => x.Wall == wallId)); }
/// <summary> /// Loads the mesh /// </summary> private void Load() { //now read input file using (ReaderUtilities sr = new ReaderUtilities(FileName)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.StartsWith("ROCKS")) { Rocks = new Rocks(); Rocks.ReadFromStream(sr); foreach (Element e in Elements) { e.rock = Rocks[e.Material-1]; } } else if (line.StartsWith("INCON")) { while ((line = sr.ReadLine().TrimEnd()) != String.Empty) { if (line.StartsWith("+++")) break; string elname = line.Substring(0,5); if (Elements.Contains(elname)) { Elements[elname].Porosity = ReaderUtilities.SplitIntoDoubles(line, 15, 15)[0]; if (line.Length > 31) Elements[elname].PrimaryVariablesIndex = int.Parse(line.Substring(31, 1)); Elements[elname].PrimaryVaribles = ReaderUtilities.SplitIntoDoubles(sr.ReadLine(), 0, 20); } } } else if (line.StartsWith("PARAM")) { sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); line = sr.ReadLine(); var arr = ReaderUtilities.SplitIntoDoubles(line, 0, 20); foreach (var el in Elements) { if (el.PrimaryVaribles == null) el.PrimaryVaribles = arr.ToArray(); } } else if (line.StartsWith("TSXCD")) { var arr = sr.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var ints = arr.Select(var => int.Parse(var)); foreach (var i in ints.Skip(1)) { if (i<=Elements.Count) detailedTimeSeries.Add(Elements[i - 1]); } } else if (line.StartsWith("GENER")) { Wells = new Gener(); Wells.ReadFromStream(sr); } } FileContent = sr.FileContent.ToString(); } NotifyPropertyChanged("FileContent"); NotifyPropertyChanged("DetailedTimeSeries"); }
public static Rock RockById(string rockId) { return(Rocks.Where(x => x.RockID == rockId).Single()); }
public override void Update(GameTime gameTime, StateManager screen, GamePadState gamePadState, MouseState mouseState, KeyboardState keyState, InputHandler input) { /* * Laser Collision: l1.StartX (238.5262) l1.StartY (283.2247) l1.EndX (238.5262) l1.EndY (303.2247) * Rock Collision: l2.StartX (300) l2.StartY (375) l2.EndX (300) l2.EndY (300) */ //Line2D.Intersects(new Line2D(238.5262f, 283.2247f, 238.5262f, 303.2247f), // new Line2D(300, 375, 300, 300)); if (!playerShip1.gameEnded) { //Only Active During Play if (input.KeyboardState.WasKeyPressed(Keys.P)) { PauseScreen pause = new PauseScreen(); screen.Push(pause); } //Only Active During Play if (input.KeyboardState.WasKeyPressed(Keys.Escape)) { screen.Pop(); AttractScreen attract = new AttractScreen(highScore); screen.Push(attract); } //Only Active During Play if (input.KeyboardState.WasKeyPressed(Keys.Enter)) { //Console.WriteLine($"playerShip1.rotation: {playerShip1.Rotation}"); if (activeLasers.Count() < 1) { //activeLasers.First.Value.Dispose(); //activeLasers.Remove(activeLasers.First); laser = new Laser(StateManager.Game, playerShip1.position.X, playerShip1.position.Y, playerShip1.Rotation, true); laser.Initialize(); activeLasers.AddLast(laser); } } //Check Collision if (!playerShip1.crashed) { elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime > TimeSpan.FromSeconds(.00000000001)) { playerShip1List = playerShip1.ConvertLanderLine2D(); CheckCollisionRocks(playerShip1List); } } } else //If the Game Has ended { /*if(player runs out of lives) * if(player qualifies for High Score) * Send them to High Score Screen * else * Send them to Attract Screen */ if (highScore.CheckScore(playerShip1.score)) { highScore.score = playerShip1.score; highScore.active = true; screen.Pop(); HighScoreScreen highScoreScreen = new HighScoreScreen(highScore); screen.Push(highScoreScreen); } else { screen.Pop(); AttractScreen attract = new AttractScreen(highScore); screen.Push(attract); } } playerShip1.Update(gameTime); if (activeLasers.Count > 0) { foreach (Laser l in activeLasers) { l.Update(gameTime); } } if (activeRocks.Count > 0) { foreach (Rocks r in activeRocks) { r.Update(gameTime); } } if (activeEnemyShips.Count > 0) { foreach (EnemyShip e in activeEnemyShips) { //e.Update(gameTime); } } #region Determine if to add Rocks or EnemyShip if (activeRocks.Count < 1) { Random rand = new Random(); int positionX = 0; int positionY = 0; float angle = 0; while (activeRocks.Count < 6) { do { positionX = rand.Next(0, StateManager.GraphicsDevice.Viewport.Width); positionY = rand.Next(0, StateManager.GraphicsDevice.Viewport.Height); } while ( (Math.Abs(positionX - playerShip1.position.X) < 100) && (Math.Abs(positionY - playerShip1.position.Y) < 100)); angle = rand.Next(0, 361); Rocks newRock = new Rocks(StateManager.Game, positionX, positionY, (float)(angle * Math.PI / 180), 1, 3); newRock.Initialize(); activeRocks.AddLast(newRock); } //StateManager.GraphicsDevice.Viewport.Width; } #endregion }
static void Main() { int livesCount = 4; int points = 0; Console.BufferHeight = Console.WindowHeight; Console.BufferWidth = Console.WindowWidth; Rocks dwarf = new Rocks(); dwarf.x = Console.WindowWidth - 42; dwarf.y = Console.WindowHeight - 1; dwarf.type = "(O)"; dwarf.color = ConsoleColor.White; Random rocksRandomizer = new Random(); List<Rocks> fallingSymbols = new List<Rocks>(); List<string> symbolType = new List<string> {"^", "@", "+", "&", "%", "$", "!", "#", ".", ";", "*", "-"}; while (true) { bool isCollision = false; Rocks newSymbol = new Rocks(); newSymbol.x = rocksRandomizer.Next(0, Console.WindowWidth); newSymbol.y = 2; newSymbol.color = (ConsoleColor)rocksRandomizer.Next((int)ConsoleColor.DarkBlue, (int)ConsoleColor.White); newSymbol.type = symbolType[rocksRandomizer.Next(symbolType.Count)]; fallingSymbols.Add(newSymbol); if (Console.KeyAvailable) { ConsoleKeyInfo userInput = Console.ReadKey(true); while (Console.KeyAvailable) { Console.ReadKey(true); } if (userInput.Key == ConsoleKey.LeftArrow) { if (dwarf.x - 1 >= 0) { dwarf.x = dwarf.x - 1; } } else if (userInput.Key == ConsoleKey.RightArrow) { if (dwarf.x + 1 < Console.WindowWidth - 3) { dwarf.x = dwarf.x + 1; } } } List<Rocks> randomList = new List<Rocks>(); for (int i = 0; i < fallingSymbols.Count; i++) { Rocks previousSymbol = fallingSymbols[i]; Rocks nextSymbol = new Rocks(); nextSymbol.x = previousSymbol.x; nextSymbol.y = previousSymbol.y + 1; nextSymbol.type = previousSymbol.type; nextSymbol.color = previousSymbol.color; if ((nextSymbol.x == dwarf.x || nextSymbol.x == dwarf.x + 1 || nextSymbol.x == dwarf.x + 2) && (nextSymbol.y == dwarf.y || nextSymbol.y == dwarf.y + 1 || nextSymbol.y == dwarf.y + 2)) { livesCount--; points = points - 100; isCollision = true; if (livesCount <= 0) { PrintStringOnPosition(31, 0, "GAME OVER!!!", ConsoleColor.Red); PrintStringOnPosition(28, 1, "Press [enter] to exit", ConsoleColor.Red); Console.ReadLine(); Environment.Exit(0); } } if (nextSymbol.y < Console.WindowHeight - 1) { randomList.Add(nextSymbol); } } fallingSymbols = randomList; Console.Clear(); if (isCollision) { fallingSymbols.Clear(); PrintOnPosition(dwarf.x, dwarf.y, ":( ", ConsoleColor.Red); } else { PrintOnPosition(dwarf.x, dwarf.y, dwarf.type, dwarf.color); points ++; } foreach (Rocks symbol in fallingSymbols) { PrintOnPosition(symbol.x, symbol.y, symbol.type, symbol.color); } PrintStringOnPosition(35, 0, "Lives: " + livesCount); PrintStringOnPosition(35, 1, "Score: " + points, ConsoleColor.Cyan); Thread.Sleep(150); } }