private void drawActors() { TCODConsole.root.setForegroundColor(player.getPlayerColor()); TCODConsole.root.print(player.getPlayerX(), player.getPlayerY(), player.getPlayerChar() + ""); Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (currentMap.getInFOV(tempMon.getX(), tempMon.getY())) { TCODConsole.root.setForegroundColor(tempMon.getColor()); TCODConsole.root.print(tempMon.getX(), tempMon.getY(), tempMon.getC() + ""); } } }
public bool checkIfMonster(int x, int y) { for (int i = 0; i < monsters.Count; i++) { Monster tmp = (Monster)monsters[i]; if (tmp.getX() == x && tmp.getY() == y) { return(true); } } return(false); }
public Monster checkMonsterHealth() { for (int i = 0; i < monsters.Count; i++) { Monster tmp = (Monster)monsters[i]; if (tmp.checkHealth()) { items[tmp.getX(), tmp.getY()] = generateItem(tmp.getLevel()); monsters.RemoveAt(i); return(tmp); } } return(null); }
private void input() { bool moveon = false; while (!moveon && !TCODConsole.isWindowClosed()) { TCODKey key = TCODConsole.waitForKeypress(true); switch (key.KeyCode) { case TCODKeyCode.Up: case TCODKeyCode.KeypadEight: if (player.getPlayerY() > 0 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.Down: case TCODKeyCode.KeypadTwo: if (player.getPlayerY() < 39 && currentMap.getPassable(player.getPlayerX(), player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX(), player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.Left: case TCODKeyCode.KeypadFour: if (player.getPlayerX() > 0 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY())) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY())) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY()) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); moveon = true; } break; case TCODKeyCode.Right: case TCODKeyCode.KeypadSix: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY())) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY())) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY()) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); moveon = true; } break; case TCODKeyCode.KeypadSeven: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.KeypadNine: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() - 1)) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() - 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() - 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); player.setPlayerY(player.getPlayerY() - 1); moveon = true; } break; case TCODKeyCode.KeypadOne: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() - 1, player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX() - 1, player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() - 1 && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() - 1); player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.KeypadThree: if (player.getPlayerX() < 44 && currentMap.getPassable(player.getPlayerX() + 1, player.getPlayerY() + 1)) { if (currentMap.checkIfMonster(player.getPlayerX() + 1, player.getPlayerY() + 1)) { Object[] temp = currentMap.getMonsters(); for (int i = 0; i < temp.Length; i++) { Monster tempMon = (Monster)temp[i]; if (tempMon.getX() == player.getPlayerX() + 1 && tempMon.getY() == player.getPlayerY() + 1) { tempMon.reduceHealth(executePlayerAttack(tempMon)); } } moveon = true; break; } player.setPlayerX(player.getPlayerX() + 1); player.setPlayerY(player.getPlayerY() + 1); moveon = true; } break; case TCODKeyCode.Char: switch (key.Character) { case 'q': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsGold()) { textBox.Add("You picked up " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality() + " gold"); player.addGold(currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getQuality()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion()) { textBox.Add("You looted " + currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getName() + " for 10 gold"); player.addGold(10); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } break; case 'w': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsWeapon()) { textBox.Add("You looted " + player.getWeapon().getName() + " for " + player.getWeapon().getQuality() + " gold"); player.addGold(player.getWeapon().getQuality()); player.setWeapon(currentMap.getItem(player.getPlayerX(), player.getPlayerY())); textBox.Add("You equip " + player.getWeapon().getName()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } else if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsArmor()) { textBox.Add("You looted " + player.getArmor().getName() + " for " + player.getArmor().getQuality() + " gold"); player.addGold(player.getArmor().getQuality()); player.setArmor(currentMap.getItem(player.getPlayerX(), player.getPlayerY())); textBox.Add("You equip " + player.getArmor().getName()); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } break; case 'e': if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()) != null) { if (currentMap.getItem(player.getPlayerX(), player.getPlayerY()).getIsPotion()) { player.setNowHP(player.getNowHP() + (player.getMaxHP() / 2)); textBox.Add("You drink the healing potion, and recover some lost health."); currentMap.setItem(player.getPlayerX(), player.getPlayerY(), null); moveon = true; } } else if (currentMap.getTransision().getX() == player.getPlayerX() && currentMap.getTransision().getY() == player.getPlayerY()) { textBox.Add("You transport yourself into another realm"); Map tmp = new Map(realmStarts[rand.Next(0, realmStarts.Length)] + realmNames[rand.Next(0, realmNames.Length)] + realmNames[rand.Next(0, realmNames.Length)] + ", The " + realmTypes[rand.Next(0, realmTypes.Length)] + " of " + realmTitles[currentMap.getLevel()], currentMap.getLevel() + 1); currentMap = tmp; player.setPlayerX(rand.Next(1, 44)); player.setPlayerY(rand.Next(1, 39)); moveon = true; } break; } break; } } }