📄 result.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Drawing;
namespace GrapeCity.Competition.TreasureHouse
{
public class Result
{
public Result(Map map, List<Direction> list, TimeSpan time)
{
this.Replay(map, list);
this._step = this._positions.Count;
this._time = time;
this.GetScore(map);
this._success = (this._time < new TimeSpan(0, 0, 10))
&& (this.Positions.Count > 0 && this._positions[this.Positions.Count - 1].IsEmpty)
&& (this.Positions.Count <= map.MaxStep);
if (!this._success)
{
this._score = 0;
}
}
private void Replay(Map map, List<Direction> list)
{
Point current = new Point(0, 0);
this._positions = new List<Point>();
for (int i = 0; i < list.Count; i++)
{
current = this.Move(current, list[i], map);
this._positions.Add(current);
}
}
private Point Move(Point current, Direction d, Map map)
{
int x = current.X;
int y = current.Y;
switch (d)
{
case Direction.Up:
y--;
break;
case Direction.Down:
y++;
break;
case Direction.Left:
x--;
break;
case Direction.Right:
x++;
break;
default:
break;
}
if (x < 0)
{
x = 0;
}
if (x > map.Size.Width - 1)
{
x = map.Size.Width;
}
if (y < 0)
{
y = 0;
}
if (y > map.Size.Height - 1)
{
y = map.Size.Height - 1;
}
if (map[x, y] == Tag.Wall)
{
return current;
}
return new Point(x, y);
}
private void GetScore(Map map)
{
List<Point> uniquePositions = new List<Point>();
for (int i = 0; i < this.Positions.Count; i++)
{
if (!uniquePositions.Contains(this.Positions[i]))
{
uniquePositions.Add(this.Positions[i]);
}
}
for (int i = 0; i < uniquePositions.Count; i++)
{
Point p = uniquePositions[i];
switch (map[p.X, p.Y])
{
case Tag.Coin:
this._coin++;
break;
case Tag.Gem:
this._gem++;
break;
case Tag.HolyA:
this._holyA++;
break;
case Tag.HolyB:
this._holyB++;
break;
case Tag.HolyC:
this._holyC++;
break;
}
}
int value = this._coin + this._gem * 4;
int holy = Math.Min(Math.Min(this._holyA, this._holyB), this._holyC);
value += holy * 24;
value += (this._holyA + this._holyB + this._holyC - holy * 3) * 2;
this._score = value;
}
public Result(bool success, int step, TimeSpan time, int coin, int gem, int holyA, int holyB, int holyC, int score)
{
this._success = success;
this._step = step;
this._time = time;
this._coin = coin;
this._gem = gem;
this._holyA = holyA;
this._holyB = holyB;
this._holyC = holyC;
this._score = score;
}
private bool _success;
private int _step;
private TimeSpan _time;
private int _coin;
private int _gem;
private int _holyA;
private int _holyB;
private int _holyC;
private int _score;
private List<Point> _positions;
public bool Success
{
get { return this._success; }
}
public int Step
{
get { return this._step; }
}
public TimeSpan Time
{
get { return this._time; }
}
public int Coin
{
get { return this._coin; }
}
public int Gem
{
get { return this._gem; }
}
public int HolyA
{
get { return this._holyA; }
}
public int HolyB
{
get { return this._holyB; }
}
public int HolyC
{
get { return this._holyC; }
}
public int Score
{
get { return this._score; }
}
[Browsable(false)]
public List<Point> Positions
{
get { return this._positions; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -