public void Run() { Console.ForegroundColor = ConsoleColor.Green; Screen screen = new Screen(10, 10); // add a couple of walls for (int i = 0; i < 3; i++) { new Wall(1, 2 + i, screen); } for (int i = 0; i < 4; i++) { new Wall(3 + i, 4, screen); } // add a player player = new Player(0, 0, screen, "Zelda"); // add a treasure Treasure treasure = new Treasure(5, 2, screen); //set initial value left to 1 Player.TLeft = 1; //adding teleport Teleport teleport1 = new Teleport(9, 0, screen); //adding nomnoms Nomnom nom1 = new Nomnom(8, 3, screen); Nomnom nom2 = new Nomnom(6, 7, screen); Nomnom nom3 = new Nomnom(2, 6, screen); //set inital val left to 3 Player.NomsLeft = 3; // add some monsters List <Monster> mons = new List <Monster>(); mons.Add(new Monster(9, 9, screen)); // initially print the game board String setup = "Welcome!\nCollect at least 2 Nomnoms ✧ "; setup += "and 1 Treasure 𓇽 to win.\nMake sure not to "; setup += "let the monster get you or the items!\n\n"; setup += "Use the teleportation device Ⓞ to travel\n"; setup += "from the bottom of the board to the top.\n"; setup += "And *one* more thing -- make sure not to "; setup += "step\non items and squish them!\n\nGood luck >ᴗ<"; PrintScreen(screen, setup, Menu()); Boolean gameOver = false; while (!gameOver) { char input = Console.ReadKey(true).KeyChar; String message = ""; if (Eq(input, 'q')) { break; } else if (Eq(input, 'w')) { player.Move(-1, 0); } else if (Eq(input, 's')) { player.Move(1, 0); } else if (Eq(input, 'a')) { player.Move(0, -1); } else if (Eq(input, 'd')) { player.Move(0, 1); } else if (Eq(input, ' ')) { //hop foward player.Move(-2, 0); } else if (Eq(input, 'i')) { message += player.Action(-1, 0) + "\n"; } else if (Eq(input, 'k')) { message += player.Action(1, 0) + "\n"; } else if (Eq(input, 'j')) { message += player.Action(0, -1) + "\n"; } else if (Eq(input, 'l')) { message += player.Action(0, 1) + "\n"; } else if (Eq(input, 'v')) { // TODO: handle inventory message = "You have nothing\n"; } else { message = $"Unknown command: {input}"; } // OK, now move the monster foreach (Monster mon in mons) { // TODO: Make monsters smarter, so they jump on the player, if it's possible to do so List <Tuple <int, int> > moves = screen.GetLegalMoves(mon.Row, mon.Col); if (moves.Count == 0) { continue; } //monsters move randomly var(deltaRow, deltaCol) = moves[random.Next(moves.Count)]; if (screen[mon.Row + deltaRow, mon.Col + deltaCol] is Player) { // the monster got the player! mon.Token = "💀"; message += "Oh no! A monster got you *෴ *\nGAME OVER\n"; gameOver = true; } else if (screen[mon.Row + deltaRow, mon.Col + deltaCol] is Treasure) { // the monster got the Treasure Player.TLeft -= 1; if (Player.TLeft == 0) { message += "Oh no! The Treasure was stolen!"; message += "\nGAME OVER *෴ *\n\n"; gameOver = true; } } else if (screen[mon.Row + deltaRow, mon.Col + deltaCol] is Nomnom) { // the monster got a Nomnom Player.NomsLeft -= 1; if (Player.NomsLeft < 2) { message += "Oh no! A Nomnom is gone and there\naren't enough left for you!"; message += "\nGAME OVER *෴ *\n\n"; gameOver = true; break; } else { message += "Oh no! A Nomnom was eaten!"; message += "\nThere are " + Player.NomsLeft + " remaining."; } } mon.Move(deltaRow, deltaCol); } //win game if (Player.Noms == 2 && Player.Chest == 1) { message = "Great job; you won the game!\n\n~(‾▿‾~)(~‾▿‾)~"; gameOver = true; PrintScreen(screen, message, ""); break; } PrintScreen(screen, message, Menu()); } }
public void Run() { Console.ForegroundColor = ConsoleColor.Green; Screen screen = new Screen(10, 10); // add a couple of walls for (int i = 0; i < 3; i++) { new Wall(1, 2 + i, screen); } for (int i = 0; i < 4; i++) { new Wall(3 + i, 4, screen); } // add a player Player player = new Player(0, 0, screen, "Zelda"); // add a treasure Treasure treasure = new Treasure(6, 2, screen); // add the acid wash trigger AcidTrigger acidPlate = new AcidTrigger(7, 5, screen); // add a trap at a random location Tuple <int, int> loc = screen.GetLegalRandPlace(screen); Trap trap = new Trap(loc.Item1, loc.Item2, screen); // add some mobs List <MovingGameObject> mobs = new List <MovingGameObject>(); mobs.Add(new Mob(9, 9, screen)); //add some special walls List <MovingGameObject> movers = new List <MovingGameObject>(); for (int i = 0; i < 3; i++) { Tuple <int, int> locMW = screen.GetLegalRandPlace(screen); movers.Add(new MovingWall(locMW.Item1, locMW.Item2, screen, 1)); } // add the pressure plate Tuple <int, int> locPP = screen.GetLegalRandPlace(screen); PressurePlate pp = new PressurePlate(locPP.Item1, locPP.Item2, screen); // initially print the game board PrintScreen(screen, "Welcome!", Menu()); Boolean gameOver = false; Boolean dead = false; Boolean deathWave = false; List <MovingGameObject> acids = new List <MovingGameObject>(); while (!gameOver) { char input = Console.ReadKey(true).KeyChar; String message = ""; message += screen.MoveManyRand(acids, ref gameOver, ref dead); if (deathWave) { for (int i = 0; i < 4; i++) { switch (i) { case 0: acids.Add(new Acid(acidPlate.Row - 1, acidPlate.Col, screen, 1)); break; case 1: acids.Add(new Acid(acidPlate.Row, acidPlate.Col, screen, 1)); break; case 2: acids.Add(new Acid(acidPlate.Row, acidPlate.Col - 1, screen, 1)); break; default: continue; } } } if (Eq(input, 'q')) { break; } else if (Eq(input, 'w')) { player.Move(-1, 0); } else if (Eq(input, 's')) { player.Move(1, 0); } else if (Eq(input, 'a')) { player.Move(0, -1); } else if (Eq(input, 'd')) { player.Move(0, 1); } else if (Eq(input, 'i')) { message += player.Action(-1, 0, ref gameOver, ref deathWave) + "\n"; } else if (Eq(input, 'k')) { message += player.Action(1, 0, ref gameOver, ref deathWave) + "\n"; } else if (Eq(input, 'j')) { message += player.Action(0, -1, ref gameOver, ref deathWave) + "\n"; } else if (Eq(input, 'l')) { message += player.Action(0, 1, ref gameOver, ref deathWave) + "\n"; } else if (Eq(input, 'v')) { // TODO: handle inventory message = "You have nothing\n"; } else { message = $"Unknown command: {input}"; } if (screen[trap.Row, trap.Col] is Player) { // The trap got the player! player.Token = "*"; message += "You have fallen in to a trap and died\nTOO BAD SO SAD...\nGAME OVER\n"; dead = true; gameOver = true; } else if (screen[pp.Row, pp.Col] is Player) { message = pp.Activate(); } else if (screen[treasure.Row, treasure.Col] is Player) { message += "Oh no! You crushed the delicate Treasure\nYou must pick it up using IJKL\nGAME OVER!!!!!!!!\n"; gameOver = true; } // Move the walls if the pressure place has not been activated if (pp.IsMoving) { message += screen.MoveManyRand(movers, ref gameOver, ref dead); } // OK, now move the mobs message += screen.MoveManyRand(mobs, ref gameOver, ref dead); if (gameOver && dead) { player.Token = "*"; } //Moved this entire block of code in to screen.MoveManyRand // foreach (Mob mob in mobs){ // // TODO: Make mobs smarter, so they jump on the player, if it's possible to do so // List<Tuple<int, int>> moves = screen.GetLegalMoves(mob.Row, mob.Col, mob.Speed); // if (moves.Count == 0){ // continue; // } // // mobs move randomly // // TBLUS:: For some reason I couldnt get tuple destructuring to work in // // vscode // Tuple<int, int> t = moves[random.Next(moves.Count)]; // int deltaRow = t.Item1; // int deltaCol = t.Item2; // // var (deltaRow, deltaCol) = moves[random.Next(moves.Count)]; // if (screen[mob.Row + deltaRow, mob.Col + deltaCol] is Player){ // // the mob got the player! // mob.Token = "*"; // message += "A MOB GOT YOU! GAME OVER\n"; // gameOver = true; // } // mob.Move(deltaRow, deltaCol); // } PrintScreen(screen, message, Menu()); } }
public void Run() { Console.ForegroundColor = ConsoleColor.White; Screen screen = new Screen(10, 10); // add a couple of walls for (int i = 0; i < 3; i++) { new Wall(1, 2 + i, screen); } for (int i = 0; i < 4; i++) { new Wall(3 + i, 4, screen); } // add a player Player player = new Player(0, 0, screen, "Zelda"); // add a treasure at a random location int tRow = random.Next(1, 9); int tCol = random.Next(1, 9); Treasure treasure = new Treasure(tRow, tCol, screen); // add a mine at a random locations int mRow = random.Next(3, 9); int mCol = random.Next(1, 9); Mine mine = new Mine(mRow, mCol, screen); // add some mobs List <Mob> mobs = new List <Mob>(); mobs.Add(new Mob(9, 9, screen)); // initially print the game board PrintScreen(screen, "Welcome!", Menu()); Boolean gameOver = false; while (!gameOver) { char input = Console.ReadKey(true).KeyChar; String message = ""; if (Eq(input, 'q')) { break; } else if (Eq(input, 'w')) { player.Move(-1, 0); } else if (Eq(input, 's')) { player.Move(1, 0); } else if (Eq(input, 'a')) { player.Move(0, -1); } else if (Eq(input, 'd')) { player.Move(0, 1); } else if (Eq(input, 'i')) { message += player.Action(-1, 0) + "\n"; } else if (Eq(input, 'k')) { message += player.Action(1, 0) + "\n"; } else if (Eq(input, 'j')) { message += player.Action(0, -1) + "\n"; } else if (Eq(input, 'l')) { message += player.Action(0, 1) + "\n"; } else if (Eq(input, 'v')) { message = "You have nothing\n"; } else { message = $"Unknown command: {input}"; } if (!treasure.isPresent && player.numT < 5) //add a new treasure when one is collected also add another mob { int newTRow = random.Next(1, 9); int newTCol = random.Next(1, 9); if ((screen[newTRow, newTCol] is GameObject)) //Check to make sure treasure isnt being added in place of another object { newTRow = random.Next(1, 9); newTCol = random.Next(1, 9); } treasure = new Treasure(newTRow, newTCol, screen); int newMobRow = random.Next(1, 9); int newMobCol = random.Next(4, 9); if ((screen[newMobRow, newMobCol] is GameObject)) //Check to make sure mob isnt being added in place of another object { newMobRow = random.Next(1, 9); newMobCol = random.Next(4, 9); } mobs.Add(new Mob(newMobRow, newMobCol, screen)); } if (player.numT > 4) //player wins when 5 treasures are collected { message += "YOU WIN!\n ALL TREASURES COLLECTED"; gameOver = true; } if (screen[mRow, mCol] is Player) // the player stepped on a mine { if (!mine.isDefused) { mine.Token = "*"; message += "GAME OVER!\nBOOM! YOU STEPPED ON A MINE!\n"; gameOver = true; } } // OK, now move the mobs foreach (Mob mob in mobs) { List <Tuple <int, int> > moves = screen.GetLegalMoves(mob.Row, mob.Col); if (moves.Count == 0) { continue; } // mobs move randomly var(deltaRow, deltaCol) = moves[random.Next(moves.Count)]; if (screen[mob.Row + deltaRow, mob.Col + deltaCol] is Mine) { // the mob stepped on a mine! mob.Token = "O"; message += "BOOM!\n"; mob.Delete(); mob.isDead = true; mine.isDefused = true; mine.Delete(); } if (screen[mob.Row + deltaRow, mob.Col + deltaCol] is Player && !mob.isDead) { // the mob got the player! mob.Token = "*"; message += "GAME OVER!\n A MOB GOT YOU!\n"; gameOver = true; } if (!mob.isDead) { mob.Move(deltaRow, deltaCol); } } PrintScreen(screen, message, Menu()); } }
public void Run() { Console.ForegroundColor = ConsoleColor.Green; Screen screen = new Screen(10, 10); // add a couple of walls for (int i = 0; i < 3; i++) { new Wall(1, 2 + i, screen); } for (int i = 0; i < 4; i++) { new Wall(3 + i, 4, screen); } // add a player Player player = new Player(0, 0, screen, "Zelda"); // add a treasure Treasure treasure = new Treasure(6, 2, screen); // add a sword Sword sword = new Sword(8, 7, screen); // add some mobs List <Mob> mobs = new List <Mob>(); mobs.Add(new Mob(9, 9, screen)); // initially print the game board PrintScreen(screen, "Welcome!", Menu()); Boolean gameOver = false; Boolean hasTreasure = false; while (!gameOver) { char input = Console.ReadKey(true).KeyChar; String message = ""; int?actionRow = null; int?actionCol = null; if (Eq(input, 'q')) { break; } else if (Eq(input, 'w')) { player.Move(-1, 0); } else if (Eq(input, 's')) { player.Move(1, 0); } else if (Eq(input, 'a')) { player.Move(0, -1); } else if (Eq(input, 'd')) { player.Move(0, 1); } else if (Eq(input, 'i')) { message += player.Action(-1, 0) + "\n"; actionRow = player.Row - 1; actionCol = player.Col; } else if (Eq(input, 'k')) { message += player.Action(1, 0) + "\n"; actionRow = player.Row + 1; actionCol = player.Col; } else if (Eq(input, 'j')) { message += player.Action(0, -1) + "\n"; actionRow = player.Row; actionCol = player.Col - 1; } else if (Eq(input, 'l')) { message += player.Action(0, 1) + "\n"; actionRow = player.Row; actionCol = player.Col + 1; } else if (Eq(input, 'v')) { // TODO: handle inventory message = "You have nothing\n"; } else { message = $"Unknown command: {input}"; } if (message.Equals("Yay, we got the treasure!\n")) { hasTreasure = true; } // OK, now move the mobs foreach (Mob mob in mobs) { // TODO: Make mobs smarter, so they jump on the player, if it's possible to do so if ((actionRow != null) && player.Armed) { if ((mob.Row == actionRow) && (mob.Col == actionCol)) { gameOver = true; mob.Token = "*"; } } else { List <Tuple <int, int> > moves = screen.GetLegalMoves(mob.Row, mob.Col); if (moves.Count == 0) { continue; } // mobs move randomly var(deltaRow, deltaCol) = moves[random.Next(moves.Count)]; if (screen[mob.Row + deltaRow, mob.Col + deltaCol] is Player) { if (!hasTreasure) { mob.Token = "*"; message += "A MOB GOT YOU! GAME OVER\n"; gameOver = true; } else { message += "You used the treasure to revive yourself\n"; hasTreasure = false; } } mob.Move(deltaRow, deltaCol); } } PrintScreen(screen, message, Menu()); } }
public void Run() { Console.ForegroundColor = ConsoleColor.Green; Screen screen = new Screen(25, 25); // Horizontal Walls // line 1 walls for (int i = 0; i < 8; i++){ new HorizontalWall(1, i, screen); } for (int i = 11; i < 16; i++){ new HorizontalWall(1, i, screen); } for (int i = 19; i < 23; i++){ new HorizontalWall(1, i, screen); } // line 2 walls for (int i = 12; i < 13; i++){ new HorizontalWall(2, i, screen); } for (int i = 14; i < 15; i++){ new HorizontalWall(2, i, screen); } // line 3 walls for (int i = 2; i < 8; i++){ new HorizontalWall(3, i, screen); } // line 6 walls for (int i = 5; i < 12; i++){ new HorizontalWall(6, i, screen); } // line 8 walls for (int i = 5; i < 16; i++){ new HorizontalWall(8, i, screen); } // line 10 walls for (int i = 2; i < 10; i++){ new HorizontalWall(10, i, screen); } for (int i = 12; i < 20; i++){ new HorizontalWall(10, i, screen); } // line 12 walls for (int i = 2; i < 10; i++){ new HorizontalWall(12, i, screen); } for (int i = 12; i < 19; i++){ new HorizontalWall(12, i, screen); } // line 14 walls for (int i = 6; i < 20; i++){ new HorizontalWall(14, i, screen); } // line 16 walls for (int i = 2; i < 16; i++){ new HorizontalWall(16, i, screen); } // line 21 walls for (int i = 5; i < 20; i++){ new HorizontalWall(21, i, screen); } // line 23 walls for (int i = 2; i < 23; i++){ new HorizontalWall(23, i, screen); } // vertical wals // vertical walls for 2 for (int i = 4; i < 10; i++){ new VerticalWall(i, 2, screen); } for (int i = 13; i < 16; i++){ new VerticalWall(i, 2, screen); } for (int i = 17; i < 23; i++){ new VerticalWall(i, 2, screen); } // vertical walls for 5 for (int i = 7; i < 8; i++){ new VerticalWall(i, 5, screen); } for (int i = 17; i < 21; i++){ new VerticalWall(i, 5, screen); } // vertical walls for 7 for (int i = 2; i < 3; i++){ new VerticalWall(i, 7, screen); } // vertical walls for 9 for (int i = 11; i < 12; i++){ new VerticalWall(i, 9, screen); } // vertical walls for 11 for (int i = 2; i < 6; i++){ new VerticalWall(i, 11, screen); } // vertical walls for 12 for (int i = 11; i < 12; i++){ new VerticalWall(i, 12, screen); } // vertical walls for 14 for (int i = 2; i < 8; i++){ new VerticalWall(i, 15, screen); } // vertical walls for 19 for (int i = 2; i < 10; i++){ new VerticalWall(i, 19, screen); } for (int i = 15; i < 21; i++){ new VerticalWall(i, 19, screen); } // vertical walls for 22 for (int i = 2; i < 23; i++){ new VerticalWall(i, 22, screen); } // end of walls // add a teleport Teleport teleport1 = new Teleport(2,5, screen); Teleport teleport2 = new Teleport(2,13, screen); // add teleport exits Teleportexit teleport_exit1 = new Teleportexit(7,7, screen); Teleportexit teleport_exit2 = new Teleportexit(2,20, screen); // add a player Player player = new Player(0, 0, screen, "Zelda"); // add a treasure Treasure treasure1 = new Treasure(20, 7, screen); Treasure treasure2 = new Treasure(11, 14, screen); Treasure treasure3 = new Treasure(11, 7, screen); Treasure treasure4 = new Treasure(17, 3, screen); //add a weapon Weapon DESTRUCTION = new Weapon(7, 13, screen); // add some mobs List<Mob> mobs = new List<Mob>(); mobs.Add(new Mob(17, 10, screen)); mobs.Add(new Mob(18, 11, screen)); mobs.Add(new Mob(19, 12, screen)); mobs.Add(new Mob(20, 13, screen)); mobs.Add(new Mob(17, 13, screen)); mobs.Add(new Mob(18, 12, screen)); mobs.Add(new Mob(19, 11, screen)); mobs.Add(new Mob(20, 10, screen)); mobs.Add(new Mob(11, 19, screen)); mobs.Add(new Mob(11, 20, screen)); mobs.Add(new Mob(11, 21, screen)); // initially print the game board PrintScreen(screen, "Welcome!", Menu()); Boolean gameOver = false; while (!gameOver) { char input = Console.ReadKey(true).KeyChar; String message = ""; if (Eq(input, 'q')) { // quit the game break; } else if (Eq(input, 'w')) { // walking player.Move(-1, 0); } else if (Eq(input, 's')) { player.Move(1, 0); } else if (Eq(input, 'a')) { player.Move(0, -1); } else if (Eq(input, 'd')) { player.Move(0, 1); // interacting with objects } else if (Eq(input, 'i')) { message += player.Action(-1, 0) + "\n"; } else if (Eq(input, 'k')) { message += player.Action(1, 0) + "\n"; } else if (Eq(input, 'j')) { message += player.Action(0, -1) + "\n"; } else if (Eq(input, 'l')) { message += player.Action(0, 1) + "\n"; } else if (Eq(input, 'v')) { message = "You have nothing\n"; } else { message = $"Unknown command: {input}"; } foreach (Mob mob in mobs){ List<Tuple<int, int>> moves = screen.GetLegalMoves(mob.Row, mob.Col); if (moves.Count == 0){ continue; } Tuple<int, int> t = moves[random.Next(moves.Count)]; int deltaRow = t.Item1; int deltaCol = t.Item2; if (screen[mob.Row + deltaRow, mob.Col + deltaCol] is Player) && mob.health > 0 /*had to add this so that mob would stop killing the player after it dies*/){ mob.Token = "~"; message += "A MOB GOT YOU! GAME OVER\n"; gameOver = true; mob.Move(deltaRow, deltaCol); //added this so now everything should work }