using System.Collections.Generic; using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using UPWG.Core; using Elite; namespace UPWG.Main { public enum TurnState { WaitingForInput, PlayerMoveAnimation, PlayerMoveResult, OpponentMoveAnimation, OpponentMoveResult, } public class BattleTest : Game { private GraphicsDeviceManager _graphicsDeviceManager; private SpriteFont _spriteFont; private Wrestler _p1; private Wrestler _p2; private Battle _match; private StateMachine _turnState; private BattleSprite _sprite1; private BattleSprite _sprite2; private ScaledRenderTarget _target; private Sprite _ring; public BattleTest() { _graphicsDeviceManager = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; MoveDatabase.Initialize(); _turnState = new StateMachine(TurnState.WaitingForInput); _turnState.AddTransition(TurnState.PlayerMoveAnimation, TurnState.PlayerMoveResult, 1); _turnState.AddTransition(TurnState.PlayerMoveResult, TurnState.OpponentMoveAnimation, 1); _turnState.AddTransition(TurnState.OpponentMoveAnimation, TurnState.OpponentMoveResult, 1); _turnState.AddTransition(TurnState.OpponentMoveResult, TurnState.WaitingForInput, 1); _p1 = new Wrestler("CM Punk", 7, 9, 5, 8, 10, WeightClass.Normal); _p2 = new Wrestler("John Cena", 8, 8, 5, 8, 8, WeightClass.Normal); _match = new Battle(_p1, _p2); } protected override void Initialize() { _graphicsDeviceManager.PreferredBackBufferWidth = 1281; _graphicsDeviceManager.PreferredBackBufferHeight = 720; _graphicsDeviceManager.ApplyChanges(); base.Initialize(); } protected override void LoadContent() { _spriteFont = Content.Load("Arial"); _target = new ScaledRenderTarget(GraphicsDevice, 640, 360, 2.0f, _spriteFont); _sprite1 = new BattleSprite(GraphicsDevice, ""); _sprite2 = new BattleSprite(GraphicsDevice, ""); _ring = new Sprite(GraphicsDevice, "Content/oga/ring_7.png"); _target.DrawList.Add(_ring); _target.DrawList.Add(_sprite1); _target.DrawList.Add(_sprite2); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { var keyboardState = Keyboard.GetState(); MoveResult moveResult; _turnState.Update(gameTime.ElapsedGameTime.TotalSeconds); _sprite1.Update(gameTime.ElapsedGameTime.TotalSeconds); _sprite2.Update(gameTime.ElapsedGameTime.TotalSeconds); if (keyboardState.IsKeyDown(Keys.Escape)) Exit(); if (_match.IsPlayerTurn() && _turnState.CurrentState == TurnState.WaitingForInput) { if (keyboardState.IsKeyDown(Keys.A)) { moveResult = _match.ApplyMove(_match.CurrentMoveOptions.Strike); _turnState.SetState(TurnState.PlayerMoveAnimation); } else if (keyboardState.IsKeyDown(Keys.S)) { moveResult = _match.ApplyMove(_match.CurrentMoveOptions.Grapple); _turnState.SetState(TurnState.PlayerMoveAnimation); } else if (keyboardState.IsKeyDown(Keys.D)) { moveResult = _match.ApplyMove(_match.CurrentMoveOptions.Other); _turnState.SetState(TurnState.PlayerMoveAnimation); } else if (keyboardState.IsKeyDown(Keys.F)) { moveResult = _match.ApplyMove(_match.CurrentMoveOptions.Special); _turnState.SetState(TurnState.PlayerMoveAnimation); } } else { _match.GetCpuMove(out var move, out var target); moveResult = _match.ApplyMove(move); } base.Update(gameTime); } private void DrawWrestler(Battle.ParticipantRole role, Battle.Participant participant) { int x, y; switch (role) { case Battle.ParticipantRole.LeftSingle: x = 100; y = 100; break; default: x = 1280 - 300; y = 100; break; } _target.DrawString( _spriteFont, $"{participant.Wrestler.Name}", new Vector2(x, y), Color.Pink ); _target.DrawString( _spriteFont, $"Momentum: {participant.Momentum}", new Vector2(x, y + 20), Color.Pink ); _target.DrawString( _spriteFont, $"Restrained: {participant.Restrained} Injured: {participant.Injured}", new Vector2(x, y + 40), Color.Pink ); _target.DrawString( _spriteFont, $"{participant.CurFatigue} / {participant.MaxFatigue}", new Vector2(x, y + 60), Color.Pink ); } private void DrawMoveOptions(MoveOptions moveOptions) { _target.DrawString(_spriteFont, $"A: {moveOptions.Strike}", new Vector2(200, 200), Color.Yellow); _target.DrawString(_spriteFont, $"S: {moveOptions.Grapple}", new Vector2(200, 210), Color.Yellow); _target.DrawString(_spriteFont, $"D: {moveOptions.Special}", new Vector2(200, 220), Color.Yellow); _target.DrawString(_spriteFont, $"F: {moveOptions.Other}", new Vector2(200, 230), Color.Yellow); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Red); const int x = 300; var y = 300; var n = 1; _target.Draw(gameTime); _target.SpriteBatch.Begin(); foreach (var (key, value) in _match.Participants) { DrawWrestler(key, value); } _target.DrawString(_spriteFont, $"{_turnState.CurrentState}", new Vector2(_target.Width / 2, 0), Color.White); foreach (var turn in _match.UpcomingTurns) { _target.DrawString(_spriteFont, $"{n}: {turn}", new Vector2(x, y), Color.Green); n += 1; y += 12; } if (_match.IsPlayerTurn()) DrawMoveOptions(_match.CurrentMoveOptions); _target.SpriteBatch.End(); base.Draw(gameTime); } } }