C# 垄断实施规则

C# 垄断实施规则,c#,C#,我用一个链表创建了这个垄断委员会 已为方块赋值,但需要能够将这些值从玩家类中指定的整数中添加或删除 如果您有任何帮助或建议,我们将不胜感激(我现在对您的评论表示歉意,这些评论还需要修改)。代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MonoPolyFin; namespace Mono

我用一个链表创建了这个垄断委员会

已为方块赋值,但需要能够将这些值从玩家类中指定的整数中添加或删除

如果您有任何帮助或建议,我们将不胜感激(我现在对您的评论表示歉意,这些评论还需要修改)。代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MonoPolyFin;

namespace MonoPolyFin
{

public class Square//Creating Squares for the board
{

    public Square next;//Declaring the Square as the next node
    public string g;//String to store the Square data

    public Square(string g)//assigning the string to g
    {
        this.g = g;
    }



    public class Board/*The Board class creating the linked list and printing it out to                        the console window*/
    {

        public Square head;//Declaring as the head 
        Square current;//and current 

        public void Add(Square s)/*The Add method for adding nodes in order to the linked list checking each time to see if the head of 
         the list is empty */
        {
            if (head == null)//if the head is empty
            {
                head = s;//the head equals the string
                current = head;//the current node is the head
            }
            else
            {
                current.next = s;//if not empty the current node is the next node
                current = current.next;//then the next
                current.next = head;//keep going round the board through the linked list
            }
        }

        public void Writeline(ref Square gamesquare)//The writeline method to print out in the console
        {
            Random r = new Random();//Creates a new object using the random method
            int n = r.Next(1, 6);//Creates a random number between 1-6
            Console.WriteLine(n);//Writes the stored number to the console
            Console.WriteLine("Player moves to " + gamesquare.g);//write the gamesquare to the console that is saved in the string g
            Console.ReadKey();//read whats in the console and throw it out


            if (n <= 1)//If the number is less than 1
            {

                head = current
                    ;//Move one positions down the list

            }
            else if (n <= 2)//If the number is less than 2
            {

                head = head.next.next;//Move two positions down the list

            }

            else if (n <= 3)//If the number is less than 3
            {

                head = head.next.next.next;//Move three positions down the list

            }
            else if (n <= 4)//If the number is less than 4
            {

                head = head.next.next.next.next;//Move four positions down the list

            }
            else if (n <= 5)//If the number is less than 5
            {

                head = head.next.next.next.next.next;//Move five positions down the list

            }
            else if (n <= 6)//If the number is less than 6
            {

                head = head.next.next.next.next.next.next;//Move six positions down the list

            }
        }
    }


  public class Player1
        {

            public string Dog;
            public int Money = 2000;
            public Square position = null;

           }


  public class Player2
  {

      public string Car;
      public int Money = 2000;
      public Square position = null;

  }


