为棋盘游戏创造棋子 [英] Creating Pieces for a Board Game

查看:85
本文介绍了为棋盘游戏创造棋子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我不熟悉在C#中创建游戏,并希望提供一些建议来帮助我入门。我正在尝试使用由P代表的人创建棋盘游戏,在由R代表的不同方块上的5个岩石和由H代表的家庭。该人基于键盘动作绕着10x10板走,在他到达时拾取岩石当他到达广场的房子时,他们正在打开并将岩石放回家。



我使用Square [0,0]数组创建了电路板 - [9,9]我正在继续制作作品。是否通常使用参数如rockcarried,powerleft,position等为person,rock1,rock2等创建一个类?同样在显示时,显示对象的角色通常是在课堂上还是分开?例如class class有一个值为'P'的char参数,或者'P'是否与该类分开?



非常感谢任何建议。



非常感谢,

Stephen。

Hi all,

I'm new to creating games in C# and was hoping for some advice to help get me started. I am trying to create a board game using a person represented by a P, 5 rocks on different squares represented by R and home represented by H. The person walks around a 10x10 board based on keyboard actions, picking up the rocks as he reached the square they are on and placing the rocks home when he reaches the square home is on.

I have created the board using an array of Square [0,0] - [9,9] and am moving on to create the pieces. Is usual protocol to create a class for person, rock1, rock2, etc. with parameters such as rockscarried, powerleft, position, etc.? Also when displaying would the character displaying the object usually be in the class or separate? e.g. would class person have a char parameter with value 'P' or would 'P' be separate from the class?

Any advice is greatly appreciated.

Thanks very much,
Stephen.

推荐答案

有很多方法可以做到!



如果游戏的状态可以完全由棋盘代表(如Suduko)那么我只想使用二维数组的字符。



虽然它的声音,但有状态(岩石携带等)所以你可能想用不同的类来模拟它 - '人','摇滚' ,'Home'都来自一个共同的基类,它保存了它在电路板中的x / y co-ord。这对于任何游戏逻辑来说都是更好的抽象,并且是塔防游戏的典型工作方式(我知道 - 我写过一个)。



在'渲染方面'再次返回'P'和'R'或'H'我会在基类中将其作为一种抽象的方法,但毫无疑问,有人会出现并抨击单一责任和不同意的SOLID原则。如果确实发生了这种情况,我建议你拍它们。



希望有帮助...
There's so many ways to do it!

If the state of the game can be completely represented by the board (as in Suduko) then I'd be inclined just to use a 2-dimensional array of chars.

By the sounds of it though, there is state (rocks carried etc.) so you might want to model it using distinct classes - 'Person', 'Rock', 'Home' all derived from a common base class which holds the x/y co-ord of where it is in the board. This is better abstraction for any game logic too and is typical of how tower defense games work (I know - I've written one).

In terms of 'rendering' returning a 'P' and 'R' or a 'H' again I'd make this an abstract method in the base class but doubtless someone will come along and bang on about 'single responsibility' and SOLID principles who will disagree. If this does happen I advise you to slap them.

Hope that helps..


这篇关于为棋盘游戏创造棋子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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