减少Pokemon元素类型系统中的if语句 [英] Reducing if-statements in a Pokemon element type system

查看:108
本文介绍了减少Pokemon元素类型系统中的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用C ++创建一个简单的口袋妖怪战斗模拟器。我现在遇到的问题是如何实现Element系统(水击火,火打草,草打水,包括所有其他元素类型)。

Im in the process of trying to create a simple pokemon battle simulator in C++. The problem Ive ran into now is how to implement the Element system (water beats fire, fire beats grass, grass beats water, and including all the other element types).

我不知道如何在不使用大量If语句的情况下创建这样的系统。有没有更好的方法呢?

I dont know how I would create such a system without having to use a ton of If statements. Is there a better way to do this?

我有很多一般的编程知识,而且我知道C ++的基础知识,比如类,循环和其他各种基本的东西。

I have a good amount of general programming knowledge, and I know the basics of C++, like classes, loops, and various other basic things.

我会提供代码,但没有提供,因为我不知道如何制作这样的系统。我想我要问的是我可以用什么样的技术,数据结构等来实现这个目标

I would provide code, but there is nothing to provide as I have no idea how to make such a system. I guess i'm asking for what kind of technique, data structure, etc I could use to accomplish this

推荐答案

考虑一个查找表决策矩阵

想象一下这张表,适用于Rock-Paper-Scissors

Imagine this table, for Rock-Paper-Scissors

   R  P  S
R  -  L  W
P  W  -  L
S  L  W  -

如果它被解释为,那么读ROW然后COL

And where it is interpreted as so, reading ROW then COL

ROW(R) at COL(R) -> R *ties* R
ROW(S) at COL(P) -> S *wins* P

(在这种情况下,矩阵的两个对角半部分是倒置镜像。)

(The two diagonal halves of the matrix are inverted mirrors in this case.)

这篇关于减少Pokemon元素类型系统中的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