public void Setup(bool same) { if (!same) //If new map { map = new GameMap(); map.Start(); } endGame = false; //setup wump = new Wumpus(); player = new Player(); bats = new Bat(); wump.room = map.getWump(); player.room = map.getCurrent(); int[] temp = map.getAdjacent(player.room); doors[0] = GameObject.Find("Left Door"); doors[1] = GameObject.Find("Middle Door"); doors[2] = GameObject.Find("Right Door"); for (int i = 0; i < 3; i++) { doors[i].GetComponent<Door>().doorNum = temp[i]; } bats.room = map.getBat(); currentNum.text = "Current Room: " + player.room; //GameObject[] doors = FindObjectsOfType(typeof(Door)) as GameObject[]; for (int i = 0; i < 20; i++) { rooms[i] = GameObject.Find("/Rooms/Room (" + i + ")"); } Warnings(); //check for initial warnings }
public void Setup(bool same) { if (!same) //If new map { map = new GameMap(); map.Start(); } endGame = false; //setup wump = new Wumpus(); player = new Player(); bats = new Bat(); wump.room = map.getWump(); player.room = map.getCurrent(); int[] temp = map.getAdjacent(player.room); doors[0] = GameObject.Find("Left Door"); doors[1] = GameObject.Find("Middle Door"); doors[2] = GameObject.Find("Right Door"); for (int i = 0; i < 3; i++) { doors[i].GetComponent <Door>().doorNum = temp[i]; } bats.room = map.getBat(); currentNum.text = "Current Room: " + player.room; //GameObject[] doors = FindObjectsOfType(typeof(Door)) as GameObject[]; for (int i = 0; i < 20; i++) { rooms[i] = GameObject.Find("/Rooms/Room (" + i + ")"); } Warnings(); //check for initial warnings }
//initializes a random new game public static void Initialize(ref bool play, out Map cave, out Player player, out Wumpus wumpus, out SuperBats bats, out Pit pitA, out Pit pitB) { //will start the main game loop later play = true; //initialize object locations int[] locations = generateLocations(); //creates a new map cave = new Map(20, locations[0], locations[1], locations[2], locations[3], locations[4]); //creates the player player = new Player(cave.Oloc[0]); //creates the wumpus wumpus = new Wumpus(cave.Oloc[1]); //creates a group of super bats bats = new SuperBats(cave.Oloc[2]); //creates a pit pitA = new Pit(cave.Oloc[3]); //creates a pit pitB = new Pit(cave.Oloc[4]); Console.WriteLine("HUNT THE WUMPUS - A new cave has been generated"); }
/// <summary> /// Create an instance of Wumpus /// wumpus.parent = room /// </summary> /// <param name="room">Room of wumpus</param> /// <returns>ref to wumpus</returns> private Wumpus MakeWumpus(Room room) { if (room == null) { return(null); } Wumpus wumpus = Instantiate <Wumpus>(wumpusPrefab, room.transform.position + new Vector3(0, 1, 0), Quaternion.Euler(0, 180, 0), room.roomObject.transform); return(wumpus); }
public EndState TakeTurn() { Logger.Write(""); var es = Wumpus.TakeTurn(this); if (!es.IsGameOver) { var roomsAdjacentToPlayer = AdjacentTo[Player.RoomNumber]; _hazards.ForEach(h => { if (roomsAdjacentToPlayer.Contains(h.RoomNumber)) { h.PrintHazardWarning(); } }); Player.PrintLocation(); } return(es); }
public void testHasOccupantType() { Wumpus wumpus = new Wumpus("Wumpy", rooms[0]); Bat bat = new Bat("Batty", rooms[4] ); Player player1 = new Player("Marie", rooms[1]); foreach (Room room in rooms) { if (room.hasOccupantType(EntityType.wumpus)) Console.WriteLine("Room " + room.id + " has a wumpus"); if (room.hasOccupantType(EntityType.bat)) Console.WriteLine("Room " + room.id + " has a bat"); if (room.hasOccupantType(EntityType.pit)) Console.WriteLine("Room " + room.id + " has a pit"); if (room.hasOccupantType(EntityType.player)) Console.WriteLine("Room " + room.id + " has a player"); if (room.hasOccupantType(EntityType.arrow)) Console.WriteLine("Room " + room.id + " has an arrow"); } }
public Map(GraphicsDevice graphicsDevice, bool isCheatMode = false) { _graphicsDevice = graphicsDevice; IsCheatMode = isCheatMode; CreateRooms(); var occupiedRooms = new HashSet <int>(); Player = new Player(GetRandomAvailableRoom(occupiedRooms), this); Wumpus = new Wumpus(GetRandomAvailableRoom(occupiedRooms)); var bottomlessPit1 = new BottomlessPit(GetRandomAvailableRoom(occupiedRooms)); var bottomlessPit2 = new BottomlessPit(GetRandomAvailableRoom(occupiedRooms)); var superbats1 = new SuperBats(GetRandomAvailableRoom(occupiedRooms)); var superbats2 = new SuperBats(GetRandomAvailableRoom(occupiedRooms)); _hazards = new List <Hazard> { Wumpus, bottomlessPit1, bottomlessPit2, superbats1, superbats2 }; _deadlyHazards = new List <DeadlyHazard> { Wumpus, bottomlessPit1, bottomlessPit2 }; _superBats = new List <SuperBats> { superbats1, superbats2 }; _roomsWithStaticHazards = new HashSet <int> { superbats1.RoomNumber, superbats2.RoomNumber, bottomlessPit1.RoomNumber, bottomlessPit2.RoomNumber }; if (isCheatMode) { PrintHazards(); } }
public void Setup(bool same) { if (!same) //If new map { map = new GameMap(); map.Start(); } endGame = false; //setup wump = new Wumpus(); player = new Player(); bats = new Bat(); wump.room = map.getWump(); player.room = map.getCurrent(); bats.room = map.getBat(); for (int i = 0; i < 20; i++) { rooms[i] = GameObject.Find("Room (" + i + ")"); rooms[i].GetComponent<Room>().player = false; } Warnings(); //check for initial warnings rooms[player.room].GetComponent<Room>().player = true; //show player room }
public void Setup(bool same) { if (!same) //If new map { map = new GameMap(); map.Start(); } endGame = false; //setup wump = new Wumpus(); player = new Player(); bats = new Bat(); wump.room = map.getWump(); player.room = map.getCurrent(); bats.room = map.getBat(); for (int i = 0; i < 20; i++) { rooms[i] = GameObject.Find("Room (" + i + ")"); rooms[i].GetComponent <Room>().player = false; } Warnings(); //check for initial warnings rooms[player.room].GetComponent <Room>().player = true; //show player room }
public void fly(List<Room> path, Room current, Wumpus target) { //Random rand = new Random(); location = current; location.addOccupant(this); int flightLength = 0; //TODO: this is ugly, clean up later foreach (Room room in path){ //check current length of flight if (flightLength < maxFlight){ if (location.hasOccupant(target)){ target.die(); //Console.WriteLine("Aha! You got the Wumpus!"); return; } //check if rooms are connected if (location.hasNeighbor(room)){ move(room); } else{ //Console.WriteLine("Room " + (location.id + 1) + " is not neighbors with Room " + // (room.id + 1) + "! Picking another room..."); int i = Random.Range(0, location.neighbors.Count - 1); move(location.neighbors[i]); } if (location == current){ //Console.WriteLine("Ouch! The arrow got you!"); break; } flightLength++; } } //Console.WriteLine("Missed!"); target.wake(); //wake the wumpus if you miss used = true; }
//update on the character's status public static void Update(ref bool play, ref Map cave, ref Player player, ref Wumpus wumpus, ref SuperBats bats, ref Pit pitA, ref Pit pitB) { //wumpus logic if (wumpus.Awake) { wumpus.move(cave); if (wumpus.Room == player.Room) { player.Alive = false; play = false; } } //player logic if (player.Alive) { bool turn = true; //continues checking input until it is valid while (turn) { //gets input String move = Console.ReadLine(); //parses input //if the player chose to move if (string.Compare(move, 0, "M", 0, 1, true) == 0) { //prompts for room number Console.WriteLine("Tunnels connect to " + cave.Rooms[cave.Cloc[0]].Adj[0] + " " + cave.Rooms[cave.Cloc[0]].Adj[1] + " " + cave.Rooms[cave.Cloc[0]].Adj[2]); Console.WriteLine("What room would you like to move to?"); move = Console.ReadLine(); //parses the room number int room; int.TryParse(move, out room); bool valid = true; //checks input against the adjacent rooms for (int i = 0; i < 3; i++) { if (room == cave.Rooms[cave.Cloc[0]].Adj[i]) { player.move(ref cave, room); break; } else if (i == 2) { Console.WriteLine("Not possible"); Console.WriteLine("Please (S)hoot or (M)ove"); valid = false; } } if (!valid) { continue; } } else if (string.Compare(move, 0, "S", 0, 1, true) == 0) { player.shoot(ref cave, ref wumpus); } else { //invalid input, ask for reentry of input Console.WriteLine("Invalid Input"); Console.WriteLine("Please (S)hoot or (M)ove"); continue; } turn = false; } } else { Console.WriteLine("The Wumpus ate you! Game Over!"); } }
public void testDie() { Wumpus wumpus = new Wumpus("Wumpy", rooms[0]); if (wumpus.location == player.location) wumpus.kill(player); }
public void shootArrow(List<Room> path, Wumpus target) { if (arrowCount > 0) { arrows[0].fly(path, location, target); arrows.Remove(arrows[0]); arrowCount--; Console.WriteLine(name + " has shot a crooked arrow. " + arrowCount + " crooked arrows are left."); } if (arrowCount <= 0) Console.WriteLine("Out of arrows!"); }
void Start() { hazard_cap = 2; wumpusCave = new Cave(); player = new Player("Hunter"); wumpus = new Wumpus("Wumpy"); bats = new List<Bat>(hazard_cap); pits = new List<Pit>(hazard_cap); //init bats & pits for (int i = 0; i < hazard_cap; i++ ){ Bat bat = new Bat(i.ToString()); bats.Add(bat); Pit pit = new Pit(i); pits.Add(pit); } positions = new int[6]; setup(1); //assign player references to controllers //*I don't like it but I run into Object reference not set to an instance errors otherwise.. inputController = GetComponent<InputController>(); guiController = GameObject.Find("Canvas").GetComponent<GUIController>(); imgController = GetComponent<ImagePlaneController>(); inputController.player = player; guiController.player = player; guiController.gameState = STATE; //assign Room prefabs to a room DAO Transform Rooms = GameObject.Find("WumpusCave/Rooms").GetComponent<Transform>(); UnityEngine.Debug.Log(Rooms.childCount); for(int i = 0; i < Rooms.childCount; i++) Rooms.GetChild(i).GetComponent<RoomBehavior>().room = wumpusCave.rooms[i]; }
//shoot public void shoot(ref Map cave, ref Wumpus wumpus) { //arrow prompt Console.WriteLine("You shot your crooked arrow!"); //wakes the wumpus on the first shot if (!Shot) { Shot = true; Console.WriteLine("The wumpus has awaken!"); wumpus.Awake = true; } //start the arrow at the player's location Arrow = cave.Cloc[0]; //logic for arrow moving, path updates for (int i = 5; i > 0; i--) { //console I/O Console.WriteLine("Your arrow is in room " + Arrow); Console.WriteLine("Tunnels connect to " + cave.Rooms[Arrow].Adj[0] + " " + cave.Rooms[Arrow].Adj[1] + " " + cave.Rooms[Arrow].Adj[2]); Console.WriteLine("What room do you want your arrow to travel to?"); String move = Console.ReadLine(); //parse input int newRoom; int.TryParse(move, out newRoom); bool valid = true; //checks input against the adjacent rooms for (int j = 0; j < 3; j++) { if (newRoom == cave.Rooms[cave.Cloc[0]].Adj[j]) { //updates the arrow's location Arrow = newRoom; break; } else if (i == 2) { Console.WriteLine("Not possible"); Console.WriteLine("Please choose a correct path."); valid = false; } } if (!valid) { continue; } //checks to see if wumpus is hit if (Arrow == wumpus.Room) { Console.WriteLine("You've slain the Wumpus!"); wumpus.Alive = false; break; } //tells player how many moves the arrow has left Console.WriteLine("You arrow can travel " + i + " more rooms."); } Console.WriteLine("Your arrow didn't hit anything."); }
public void testSense() { Wumpus wumpus = new Wumpus("Wumpy", rooms[1]); //put him in a room next to player Bat bat = new Bat("Batty", rooms[4]); player.sense(); }
public void testShootArrow() { List<Room> path = new List<Room>(4); path.Add(rooms[1]); path.Add(rooms[2]); path.Add(rooms[3]); path.Add(rooms[4]); Wumpus wumpus = new Wumpus("Wumpy", rooms[3]); //path.Add(rooms[0]); //path.Add(rooms[1]); int max = Player.arrowMax; for (int i = 0; i < max + 1; i++) { player.shootArrow(path, wumpus); } }