⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arena.cpp

📁 with vxworks we can develope a group of control software for industry.
💻 CPP
字号:
/*    BladeMaster 2, a text, rougelike(kinda), arena combat simulation game.   Copyright (C) 2002 Blademaster 2 Team, see CREDITS   Clone of BladeMaster by Logicom, Inc. Copyright(C) 1990/1993   In no means affliated with the original Blademaster or the original   Blademaster creators/programmers.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   Useful contact information:       Website: blademaster2.sourceforge.net       Project page: www.sf.net/projects/blademaster2/   Project Lead (see CREDITS for other members of the developement team)       E-Mail: ilswyn@users.sourceforge.net       AIM: ilswyn*/#include <string>#include <ncurses.h>#include "arena.h"#include "items.h"#include "players.h"#include "shops.h"#include "globals.h"Position::Position(){  x = 0;  y = 0;}Position::~Position(){}Position& Position::operator=(const Position& right){  if(this==&right)    return *this;    x = right.x;  y = right.y;  return *this;}int operator==(const Position& left, const  Position& right){  if(left.x == right.x && left.y == right.y)    return 1;  else    return 0;}void ArenaObject::setObjPos(int tempX, int tempY){  obj_pos.setPos_X(tempX);  obj_pos.setPos_Y(tempY);}void ArenaObject::setObjLastPos(int tempX, int tempY){  obj_pos.setPos_X(tempX);  obj_pos.setPos_Y(tempY);}ArenaObject::ArenaObject(){  exp_value = 0;}ArenaObject::~ArenaObject() {}//   Draw object, and redraw object by inserting spaces in the//  previous location of the object.void ArenaObject::draw(){  mvwaddch(arena, obj_last_pos.getPos_Y(), obj_last_pos.getPos_X(), ' ');  // Previous coordinates for the object  obj_last_pos = obj_pos;  mvwaddch(arena, obj_pos.getPos_Y(), obj_pos.getPos_X(), obj_char);  wrefresh(arena);}// Every object in the arena takes a turn even if they do nothingvoid ArenaObject::take_turn(){}//    Checks if the specified coordinates match the coordinates// of the object (a collision) returns 1 if there is a collision// and returns 0 if there isnt a collisionint ArenaObject::check_collision(Position dest_pos){  // if ((obj_pos.getPos_X() == dest_pos.getPos_X() && obj_pos.getPos_Y() == dest_pos.getPos_Y())  //    || !(in_arena_boundary(dest_pos)))  if((obj_pos == dest_pos) || !(in_arena_boundary(dest_pos)))    return 1;  else return 0;}// Checks if destination is within the boundary of the arenaint ArenaObject::in_arena_boundary(Position dest_pos){  if (dest_pos.getPos_X() <= arena_boundary.getPos_X() &&       dest_pos.getPos_X() >= 0 &&       dest_pos.getPos_Y() <= arena_boundary.getPos_Y() &&       dest_pos.getPos_Y() >= 0)    return 1; // in arena boundary  else return 0; // out of arena boundary}// Gets the nearest <type> of object, for example it would get the nearest// human if 0 was specified, or get the nearest comp when 1 is specified.ArenaObject* Arena::get_nearest_type(Position origin, int type){  int closest_obj_index = 0;  int acc = 0;  Position closest_obj_pos;  closest_obj_pos = arena_obj_list[acc]->getObjPos();  while (acc < end_arena_object)    {      closest_obj_pos = closest_to(arena_obj_list[acc]->getObjPos(),				   closest_obj_pos, origin);            if (type == HUMAN && arena_obj_types[acc] == HUMAN)	{	  if(closest_obj_pos == arena_obj_list[acc]->getObjPos())	    {		  	      closest_obj_index = acc;	    }	}      else if (type == COMP && arena_obj_types[acc] == COMP)	{	  if (closest_obj_pos == arena_obj_list[acc]->getObjPos())	    {	      closest_obj_index = acc;	    }	}            acc++;    }    return arena_obj_list[closest_obj_index];}// Inputs 3 positions, sees what is closer to the origin, obj1 or obj2.Position Arena::closest_to(Position obj1, Position obj2, Position origin){  // Distance from origin to object 1 and 2  Position to_obj1;  to_obj1.setPos_X(origin.getPos_X() - obj1.getPos_X());  to_obj1.setPos_Y(origin.getPos_Y() - obj1.getPos_Y());    Position to_obj2;  to_obj2.setPos_X(origin.getPos_X() - obj2.getPos_X());  to_obj2.setPos_Y(origin.getPos_Y() - obj2.getPos_Y());  if (to_obj1.getPos_X() < to_obj2.getPos_X() && to_obj1.getPos_Y() < to_obj2.getPos_Y())    return obj1;  else return obj2;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -