Beispiel #1
0
        /// <summary>Runs a 1 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);

            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.RandomSetUpMap(ShipList, PlaneList);

            CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            for (int i = 0; i < Player1.Height * Player1.Width; i++)
            {
                PossibleList.Add(i);
            }
            SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
            foreach (int[] i in SelectedShip.BodyList())
            {
                AttackingList.Add(i[0] + i[1] * Player1.Width);
            }

            Turn t;

            do
            {
                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                }
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                RandomTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 1 has lost the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
        }
Beispiel #2
0
        /// <summary>Runs a 2 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);

            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.ManualSetUp("Player 2", ShipList, PlaneList);
            Turn t;

            do
            {
                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                }
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player2, Player1);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player2, Player1);
                }
                PauseGame("It's time for player 2 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 2 has won the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
            //base.RunGame();
        }
Beispiel #3
0
        /// <summary>Runs a 2 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);
            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.ManualSetUp("Player 2", ShipList, PlaneList);
            Turn t;
            do
            {
                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                else
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player2, Player1);
                else
                    t = new Turn(Bonus, Salvo, Player2, Player1);
                PauseGame("It's time for player 2 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 2 has won the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
            //base.RunGame();
        }
Beispiel #4
0
        /// <summary>Runs a LAN game, here this computer is the client.</summary>
        public override void RunGame()
        {
            string buf = "";
            Console.CursorVisible = true;
            IPAddress hostIP = null;
            do {
                Console.Clear();
                Console.Write("Enter the ip of the host:");
                try
                {
                    hostIP = IPAddress.Parse(Console.ReadLine());
                    if (hostIP != null) break;
                }
                catch (Exception ex) {
                    continue;
                }
            }while(true) ;
            Console.CursorVisible = false;

            TcpClient client = new TcpClient(hostIP.ToString(),Program.Port);

            if ((buf = LanHost.GetData(client)).Equals("")) return;

            string[] inps = buf.Split(LanHost.FieldDelimiter.ToCharArray());

            bool clientSalvo = bool.Parse(inps[0]);
            bool clientBonus = bool.Parse(inps[1]);
            bool clientAdvanced = bool.Parse(inps[2]);

            SetUpMap temp = new SetUpMap(Player2, clientAdvanced);
            if (!LanHost.SendData(temp.ManualSetUp("Client", ShipList, PlaneList), client)) return;

            Console.Clear();
            Console.WriteLine("Waiting for Host to finish setting up map.");

            if ((buf = LanHost.GetData(client)).Equals("")) return;
            temp = new SetUpMap(Player1, clientAdvanced);
            temp.TextSetUp(buf, ShipList, PlaneList);

            Turn t;
            do
            {
                Console.Clear();
                Console.WriteLine("It's time for the host to play, please wait.");
                if ((buf = LanHost.GetData(client)).Equals("")) return;
                if (clientAdvanced)
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player1, Player2);
                else
                    t = new Turn(clientBonus, clientSalvo, Player1, Player2);

                t.DoTextTurnSequence(buf);
                if (Player2.hasLost())
                {
                    PauseGame("The client has lost the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }

                if (clientAdvanced)
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player2, Player1);
                else
                    t = new Turn(clientBonus, clientSalvo, Player2, Player1);
                PauseGame("It's time for the client to play, press ESC to continue.");
                if (!LanHost.SendData(t.DoManualTurnSequence(), client)) return;
                if (Player1.hasLost())
                {
                    PauseGame("The client has won the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }
            } while (true);
        }
Beispiel #5
0
        /// <summary>Runs a LAN game, here this computer is the client.</summary>
        public override void RunGame()
        {
            string buf = "";

            Console.CursorVisible = true;
            IPAddress hostIP = null;

            do
            {
                Console.Clear();
                Console.Write("Enter the ip of the host:");
                try
                {
                    hostIP = IPAddress.Parse(Console.ReadLine());
                    if (hostIP != null)
                    {
                        break;
                    }
                }
                catch (Exception ex) {
                    continue;
                }
            }while(true);
            Console.CursorVisible = false;

            TcpClient client = new TcpClient(hostIP.ToString(), Program.Port);

            if ((buf = LanHost.GetData(client)).Equals(""))
            {
                return;
            }

            string[] inps = buf.Split(LanHost.FieldDelimiter.ToCharArray());

            bool clientSalvo    = bool.Parse(inps[0]);
            bool clientBonus    = bool.Parse(inps[1]);
            bool clientAdvanced = bool.Parse(inps[2]);

            SetUpMap temp = new SetUpMap(Player2, clientAdvanced);

            if (!LanHost.SendData(temp.ManualSetUp("Client", ShipList, PlaneList), client))
            {
                return;
            }

            Console.Clear();
            Console.WriteLine("Waiting for Host to finish setting up map.");

            if ((buf = LanHost.GetData(client)).Equals(""))
            {
                return;
            }
            temp = new SetUpMap(Player1, clientAdvanced);
            temp.TextSetUp(buf, ShipList, PlaneList);

            Turn t;

            do
            {
                Console.Clear();
                Console.WriteLine("It's time for the host to play, please wait.");
                if ((buf = LanHost.GetData(client)).Equals(""))
                {
                    return;
                }
                if (clientAdvanced)
                {
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(clientBonus, clientSalvo, Player1, Player2);
                }

                t.DoTextTurnSequence(buf);
                if (Player2.hasLost())
                {
                    PauseGame("The client has lost the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }

                if (clientAdvanced)
                {
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player2, Player1);
                }
                else
                {
                    t = new Turn(clientBonus, clientSalvo, Player2, Player1);
                }
                PauseGame("It's time for the client to play, press ESC to continue.");
                if (!LanHost.SendData(t.DoManualTurnSequence(), client))
                {
                    return;
                }
                if (Player1.hasLost())
                {
                    PauseGame("The client has won the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }
            } while (true);
        }
Beispiel #6
0
        /// <summary>Runs a LAN game, here this computer is the host.</summary>
        public override void RunGame()
        {
            string buf = "";
            Console.Clear();
            IPAddress[] hostIPs = Dns.GetHostAddresses(Dns.GetHostName());
            IPAddress hostIP = null;
            foreach (IPAddress i in hostIPs)
                if ((i.AddressFamily == AddressFamily.InterNetworkV6) == Program.IPv6Hosting && !i.ToString().Substring(0, 3).Equals("127"))
                {
                    hostIP = i;
                    break;
                }
            if (hostIP == null)
            {
                Console.Write("Cannot get ip address, make sure your IPv" + (Program.IPv6Hosting ? "6" : "4") + " network is connected.\nPress ESC to return to main menu");
                while (Console.ReadKey().Key != ConsoleKey.Escape)
                { }
                return;
            }
            Console.Clear();
            Console.WriteLine("Waiting for a connection, your ip is: " + hostIP.ToString());
            TcpListener host = new TcpListener(hostIP,Program.Port);
            host.Start();
            TcpClient client = host.AcceptTcpClient();

            if (!SendData(Salvo.ToString() + FieldDelimiter + Bonus.ToString() + FieldDelimiter + Advanced.ToString(), client)) return;
            SetUpMap temp = new SetUpMap(Player1, Advanced);
            if (!SendData(temp.ManualSetUp("Host", ShipList, PlaneList),client)) { host.Stop(); return; }

            Console.Clear();
            Console.WriteLine("Waiting for Client to finish setting up map.");

            temp = new SetUpMap(Player2, Advanced);
            if ((buf = GetData(client)).Equals("")) { host.Stop(); return; }
            temp.TextSetUp(buf, ShipList, PlaneList);

            Turn t;
            do
            {
                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                else
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                PauseGame("It's time for the host to play, press ESC to continue.");
                buf = t.DoManualTurnSequence();
                if (!SendData(buf, client)) { host.Stop(); return; }
                if (Player2.hasLost())
                {
                    PauseGame("The host has won the game, press ESC to return to main menu.");
                    client.Close();
                    host.Stop();
                    return;
                }
                Console.Clear();
                Console.WriteLine("It's time for the client to play, please wait.");
                if ((buf = GetData(client)).Equals("")) { host.Stop(); return; }
                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player2, Player1);
                else
                    t = new Turn(Bonus, Salvo, Player2, Player1);

                t.DoTextTurnSequence(buf);
                if (Player1.hasLost())
                {
                    PauseGame("The host has lost the game, press ESC to return to main menu.");
                    client.Close();
                    host.Stop();
                    return;
                }
            } while (true);
        }
Beispiel #7
0
        /// <summary>Runs a 1 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);
            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.RandomSetUpMap(ShipList, PlaneList);

            CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            for (int i = 0; i < Player1.Height * Player1.Width; i++)
                PossibleList.Add(i);
            SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
            foreach (int[] i in SelectedShip.BodyList())
                AttackingList.Add(i[0] + i[1] * Player1.Width);

            Turn t;
            do
            {
                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                else
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                RandomTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 1 has lost the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
        }
Beispiel #8
0
        /// <summary>Runs a LAN game, here this computer is the host.</summary>
        public override void RunGame()
        {
            string buf = "";

            Console.Clear();
            IPAddress[] hostIPs = Dns.GetHostAddresses(Dns.GetHostName());
            IPAddress   hostIP  = null;

            foreach (IPAddress i in hostIPs)
            {
                if ((i.AddressFamily == AddressFamily.InterNetworkV6) == Program.IPv6Hosting && !i.ToString().Substring(0, 3).Equals("127"))
                {
                    hostIP = i;
                    break;
                }
            }
            if (hostIP == null)
            {
                Console.Write("Cannot get ip address, make sure your IPv" + (Program.IPv6Hosting ? "6" : "4") + " network is connected.\nPress ESC to return to main menu");
                while (Console.ReadKey().Key != ConsoleKey.Escape)
                {
                }
                return;
            }
            Console.Clear();
            Console.WriteLine("Waiting for a connection, your ip is: " + hostIP.ToString());
            TcpListener host = new TcpListener(hostIP, Program.Port);

            host.Start();
            TcpClient client = host.AcceptTcpClient();

            if (!SendData(Salvo.ToString() + FieldDelimiter + Bonus.ToString() + FieldDelimiter + Advanced.ToString(), client))
            {
                return;
            }
            SetUpMap temp = new SetUpMap(Player1, Advanced);

            if (!SendData(temp.ManualSetUp("Host", ShipList, PlaneList), client))
            {
                host.Stop(); return;
            }

            Console.Clear();
            Console.WriteLine("Waiting for Client to finish setting up map.");

            temp = new SetUpMap(Player2, Advanced);
            if ((buf = GetData(client)).Equals(""))
            {
                host.Stop(); return;
            }
            temp.TextSetUp(buf, ShipList, PlaneList);

            Turn t;

            do
            {
                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                }
                PauseGame("It's time for the host to play, press ESC to continue.");
                buf = t.DoManualTurnSequence();
                if (!SendData(buf, client))
                {
                    host.Stop(); return;
                }
                if (Player2.hasLost())
                {
                    PauseGame("The host has won the game, press ESC to return to main menu.");
                    client.Close();
                    host.Stop();
                    return;
                }
                Console.Clear();
                Console.WriteLine("It's time for the client to play, please wait.");
                if ((buf = GetData(client)).Equals(""))
                {
                    host.Stop(); return;
                }
                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player2, Player1);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player2, Player1);
                }

                t.DoTextTurnSequence(buf);
                if (Player1.hasLost())
                {
                    PauseGame("The host has lost the game, press ESC to return to main menu.");
                    client.Close();
                    host.Stop();
                    return;
                }
            } while (true);
        }