  static void Main(string[] args)//Main method
        {
            int go = 200;//Value of the square in the linked list
            int strand = 220;//Value of the square in the linked list
            int trafalger_square = 220;//Value of the square in the linked list
            int leicester_square = 280;//Value of the square in the linked list
            int piccadilly = 280;//Value of the square in the linked list
            int regent_street = 300;//Value of the square in the linked list
            int oxford_street = 300;//Value of the square in the linked list
            int mayfair = 400;//Value of the square in the linked list
            int park_lane = 400;//Value of the square in the linked list
            int whitechapel = 60;//Value of the square in the linked list
            int old_kent_road = 60;//Value of the square in the linked list
            int euston = 100;//Value of the square in the linked list
            int islington = 100;//Value of the square in the linked list
            int pall_mall = 140;//Value of the square in the linked list
            int whitehall = 140;//Value of the square in the linked list
            int vine_street = 180;//Value of the square in the linked list
            int bow_strett = 180;//Value of the square in the linked list

            Board list = new Board();//constructor to create the list
            list.Add(new Square("Go Collect £" + go));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Strand £" + strand + " Black"));//Add to the linked list using the Add method also assigning the int value
            list.Add(new Square("Trafalger Square £" + trafalger_square + " Black"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Gas"));//Add to the linked list
            list.Add(new Square("Leicester Square £" + leicester_square + " Aqua"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Piccadilly £" + piccadilly + " Aqua"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Card"));//Add to the linked list
            list.Add(new Square("Regent Street £" + regent_street + " Yellow"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Oxford £" + oxford_street + " Yellow"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Electric" ));//Add to the linked list
            list.Add(new Square("Mayfair £" + mayfair + " Green"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Park Lane £" + park_lane + " Green"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Jail"));//Add to the linked list
            list.Add(new Square("Old Kent Road £" + old_kent_road + " Blue"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Whitechapel £" + whitechapel + " Blue"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Water"));//Add to the linked list
            list.Add(new Square("Islington £" + islington + " Red"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Euston £" + euston + " Red"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Card"));//Add to the linked list
            list.Add(new Square("Pall Mall £" + pall_mall + " Pink"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Whitehall £" + whitehall + " Pink"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Phone" ));//Add to the linked list
            list.Add(new Square("Bow Street £" + bow_strett + " Brown"));//Add to the linked list using the Add method also assigning the int value 
            list.Add(new Square("Vine Street £" + vine_street + " Brown"));//Add to the linked list using the Add method also assigning the int value 

            for (int i = 0; i <= 10; i++)
            {

                Player2 car = new Player2();
                car.position = list.head;
                Console.WriteLine("Car roles the dice and roles");
                list.Writeline(ref car.position);

                Player1 dog = new Player1();
                dog.position = list.head;
                Console.WriteLine("Dog roles the dice and roles");
                list.Writeline(ref dog.position);
            }

          }

        }
    }
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用单极鳍;
单极鳍
{
公共类方形//为董事会创建方形
{
public Square next;//将该Square声明为下一个节点
公共字符串g;//用于存储方形数据的字符串
公共正方形(字符串g)//将字符串分配给g
{
这个.g=g;
}
public class Board/*创建链接列表并将其打印到控制台窗口的Board类*/
{
公共方头;//声明为方头
平方电流;//和电流
public void Add(Square s)/*用于添加节点的Add方法,以便每次检查链接列表的头
列表是空的*/
{
if(head==null)//如果head为空
{
head=s;//head等于字符串
current=head;//当前节点是head
}
其他的
{
current.next=s;//如果不为空,则当前节点为下一个节点
current=current.next;//然后是next
current.next=head;//通过链表在电路板上循环
}
}
public void Writeline(ref Square gamesquare)//要在控制台中打印的Writeline方法
{
Random r=new Random();//使用Random方法创建一个新对象
int n=r.Next(1,6);//在1-6之间创建一个随机数
Console.WriteLine(n);//将存储的号码写入控制台
Console.WriteLine(“玩家移动到”+gamesquare.g);//将gamesquare写入保存在字符串g中的控制台
Console.ReadKey();//读取控制台中的内容并将其抛出

如果(n看起来你的方块应该由一个类型层次结构组成

方格

  • 抽牌
    • 机会
    • 公益金
  • 税/去
  • 监狱
  • 可拥有
    • 效用
    • 铁路
    • 有色的
所有这些都将有一个多态方法

virtual void VisitFrom(int diceRoll, Player activePlayer);
例如,实用程序的实现可能是

virtual void VisitFrom(int diceRoll, Player activePlayer)
{
    if (owner == Bank)
        activePlayer.offerProperty(this, 150);
    else if (activePlayer != owner)
        activePlayer.Pay(owner, ((otherUtility.owner == owner)? 10: 4) * diceRoll);
}
哦,另一方面,两个玩家应该是同一类的实例

对于行为不同的对象,您需要单独的类。当对象行为相似时,请使用实例


当然,你也需要将彩色实例关联到彩色组中,以便在同一玩家拥有所有实例时给予奖励。

忽略这看起来像是家庭作业这一事实,你发布了一大堆代码。请将你的代码缩小到只有你有疑问的代码。无可否认,这是家庭作业,我已经收到了很多家庭作业尽管我自己在寻找解决方案,但还是找不到。我已经贴了一堵代码墙,让查看代码的人知道我在哪里,并希望能在那里给我建议,在哪里添加我在上述问题中询问过的代码。嗯,我本来希望在“广场”上有一个活动游戏的一个有趣的部分是分散业主的注意力,这样他们就不会注意到你刚刚在梅菲尔的酒店着陆……事实上,我不知道如何在链接列表中的节点上执行活动,如果这是我必须做的!!!重复像“Pall Mall”这样的文本片段建议数据结构可能无法清楚地表示问题域。在我看来,似乎有两种选择:将当前的数据结构集与意大利面串连接在一起,或者创建对象来表示正方形-当玩家降落到正方形上时,可能会将玩家作为参数传递给正方形的方法。也就是说,设计一个不同的系统可能比从当前代码开始更容易。你说的对,我已经在同一个类中实现了播放器(如建议的)因为它们具有相同的行为!!!我不知道如何构造层次结构,因为正方形实际上是链表的一部分,这是我的问题。@Itchebanty:我显示的层次结构是一个继承层次结构,而不是一个数据结构。您仍然可以将它们作为链表链接在一起。因为链接在基类中。