/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element okna Kreatora grafu /// </summary> /// <param name="mousePos"></param> /// <param name="pi"></param> /// <param name="content"></param> public void CheckGraphCreator(Point mousePos, PlayerInterface pi, ContentManager content) { int index = GetIndex(GCButtons, mousePos); List<Fence> outFences; if (index > -1) { switch (GCButtons[index].name) { case "anuluj": pi.state = InterfaceState.MainMenu; break; case "zapisz-graf": DateTime now = DateTime.Now; SerializationManager.SerializeObject(graph, String.Format("{0}-{1}-{2}-{3}-{4}-{5}.xml", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second)); pi.state = InterfaceState.MainMenu; break; } } for(int i =0;i<VerticesNr;i++) { if(graph.flowers[i].ContainsPoint(mousePos)) { if(lastClicked==null) { lastClicked = graph.flowers[i]; lastClicked.color = Color.LightBlue; } else { if (graph.flowers[i] != lastClicked) { Fence f = new Fence(lastClicked, graph.flowers[i], "Plotek"); outFences = graph.GetOutFences(lastClicked); if (!outFences.Exists(x => (x.f1.Equals(lastClicked) && x.f2.Equals(graph.flowers[i])) || (x.f1.Equals(graph.flowers[i]) && x.f2.Equals(lastClicked)))) { outFences.Add(f); graph.fences.Add(f); graph.fencesNumber += 1; } } lastClicked.color = Color.White; lastClicked = null; } } } }
/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element okna zapytania o ilosc kwiatkow w grafie /// </summary> /// <param name="mousePos"></param> /// <param name="pi"></param> /// <param name="content"></param> public void CheckVerticesAsking(Point mousePos, PlayerInterface pi, ContentManager content) { int i = GetIndex(VerticesButtons, mousePos); if(i>-1) { switch(VerticesButtons[i].name) { case "start": VerticesNr = int.Parse(VerticesNrBuilder.ToString()); if (VerticesNr > 2) { graph = PredefinedGraphs.CreateEmptyGraph(VerticesNr, content); pi.state = InterfaceState.GraphCreation; } break; case "anuluj": pi.state = InterfaceState.MainMenu; break; } } }
/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element okna Kreatora grafu /// </summary> /// <param name="mousePos"></param> /// <param name="pi"></param> /// <param name="content"></param> public void CheckGraphCreator(Point mousePos, PlayerInterface pi, ContentManager content) { int index = GetIndex(GCButtons, mousePos); List<Fence> outFences; if (index > -1) { switch (GCButtons[index].name) { case "anuluj": pi.state = InterfaceState.MainMenu; break; case "zapisz-graf": DateTime now = DateTime.Now; PrepareGraphForSerialization(); SerializationManager.SerializeObject(graph, SerializationManager.CreateFileName(now)); pi.state = InterfaceState.MainMenu; break; case "usun": if(GCButtons[index].color == Color.White) { if (lastClicked is Fence) { graph.fences.Remove((Fence)lastClicked); graph.fencesNumber--; } else if(lastClicked is Flower) { outFences = graph.GetOutFences((Flower)lastClicked); if (outFences.Count > 0) Game1.MessageBox(new IntPtr(), "Najpierw usuń wychodzące krawędzie", "", 0); else { graph.flowers.Remove((Flower)lastClicked); graph.flowersNumber--; } } GCButtons[index].color = Color.Gray; lastClicked.color = Color.White; lastClicked = null; GCButtons[3].color = Color.White; return; } break; case "dodaj-kwiatek": if (GCButtons[index].color == Color.White) { List<int> indices = new List<int>(); foreach(Flower f in graph.flowers) { indices.Add(f.index); } indices.Sort(); int previous_index = -1; int flower_index = graph.flowersNumber; foreach(int ind in indices) { if(ind - previous_index > 1) { flower_index = previous_index + 1; break; } previous_index = ind; } Flower flower = new Flower(Game1.GetRatioDimensions(new Vector2(0, 390)), "Kwiatek", flower_index); graph.flowers.Add(flower); graph.flowersNumber++; return; } break; } } if (!(lastClicked is Fence)) { for (int i = 0; i < graph.flowersNumber; i++) { if (graph.flowers[i].ContainsPoint(mousePos)) { if (lastClicked == null) { lastClicked = graph.flowers[i]; lastClicked.color = Color.LightBlue; movingFlower = true; GCButtons[2].color = Color.White; GCButtons[3].color = Color.Gray; break; } else if (!movingFlower) { if (graph.flowers[i] != lastClicked) { Fence f = new Fence((Flower)lastClicked, graph.flowers[i], "Plotek"); outFences = graph.GetOutFences((Flower)lastClicked); if (!outFences.Exists(x => (x.f1.Equals(lastClicked) && x.f2.Equals(graph.flowers[i])) || (x.f1.Equals(graph.flowers[i]) && x.f2.Equals(lastClicked)))) { graph.fences.Add(f); graph.fencesNumber += 1; } } lastClicked.color = Color.White; lastClicked = null; GCButtons[2].color = Color.Gray; GCButtons[3].color = Color.White; return; } } } } if (movingFlower) { if (previousMousePosition != Vector2.Zero) { ((Flower)lastClicked).position.X -= previousMousePosition.X - mousePos.X; ((Flower)lastClicked).position.Y -= previousMousePosition.Y - mousePos.Y; ((Flower)lastClicked).center.X -= previousMousePosition.X - mousePos.X; ((Flower)lastClicked).center.Y -= previousMousePosition.Y - mousePos.Y; } previousMousePosition = new Vector2(mousePos.X, mousePos.Y); } else { if (lastClicked == null || lastClicked is Fence) { for (int i = 0; i < graph.fencesNumber; i++) { if (graph.fences[i].ContainsPoint(mousePos)) { if (lastClicked == null) { lastClicked = graph.fences[i]; lastClicked.color = Color.LightBlue; GCButtons[2].color = Color.White; GCButtons[3].color = Color.Gray; } else { if (graph.fences[i] == lastClicked) { lastClicked.color = Color.White; lastClicked = null; GCButtons[2].color = Color.Gray; GCButtons[3].color = Color.White; break; } } } } } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Globals.content = Content; playerInterface = new PlayerInterface(Content); graphCreator = new GraphCreator(Content); IsMouseVisible = true; Player p1 = new Player("Gracz1"); Computer c1 = new Computer(true); PredefinedGraphs.graphs = new List<GardenGraph>() { PredefinedGraphs.GraphZero(Content), PredefinedGraphs.GraphOne(Content), PredefinedGraphs.GraphTwo(Content) }; background = Content.Load<Texture2D>("tlo"); screenRectangle = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight); this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 10.0f); base.Initialize(); }
public void ManageGame(MouseState mouseState, GameTime gameTime) { bool didGardenerWon; if (mouseState.LeftButton == ButtonState.Pressed) { if (game.Escape.ContainsPoint(new Point(mouseState.X, mouseState.Y))) { if (MessageBox(new IntPtr(), "Zakoñczyæ grê?", "Wyjœcie", 4) == 6) { game = null; wasChecked = false; gameStarted = false; playerInterface = new PlayerInterface(Content); playerInterface.state = InterfaceState.MainMenu; return; } } } if (!wasChecked) { if (game.whoseTurn == 0) { if (!game.gardenerStartedMove && gameStarted) { game.ChangeTurn(game.player1.isGardener); game.gardenerStartedMove = true; } if (mouseState.LeftButton == ButtonState.Pressed) { if (game.gameType == GameType.VerticesColoring) CheckForFlowersClicked(mouseState); else CheckForFencesClicked(mouseState); CheckForColorsClicked(mouseState); } } else if (game.whoseTurn == 1) { if (game.gameMode == GameMode.SinglePlayer) { ((Computer)game.player2).CalculateMove(game); ((Computer)game.player2).elapsed += gameTime.ElapsedGameTime.TotalSeconds; } else { if (game.gardenerStartedMove && gameStarted) { game.ChangeTurn(!game.player1.isGardener); game.gardenerStartedMove = false; } if (mouseState.LeftButton == ButtonState.Pressed) { if(game.gameType == GameType.VerticesColoring) CheckForFlowersClicked(mouseState); else CheckForFencesClicked(mouseState); CheckForColorsClicked(mouseState); } } } } if (game.CheckIfEnd(out didGardenerWon)) { if (wasChecked) { if (didGardenerWon) { if (game.gameType == GameType.VerticesColoring) MessageBox(new IntPtr(), "Ogrodnik wygra³.\nPosadzi³ wszystkie kwiaty wed³ug w³asnego uznania.", "Koniec gry", 0); else MessageBox(new IntPtr(), "Ogrodnik wygra³.\nPomalowa³ wszystkie p³otki wed³ug w³asnego uznania.", "Koniec gry", 0); } else { if (game.gameType == GameType.VerticesColoring) MessageBox(new IntPtr(), "S¹siad wygra³.\nKtóryœ z kwiatów nie mo¿e zostaæ prawid³owo posadzony.", "Koniec gry", 0); else MessageBox(new IntPtr(), "S¹siad wygra³.\nKtóryœ z p³otków nie mo¿e zostaæ prawid³owo pomalowany.", "Koniec gry", 0); } game = null; wasChecked = false; gameStarted = false; playerInterface = new PlayerInterface(Content); playerInterface.state = InterfaceState.MainMenu; } else wasChecked = true; } }
public void ManageGame(MouseState mouseState, GameTime gameTime) { bool didGardenerWon; if (!wasChecked) { if (game.whoseTurn == 0) { if (game.gameMode == GameMode.ZeroPlayer) { ((Computer)game.player1).CalculateMove(game); ((Computer)game.player1).elapsed += gameTime.ElapsedGameTime.TotalSeconds; } else { if (!game.gardenerStartedMove && gameStarted) { //MessageBox(new IntPtr(), "Gardener turn", "Next turn", 0); game.ChangeTurn(game.player1.isGardener); game.gardenerStartedMove = true; } if (mouseState.LeftButton == ButtonState.Pressed) { if (game.gameType == GameType.VerticesColoring) CheckForFlowersClicked(mouseState); else CheckForFencesClicked(mouseState); CheckForColorsClicked(mouseState); } } } else if (game.whoseTurn == 1) { if (game.gameMode == GameMode.SinglePlayer || game.gameMode == GameMode.ZeroPlayer) { ((Computer)game.player2).CalculateMove(game); ((Computer)game.player2).elapsed += gameTime.ElapsedGameTime.TotalSeconds; } else { if (game.gardenerStartedMove && gameStarted) { //MessageBox(new IntPtr(), "Neighbour turn", "Next turn", 0); game.ChangeTurn(!game.player1.isGardener); game.gardenerStartedMove = false; } if (mouseState.LeftButton == ButtonState.Pressed) { if(game.gameType == GameType.VerticesColoring) CheckForFlowersClicked(mouseState); else CheckForFencesClicked(mouseState); CheckForColorsClicked(mouseState); } } } } if (game.CheckIfEnd(out didGardenerWon)) { if (wasChecked) { if (didGardenerWon) MessageBox(new IntPtr(), "Gardener won", "Game over", 0); else MessageBox(new IntPtr(), "Neighbour won", "Game over", 0); game = null; wasChecked = false; gameStarted = false; playerInterface = new PlayerInterface(Content); playerInterface.state = InterfaceState.MainMenu; } else wasChecked = true; } }