示例#1
0
 static void Main()
 {
     DataAccessLayer dal = new DataAccessLayer();
     Game game = new Game();
     game.InitializePorts();
     Controller controller = new Controller(ref dal, ref game);
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Form1(ref controller));
 }
        public void SaveGameState(List<Port> portList, Player player, Game game)
        {
            string deleteQuery = string.Format("DELETE FROM player WHERE playerName = '{0}'; DELETE FROM port WHERE playerName = '{0}'", player.PlayerName);
            SendData(deleteQuery);

            string queryPlayer = string.Format("INSERT INTO player VALUES ( '{0}', '{1}', '{2}',", player.PlayerName, player.Gold, game.Turn);

            foreach (Port port in portList)
            {
                string queryPort = string.Format("INSERT INTO port VALUES ('{0}', '{1}',", player.PlayerName, port.GetPortName());

                foreach (Cargo cargo in port.GetPortsCargoList())
                {
                    queryPort += string.Format(" '{0}',", cargo.Price);
                }

                queryPort = queryPort.Remove(queryPort.Length - 1);
                queryPort += ")";
                SendData(queryPort);
            }

            foreach (Cargo cargo in player.GetPlayersCargoList())
            {
                queryPlayer += "'" + cargo.Amount + "',";
            }
            queryPlayer = queryPlayer.Remove(queryPlayer.Length - 1);
            queryPlayer += ")";

            SendData(queryPlayer);
        }
示例#3
0
 /// <summary>
 /// Constructor that references DAL and Game 
 /// via inparameters.
 /// </summary>
 public Controller(ref DataAccessLayer dal, ref Game game)
 {
     this.dal = dal;
     this.game = game;
 }