You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

using System;
2 years ago
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using Unity.VisualScripting;
using UnityEngine;
2 years ago
using UnityEngine.Assertions;
using Object = UnityEngine.Object;
namespace Game {
public class GameManager : NetworkBehaviour {
2 years ago
public static GameManager Singleton { get; private set; }
private void OnEnable() {
Singleton = this;
}
public Object ballPrefab;
public Object playerPrefab;
2 years ago
public List<Ball> Balls { get; } = new();
private static void Tests() {
var v1 = new Vector2(1, 3);
var v2 = new Vector2(3, 2);
var v3 = new Vector2(4, 4);
var v4 = new Vector2(1, 1);
var v5 = new Vector2(4, 1);
var v6 = new Vector2(2, 5);
var v7 = new Vector2(2, 3);
var v8 = new Vector2(-1, 4);
var v9 = new Vector2(-2, 1);
var v10 = new Vector2(3, -1);
Assert.IsTrue(AIPlayer.Intersect(v8, v4, v1, v9, out _));
Assert.IsTrue(AIPlayer.Intersect(v1, v2, v4, v7, out _));
Assert.IsTrue(AIPlayer.Intersect(v10, v6, v9, v2, out _));
Assert.IsTrue(AIPlayer.Intersect(v9, v5, v8, v10, out _));
Assert.IsFalse(AIPlayer.Intersect(v8, v4, v6, v5, out _));
Assert.IsFalse(AIPlayer.Intersect(v3, v5, v6, v8, out _));
Assert.IsFalse(AIPlayer.Intersect(v10, v4, v8, v9, out _));
Assert.IsFalse(AIPlayer.Intersect(v1, v7, v3, v2, out _));
var v11 = new Vector2(0, 4.8f);
var v12 = new Vector2(0, 14.8f);
var v13 = new Vector2(-9.75f, 14.75f);
var v14 = new Vector2(9.75f, 14.75f);
Assert.IsTrue(AIPlayer.Intersect(v11, v12, v13, v14, out _));
}
private void Start() {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.Easy;
var ball = Instantiate(ballPrefab).GetComponent<Ball>();
2 years ago
Balls.Add(ball);
2 years ago
ball.Radius = 0.5f;
2 years ago
var p1Obj = Instantiate(playerPrefab);
var p2Obj = Instantiate(playerPrefab);
Player p1, p2;
switch (Settings.Type) {
case Type.AI:
p1 = p1Obj.AddComponent<AIPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((AIPlayer) p1).Difficulty = Settings.AIDifficulty;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
break;
case Type.Real:
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<RealPlayer>();
((RealPlayer) p1).isThisClient = true;
break;
case Type.Hybrid:
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((RealPlayer) p1).isThisClient = true;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
break;
default:
throw new ArgumentOutOfRangeException();
}
p1.Side = Player.ESide.Bottom;
p2.Side = Player.ESide.Top;
2 years ago
Tests();
}
}
}